BEGIN {
$^P = 831;
}
sub
DB::DB {}
my
(
$foo_role_start
,
$foo_role_end
,
$foo_start_1
,
$foo_end_1
,
$foo_start_2
,
$foo_end_2
);
{
$foo_role_start
= __LINE__ + 1;
sub
foo_role {
return
'FooRole::foo_role'
;
}
$foo_role_end
= __LINE__ - 1;
}
{
$foo_start_1
= __LINE__ + 1;
sub
foo {
return
'foo'
;
}
$foo_end_1
= __LINE__ - 1;
no
Moose;
}
{
$foo_start_2
= __LINE__ + 1;
sub
foo {
return
'bar'
;
}
$foo_end_2
= __LINE__ - 1;
no
Moose;
}
my
$bar_object
= Bar->new();
isa_ok(Foo->meta->get_method(
'foo'
),
'Moose::Meta::Method'
);
isa_ok(Bar->meta->get_method(
'foo'
),
'Moose::Meta::Method'
);
isa_ok(Foo->meta->get_method(
'foo_role'
),
'Moose::Meta::Method'
);
is(
$bar_object
->foo_role(),
'FooRole::foo_role'
,
'Bar object has access to foo_role method'
);
my
$bar_meta
= Bar->meta;
like(
$DB::sub
{
"Bar::foo"
},
qr/add_method_debugmode\.t:($foo_start_2)-($foo_end_2)/
,
"Check line numbers for Bar::foo (initial)"
);
$bar_meta
->_restore_metamethods_from(
$bar_meta
);
like(
$DB::sub
{
"Foo::foo"
},
qr/add_method_debugmode\.t:($foo_start_1)-($foo_end_1)/
,
"Check line numbers for Foo::foo (after _restore)"
);
like(
$DB::sub
{
"Bar::foo"
},
qr/add_method_debugmode\.t:($foo_start_2)-($foo_end_2)/
,
"Check line numbers for Bar::foo (after _restore)"
);
is( exception {
$bar_meta
=
$bar_meta
->reinitialize(
'Bar'
);
},
undef
);
isa_ok(Bar->meta->get_method(
'foo'
),
'Moose::Meta::Method'
);
like(
$DB::sub
{
"Foo::foo"
},
qr/add_method_debugmode\.t:($foo_start_1)-($foo_end_1)/
,
"Check line numbers for Foo::foo (after reinitialize)"
);
like(
$DB::sub
{
"Bar::foo"
},
qr/add_method_debugmode\.t:($foo_start_2)-($foo_end_2)/
,
"Check line numbers for Bar::foo (after reinitialize)"
);
$bar_meta
->add_method(
'foo2'
=>
sub
{
return
'new method foo2'
; });
like(
$DB::sub
{
"Foo::foo"
},
qr/add_method_debugmode\.t:($foo_start_1)-($foo_end_1)/
,
"Check line numbers for Foo::foo (after add_method)"
);
like(
$DB::sub
{
"Bar::foo"
},
qr/add_method_debugmode\.t:($foo_start_2)-($foo_end_2)/
,
"Check line numbers for Bar::foo (after add_method)"
);
like(
$DB::sub
{
"Bar::foo2"
},
qr/(.*):(\d+)-(\d+)/
,
"Check for existence of Bar::foo2"
);
$bar_meta
->add_method(
'foo'
=>
$bar_meta
->method_metaclass->wrap(
package_name
=>
$bar_meta
->name,
name
=>
'foo'
,
body
=>
sub
{
return
'clobbered Bar::foo'
; }
)
);
unlike(
$DB::sub
{
"Bar::foo"
},
qr/add_method_debugmode\.t/
,
"Check that source file for Bar::foo has changed"
);
my
$foorole_meta
= FooRole->meta;
like(
$DB::sub
{
"FooRole::foo_role"
},
qr/add_method_debugmode\.t:($foo_role_start)-($foo_role_end)/
,
"Check line numbers for FooRole::foo_role (initial)"
);
$foorole_meta
->_restore_metamethods_from(
$foorole_meta
);
like(
$DB::sub
{
"FooRole::foo_role"
},
qr/add_method_debugmode\.t:($foo_role_start)-($foo_role_end)/
,
"Check line numbers for FooRole::foo_role (after _restore)"
);
is( exception {
$foorole_meta
->reinitialize(
'FooRole'
);
},
undef
);
isa_ok(FooRole->meta->get_method(
'foo_role'
),
'Moose::Meta::Method'
);
like(
$DB::sub
{
"FooRole::foo_role"
},
qr/add_method_debugmode\.t:($foo_role_start)-($foo_role_end)/
,
"Check line numbers for FooRole::foo_role (after reinitialize)"
);
$foorole_meta
->add_method(
'foo_role'
=>
$foorole_meta
->method_metaclass->wrap(
package_name
=>
$foorole_meta
->name,
name
=>
'foo_role'
,
body
=>
sub
{
return
'clobbered FooRole::foo_role'
; }
)
);
unlike(
$DB::sub
{
"FooRole::foo_role"
},
qr/add_method_debugmode\.t/
,
"Check that source file for FooRole::foo_role has changed"
);
done_testing;