Sam-I-Am on Web Development

Sam Foster on the web and web-ish software developmen

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:

<< Home