< back

Sam-I-Am's Builder Blog

Work type stuff - handy urls and notes on the trials and tribulations of a web builder.

Thursday, May 05, 2005

Perl Design Patterns Wiki

There's a world of goodness over at the perl design patterns wiki. Take this little snippet:

foreach my $i (qw(name price quantity)) {
    my $field = $i;
    *{"get_$field"} = sub {
      my $me = shift;
      return $me->{$field};
    };
    *{"set_$field"} = sub {
      my $me = shift;
      @_ or die "not enough arguments to set_$field, stopped";
      $me->{$field} = shift;
      return 1;
     };
  }

..All your getters and setters, done. I'm in awe, and I'm dumping php and going back to perl :) This and other wisdom comes from the AccessorPattern page.

0 Comments:

Post a Comment

<< Home

< back

© Copyright 1999-2005 Sam Foster