[pm-h] Moose question

Will Willis will.willis at gmail.com
Mon Dec 21 13:37:07 PST 2009


Thanks Todd,

What does the immutable bit do at the end? Freeze my object to any further
changes? What about 'no Moose'?

I've seen it done in the manual but haven't seen an explaination.

On Dec 21, 2009 10:25 AM, "Todd Rinaldo" <toddr at null.net> wrote:

I'm a big fan of lazy. You're kinda randomly initializing your object
in the object if you don't use it. Oh and per the Moose gods, don't
forget to turn off Moose and make immutable at the end of your module.

Try this:

#!/usr/bin/perl use strict; use Website; my $web = Website->new(name
='Google', url ='http://www.g...

package Website; use Moose; use WWW::Mechanize;
# Mech will initialize whenever it's first called.
has '_mech'    => (isa => 'Object', is => 'ro', lazy => 1, default =>
sub { WWW::Mechanize->new });

has 'name'  =( is ='rw', isa ='Str', required =1); has 'url'   =(is ='rw',
isa ='Str', required =1)...

    $self->_mech->get($self->url);     return $self->_mech->content; }
no Moose;
__PACKAGE__->meta->make_immutable;
1;

_______________________________________________ Houston mailing list
Houston at pm.org http://mail.pm.o...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/mailman/private/houston/attachments/20091221/1fefaa9b/attachment.html>


More information about the Houston mailing list