09 January 2009
This post may be outdated due to it was written on 2009. The links may be broken. The code may be not working anymore. Leave comments if needed.
Writing Moose is really very fun and happy.

I'm happy that sunnavy picked up the Moose for Net::Google::Code.

Today I'm implementing some attributes for the Net::Google::Code. the code would be something like
    use Net::Google::Code;
my $project = Net::Google::Code->new( project => 'net-google-code' );
print join(', ', @{ $project->owners } );
so in old plain Perl code, you must write code in Net/Google/Code.pm or else you need sub owners { Net::Google::Code::Home->new()->owners }, something like that.

with Moose, with hanldes, we can simply write code like
has 'home'  => (
isa => 'Net::Google::Code::Home',
is => 'ro',
lazy => 1,
default => sub {
require Net::Google::Code::Home;
Net::Google::Code::Home->new( parent => $_[0] );
handles => [ 'owners', 'members' ],

in this way, it makes the code really clean and small.

the magic is $project->owners == $project->home->owners, more example can be found: http://search.cpan.org/src/DROLSKY/Moose-0.64/t/020_attributes/010_attribute_delegation.t.

if you never use Moose before, you SHOULD use Moose today!


blog comments powered by Disqus