[Israel.pm] Using Closures as Methods

Yuval Kogman nothingmuch at woobling.org
Thu Feb 9 08:50:19 PST 2006

On Thu, Feb 09, 2006 at 17:24:27 +0200, Shlomi Fish wrote:
> Hi all!
> As the following code demonstrates, it is in fact possible to use closures as 
> methods in Perl 5. Furthermore, one can use the SUPER meta-class in them to 
> call the method of the base class.

Well duh, any sub reference in the symbol table is no longer
anonymous and can be used as a method.

Also, every subroutine in Perl is a closure. It's just that some of
them don't close on any variables.

my $foo;

sub bar { # also a closure

This is a pretty standard way to generate subroutines which are
mundane to write, like, for example, log event handlers, or
convenient methods.

Class::Accessor also does to generate accessors.

 ()  Yuval Kogman <nothingmuch at woobling.org> 0xEBD27418  perl hacker &
 /\  kung foo master: *shu*rik*en*sh*u*rik*en*s*hur*i*ke*n*: neeyah!!!!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://perl.org.il/pipermail/perl/attachments/20060209/7fc439a0/attachment.pgp 

More information about the Perl mailing list