Access to the Muses

Failed to figure out the syntax (which I'm sure is obvious, and I'm stupid) for clicking on the Moose array. This is a continuation of this issue . It seems to me that I need more than a simple value for my particular case. Trying to implement it using the salmon path (maybe this is wrong?), But I obviously am not doing it right.

use Moose::Role;
has 'tid_stack' => (
    traits => ['Array'],
    is     => 'rw',
    isa    => 'ArrayRef[Str]',
    default => sub { [] },
);


around 'process' => sub {
    my $orig = shift;
    my $self = shift;
    my ( $template ) = @_;

    $self->tid_stack->push( get_hrtid( $template ) );

    $self->$orig(@_)
};
+3
source share
1 answer

You misunderstood what you are doing traits => ['Array']. This allows you to customize methods handles. This prevents you from directly accessing type methods push. To do this, you need use Moose::Autobox(and you do not need an array trait).

Or you could do:

has 'tid_stack' => (
    traits => ['Array'],
    is     => 'rw',
    isa    => 'ArrayRef[Str]',
    default => sub { [] },
    handles => {
      push_tid => 'push',
    },
);

...

    $self->push_tid( get_hrtid( $template ) );
+9

Source: https://habr.com/ru/post/1759760/


All Articles