in reply to calling new inside the same module?

If you call the new subroutine, you need to give it a proper first argument:

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

Replies are listed 'Best First'.
Re^2: calling new inside the same module?
by Discipulus (Canon) on Nov 26, 2018 at 13:04 UTC
    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.

      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.

      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.