develooper Front page | perl.moose | Postings from May 2012

Re: Set attribute using 'after'

Thread Previous | Thread Next
From:
Curtis Jewell
Date:
May 11, 2012 07:30
Subject:
Re: Set attribute using 'after'
Message ID:
1336746613.28802.140661074237237.77104BDC@webmail.messagingengine.com
On Fri, May 11, 2012, at 15:42, Emmanuel Quevillon wrote:
> Hi,
> 
> I got an exception when using 'after' this way.
> Here is my Moose class :
> 
> package Myclass;
> 
> use Moose;
> extends 'SuperClass';
> with 'MyRole';
> 
> has 'file' => (is => 'rw', isa => 'Str', required => 1);
> has 'fh'   => (is => 'rw', isa => 'FileHandle');
> 
> after 'new' => sub {
>     my $self = shift;
>     my $file = $self->file();
>     $self->set_fh($self->open_file($file)); # Returns a FileHandle obj
>     return 0;
> };
> 
> 1;

You don't have a 'new' attribute to hook 'after'.

The technical name for "after 'new' => sub {" is "sub BUILD {". See
Moose::Cookbook::Basics::Person_BUILDARGSAndBUILD for more details.

--Curtis Jewell
--
Curtis Jewell
swordsman@curtisjewell.name

%DCL-E-MEM-BAD, bad memory
-VMS-F-PDGERS, pudding between the ears


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About