p5-Mouse icon indicating copy to clipboard operation
p5-Mouse copied to clipboard

support method modifiers for overrided accessor

Open potatogim opened this issue 5 years ago • 1 comments

method modifiers for overrided attribute's accessors(reader/writer/accessor) are not executed when I try to use method modifiers in child class for that.

#!/usr/bin/env perl 

{
    package My;

    use Mouse;

    has 'name' =>
    (
        is      => 'ro',
        isa     => 'Str',
        default => 'noname',
        writer  => 'set_name',
    );

    around 'set_name' => sub
    {
        my $orig = shift;
        my $self = shift;

        print __PACKAGE__ . "::set_name\n";

        $self->$orig(@_);
    };
}

{
    package My::Child;

    use Mouse;

    extends 'My';

    has '+name' =>
    (
        coerce => 1,
    );

    around 'set_name' => sub
    {
        my $orig = shift;
        my $self = shift;

        print __PACKAGE__ . "::set_name\n";

        $self->$orig(@_);
    };
}

my $mychild = My::Child->new();

printf "Name: %s\n", $mychild->set_name('potatogim');
# before
> perl test.pl
My::Child::set_name
Name: potatogim

# after
> perl test.pl
My::Child::set_name
My::set_name
Name: potatogim

Signed-off-by: Ji-Hyeon Gim [email protected]

potatogim avatar May 10 '19 10:05 potatogim