Re: Set attribute using 'after'

[email protected] (Curtis Jewell)
Newsgroups perl.moose
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
[email protected]

%DCL-E-MEM-BAD, bad memory
-VMS-F-PDGERS, pudding between the ears
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.