Include method name in immutable methods (fixes #49680)
[gitmo/Class-MOP.git] / t / 309_subname.t
CommitLineData
bfa0d9f8 1use strict;
2use warnings;
3
4use Test::More tests => 6;
5
6use Class::MOP;
7
8{
9
10 package Origin;
11 sub bar { ( caller(0) )[3] }
12
13 package Foo;
14}
15
16my $Foo = Class::MOP::Class->initialize('Foo');
17
18$Foo->add_method( foo => sub { ( caller(0) )[3] } );
19
20is_deeply(
21 [ Class::MOP::get_code_info( $Foo->get_method('foo')->body ) ],
22 [ "Foo", "foo" ],
23 "subname applied to anonymous method",
24);
25
26is( Foo->foo, "Foo::foo", "caller() aggrees" );
27
28$Foo->add_method( bar => \&Origin::bar );
29
30is( Origin->bar, "Origin::bar", "normal caller() operation in unrelated class" );
31
32is_deeply(
33 [ Class::MOP::get_code_info( $Foo->get_method('foo')->body ) ],
34 [ "Foo", "foo" ],
35 "subname not applied if a name already exists",
36);
37
38is( Foo->bar, "Origin::bar", "caller aggrees" );
39
40is( Origin->bar, "Origin::bar", "unrelated class untouched" );