Skip to content

Conversation

potatogim
Copy link

@potatogim potatogim commented May 11, 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 Moose;

    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 Moose;

    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
# Test result
> make test
...
t/type_constraints/type_names.t .................................. ok   
t/type_constraints/type_notation_parser.t ........................ ok    
t/type_constraints/types_and_undef.t ............................. ok    
t/type_constraints/union_is_a_type_of.t .......................... ok    
t/type_constraints/union_types.t ................................. ok    
t/type_constraints/union_types_and_coercions.t ................... ok    
t/type_constraints/util_find_type_constraint.t ................... ok    
t/type_constraints/util_more_type_coercion.t ..................... ok    
t/type_constraints/util_std_type_constraints.t ................... ok      
t/type_constraints/util_type_coercion.t .......................... ok    
t/type_constraints/util_type_constraints.t ....................... ok     
t/type_constraints/util_type_constraints_export.t ................ ok   
t/type_constraints/util_type_reloading.t ......................... ok   
t/type_constraints/with-specio.t ................................. ok   
t/type_constraints/with-type-tiny.t .............................. ok   
All tests successful.
Files=477, Tests=17326, 161 wallclock secs ( 2.83 usr  0.66 sys + 146.96 cusr 10.50 csys = 160.95 CPU)
Result: PASS

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

@potatogim potatogim force-pushed the accssor_modifier branch 7 times, most recently from c2666a4 to 3e5fc9a Compare May 16, 2019 16:35
@potatogim
Copy link
Author

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

@autarch autarch changed the title support method modifiers for overrided accessor support method modifiers for overridden accessor Dec 22, 2020
@potatogim potatogim closed this Aug 21, 2024
@potatogim potatogim reopened this Mar 17, 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