"package"の代わりに"class"を使うclass.pm作った
再発明かな。
use strict; use warnings; use class; class "Foo" => ( bar => sub { my $self = shift; if (@_) { $self->{bar} = shift; } $self->{bar}; }, ); my $foo = Foo->new(bar => 'baz'); print $foo->bar, "\n"; #=> 'baz' $foo->bar('hoge'); print $foo->bar, "\n"; #=> 'hoge'