Thank you all monks,

> 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*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re^2: calling new inside the same module? by Discipulus
in thread calling new inside the same module? by Discipulus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.