Skip to content

Conversation

@potatogim
Copy link

@potatogim potatogim commented May 10, 2019

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 potatogim force-pushed the accessor_modifier branch 2 times, most recently from 621b274 to b8a4474 Compare May 18, 2019 16:14
@potatogim potatogim force-pushed the accessor_modifier branch 4 times, most recently from 7717ac0 to cb711b9 Compare May 27, 2019 06:54
@potatogim
Copy link
Author

Hello! Could you let me know what kinds of things needed for this PR? 😄

@potatogim potatogim closed this Aug 21, 2024
@potatogim potatogim reopened this Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant