in reply to Re: Object not created as well with Moose
in thread Object not created as well with Moose

#!/usr/bin/perl -w use strict; use Package::System::Foo; use Data::Dumper; my $foo = Package::System::Foo->new(); $foo->start(); print Dumper $foo;
package Package::System::Foo; use Moose; extends 'Package::Contol::Base::Daemon::Server'; use Package::System::Config; has 'CONFIG' => (is=>'rw',isa=>'Object'); # OR I tried isa=>'Any' sub _init{ my $self = shift; $self->CONFIG(Package::System::Config->new()); #not executing after that } sub start{ my $self = shift; $self->_init(); # not executing after _init() ......... } 1;
package Package::Contol::Base::Daemon::Server; use Moose; has 'DAEMON' => (is=>rw,isa=>'Object'); 1;
'Package' it's just sample. I cannot show real module name for some reason, sorry.

Replies are listed 'Best First'.
Re^3: Object not created as well with Moose
by ww (Archbishop) on Dec 10, 2008 at 22:55 UTC
    Try re-reading Corion's comment.

    It points out a typo in your SOPW.

Re^3: Object not created as well with Moose
by stvn (Monsignor) on Dec 12, 2008 at 04:59 UTC

    If you wrap your Moose class definitions in a BEGIN {} block it should work correctly. This is needed because the Moose "keywords" are just plain perl functions and so in the example you show above, they will not have run prior to your test code running.

    Also, _init has no meaning to Moose, you must be looking for BUILD.

    -stvn