Re: Set attribute using 'after'

[email protected] (Chris Weyl)
Newsgroups perl.moose
Message-ID <CABSyATFFgX2vpgX1swc1aKggFPcxk0aRTjZOs-4qFFbWPqg=4w@mail.gmail.com>
Hmmm... did you notice that you defined "Myclass", then tried:
"MyClass->new"?

-Chris
On May 11, 2012 6:42 AM, "Emmanuel Quevillon" <[email protected]> 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;
>
>
> Later when I use my Class, I get the following error :
>
> my $c = MyClass->new(file => '/tmp/foobar');
>
> Can't use string ("MyClass") as a HASH ref while "strict refs" in use at
> accessor MyClass::file (defined at /home/tuco/src/workspace/**cnvdb/script/../lib/Class.pm
> line 7)
>
>
>
> Can someone light my lantern?
>
> Sorry for the stupid question
>
> Regards
>
>
> --
> -------------------------
> Emmanuel Quevillon
> CIB, Centre Informatique pour la Biologie
> Institut Pasteur
> +33 1 44 38 95 98
> tuco at_ pasteur dot fr
> -------------------------
>
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.