in reply to Re: calling new inside the same module?
in thread calling new inside the same module?

Thanks Corion

anyway with push @{ $self->{ stored } }, $self->new( $it ); I get: Attempt to bless into a reference at Exp.pm line 11.

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.

Replies are listed 'Best First'.
Re^3: calling new inside the same module?
by Corion (Patriarch) on Nov 26, 2018 at 13:13 UTC

    Then you need to either use (ref $self)->new(...) or have your constructor accept both, a reference or a string (that is, doing the my  $class = ref $self || $self;). Having such a dual-use constructor makes or at least made some people scream in agony, but I never really understood why.

Re^3: calling new inside the same module?
by Your Mother (Archbishop) on Nov 26, 2018 at 16:20 UTC

    In addition to what Corion already said, this is an option–

        push @{ $self->{ stored } }, __PACKAGE__->new( $it );

    Seems like an odd code design though. The container type is the contained type.

      __PACKAGE__->new() doesn't play as nicely with subclasses. ref($self)->new() is usually what you want.