4 use Test::More tests => 46;
8 use Class::MOP::Method;
11 my $method = Class::MOP::Method->wrap(
13 package_name => 'main',
16 is($method->meta, Class::MOP::Method->meta, '... instance and class both lead to the same meta');
18 is($method->package_name, 'main', '... our package is main::');
19 is($method->name, '__ANON__', '... our sub name is __ANON__');
20 is($method->fully_qualified_name, 'main::__ANON__', '... our subs full name is main::__ANON__');
21 is($method->original_method, undef, '... no original_method ');
22 is($method->original_package_name, 'main', '... the original_package_name is the same as package_name');
23 is($method->original_name, '__ANON__', '... the original_name is the same as name');
24 is($method->original_fully_qualified_name, 'main::__ANON__', '... the original_fully_qualified_name is the same as fully_qualified_name');
26 dies_ok { Class::MOP::Method->wrap } q{... can't call wrap() without some code};
27 dies_ok { Class::MOP::Method->wrap([]) } q{... can't call wrap() without some code};
28 dies_ok { Class::MOP::Method->wrap(bless {} => 'Fail') } q{... can't call wrap() without some code};
30 dies_ok { Class::MOP::Method->name } q{... can't call name() as a class method};
31 dies_ok { Class::MOP::Method->body } q{... can't call body() as a class method};
32 dies_ok { Class::MOP::Method->package_name } q{... can't call package_name() as a class method};
33 dies_ok { Class::MOP::Method->fully_qualified_name } q{... can't call fully_qualified_name() as a class method};
35 my $meta = Class::MOP::Method->meta;
36 isa_ok($meta, 'Class::MOP::Class');
38 foreach my $method_name (qw(
43 ok($meta->has_method($method_name), '... Class::MOP::Method->has_method(' . $method_name . ')');
44 my $method = $meta->get_method($method_name);
45 is($method->package_name, 'Class::MOP::Method', '... our package is Class::MOP::Method');
46 is($method->name, $method_name, '... our sub name is "' . $method_name . '"');
50 Class::MOP::Method->wrap()
51 } '... bad args for &wrap';
54 Class::MOP::Method->wrap('Fail')
55 } '... bad args for &wrap';
58 Class::MOP::Method->wrap([])
59 } '... bad args for &wrap';
62 Class::MOP::Method->wrap(sub { 'FAIL' })
63 } '... bad args for &wrap';
66 Class::MOP::Method->wrap(sub { 'FAIL' }, package_name => 'main')
67 } '... bad args for &wrap';
70 Class::MOP::Method->wrap(sub { 'FAIL' }, name => '__ANON__')
71 } '... bad args for &wrap';
73 my $clone = $method->clone(
74 package_name => 'NewPackage',
78 isa_ok($clone, 'Class::MOP::Method');
79 is($clone->package_name, 'NewPackage', '... cloned method has new package name');
80 is($clone->name, 'new_name', '... cloned method has new sub name');
81 is($clone->fully_qualified_name, 'NewPackage::new_name', '... cloned method has new fq name');
82 is($clone->original_method, $method, '... cloned method has correct original_method');
83 is($clone->original_package_name, 'main', '... cloned method has correct original_package_name');
84 is($clone->original_name, '__ANON__', '... cloned method has correct original_name');
85 is($clone->original_fully_qualified_name, 'main::__ANON__', '... cloned method has correct original_fully_qualified_name');
87 my $clone2 = $clone->clone(
88 package_name => 'NewerPackage',
92 is($clone2->package_name, 'NewerPackage', '... clone of clone has new package name');
93 is($clone2->name, 'newer_name', '... clone of clone has new sub name');
94 is($clone2->fully_qualified_name, 'NewerPackage::newer_name', '... clone of clone new fq name');
95 is($clone2->original_method, $clone, '... cloned method has correct original_method');
96 is($clone2->original_package_name, 'main', '... original_package_name follows clone chain');
97 is($clone2->original_name, '__ANON__', '... original_name follows clone chain');
98 is($clone2->original_fully_qualified_name, 'main::__ANON__', '... original_fully_qualified_name follows clone chain');