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 :  /usr/share/doc/perl-Moose/t/cmop/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/perl-Moose/t/cmop/rebless_instance_away.t
use strict;
use warnings;
use Test::More;
use Class::MOP;

my @calls;

do {
    package My::Meta::Class;
    use parent 'Class::MOP::Class';

    sub rebless_instance_away {
        push @calls, [@_];
        shift->SUPER::rebless_instance_away(@_);
    }
};

do {
    package Parent;
    use metaclass 'My::Meta::Class';

    package Child;
    use metaclass 'My::Meta::Class';
    use parent -norequire => 'Parent';
};

my $person = Parent->meta->new_object;
Child->meta->rebless_instance($person);

is(@calls, 1, "one call to rebless_instance_away");
is($calls[0][0]->name, 'Parent', 'rebless_instance_away is called on the old metaclass');
is($calls[0][1], $person, 'with the instance');
is($calls[0][2]->name, 'Child', 'and the new metaclass');
splice @calls;

Child->meta->rebless_instance($person, foo => 1);
is($calls[0][0]->name, 'Child');
is($calls[0][1], $person);
is($calls[0][2]->name, 'Child');
is($calls[0][3], 'foo');
is($calls[0][4], 1);
splice @calls;

done_testing;

Hry