[Phoenix-pm] inside out objects

Brock awwaiid at thelackthereof.org
Wed Nov 23 09:16:38 PST 2005


On 2005.11.23.17.06, Scott Walters wrote:
|...
| This is the AUTOLOAD glue needed to so that objects created as 
| follows work:
| 
|   package Person;
|   use hashclosure;
| 
|   our $this;
| 
|   sub new {
|       my $class = shift;
|       my $name;
|       my $age;
|       bless { 
|           name => sub { $name },
|           set_name => sub { $name = shift },
|           age  => sub { $age },
|           set_age => sub { $age = shift },
|           print_stats => sub {
|               my $self = shift;
|               print "name: ", $self->name, "\n";
|               print "age: ", $self->age, "\n"; 
|           },  
|           get_older => sub {
|               my $self = shift;
|               $self->age++;
|           },
|       }, $class;
|   } 
| 
|...

Should that print_stats sub be

  print_stats => sub {
    print "name: $name\n";
    print "age: $age\n";
    $this->other_method_invocation();
  }

without the need to get $self? Also with that example self-method
invocation?

--Brock



More information about the Phoenix-pm mailing list