> Note that my intention is not to store children objects inside the father: in my project i store a configuration for various jobs to be executed and foreach one i instantiate a new object and i run it
So i have not to store children objects; i rather have an object that can do an action OR can load a serie of small configuration e instantiate children to do each one one action. Like:
my $obj = new->( arg => 23); $obj->run(); # run will use 23 # OR INSTEAD: my $obj = new->( configuration => file ); # this will load [12, 23, 15 +] into $obj->{ container } $obj->run_all(); sub run_all{ my $self = shift; foreach my $it ( @{$obj->{ container }} ){ my $new_obj = ref($self)->new($it); $new_obj->run; } } # update: i had Class instead of new in the above: corrected
It is that bad? I suppose no..
I'd go with ref($self)->new($it) instead of __PACKAGE__->new($it) because seems more clear even if i have no intention to subclassing.. it is already a mess ;=)
> Or once the object's been constructed, it's guaranteed to be valid?
Yes, it is supposed to be like this; once instantiated the object is guaranteed to be valid.
Anyway, now that the confusion is away from my mind, I know what i intended to write: infact new is a normal subroutine, but what i forgot is that it shift the package name!!
What i intended to write was: new(__PACKAGE__,$it)
L*
In reply to Re^2: calling new inside the same module?
by Discipulus
in thread calling new inside the same module?
by Discipulus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |