Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/self/root/proc/self/root/usr/share/doc/perl-Moose/t/cmop/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/proc/self/root/usr/share/doc/perl-Moose/t/cmop/modify_parent_method.t
use strict;
use warnings;

use Test::More;
use Class::MOP;

my @calls;

{
    package Parent;

    use strict;
    use warnings;
    use metaclass;

    use Carp 'confess';

    sub method { push @calls, 'Parent::method' }

    package Child;

    use strict;
    use warnings;
    use metaclass;

    use parent -norequire => 'Parent';

    Child->meta->add_around_method_modifier(
        'method' => sub {
            my $orig = shift;
            push @calls, 'before Child::method';
            $orig->(@_);
            push @calls, 'after Child::method';
        }
    );
}

Parent->method;

is_deeply(
    [ splice @calls ],
    [
        'Parent::method',
    ]
);

Child->method;

is_deeply(
    [ splice @calls ],
    [
        'before Child::method',
        'Parent::method',
        'after Child::method',
    ]
);

{
    package Parent;

    Parent->meta->add_around_method_modifier(
        'method' => sub {
            my $orig = shift;
            push @calls, 'before Parent::method';
            $orig->(@_);
            push @calls, 'after Parent::method';
        }
    );
}

Parent->method;

is_deeply(
    [ splice @calls ],
    [
        'before Parent::method',
        'Parent::method',
        'after Parent::method',
    ]
);

Child->method;

TODO: {
    local $TODO = "pending fix";
    is_deeply(
        [ splice @calls ],
        [
            'before Child::method',
            'before Parent::method',
            'Parent::method',
            'after Parent::method',
            'after Child::method',
        ],
        "cache is correctly invalidated when the parent method is wrapped"
    );
}

done_testing;

Hry