X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F030_method.t;h=f803363289a0cc1fb4d1217dfe822bdb7a775a46;hb=de0d4f939dec6cd53dcd304bb8dfca4f24ca47cb;hp=b0d4923196194d5b9074cde997e1807be2c61160;hpb=cbd9f94236f2c6be75aafbf52b796c754bc4d941;p=gitmo%2FClass-MOP.git diff --git a/t/030_method.t b/t/030_method.t index b0d4923..f803363 100644 --- a/t/030_method.t +++ b/t/030_method.t @@ -3,27 +3,41 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 25; use Test::Exception; BEGIN { + use_ok('Class::MOP'); use_ok('Class::MOP::Method'); } +my $method = Class::MOP::Method->wrap(sub { 1 }); +is($method->meta, Class::MOP::Method->meta, '... instance and class both lead to the same meta'); + +is($method->package_name, 'main', '... our package is main::'); +is($method->name, '__ANON__', '... our sub name is __ANON__'); +is($method->fully_qualified_name, 'main::__ANON__', '... our subs full name is main::__ANON__'); + +dies_ok { Class::MOP::Method->wrap } '... cant call this method without some code'; +dies_ok { Class::MOP::Method->wrap([]) } '... cant call this method without some code'; +dies_ok { Class::MOP::Method->wrap(bless {} => 'Fail') } '... cant call this method without some code'; + +dies_ok { Class::MOP::Method->name } '... cant call this method with a class'; +dies_ok { Class::MOP::Method->package_name } '... cant call this method with a class'; +dies_ok { Class::MOP::Method->fully_qualified_name } '... cant call this method with a class'; + my $meta = Class::MOP::Method->meta; isa_ok($meta, 'Class::MOP::Class'); - -{ - my $meta = Class::MOP::Method->meta(); - isa_ok($meta, 'Class::MOP::Class'); - - foreach my $method_name (qw( - meta - wrap - )) { - ok($meta->has_method($method_name), '... Class::MOP::Method->has_method(' . $method_name . ')'); - } +foreach my $method_name (qw( + wrap + package_name + name + )) { + ok($meta->has_method($method_name), '... Class::MOP::Method->has_method(' . $method_name . ')'); + my $method = $meta->get_method($method_name); + is($method->package_name, 'Class::MOP::Method', '... our package is Class::MOP::Method'); + is($method->name, $method_name, '... our sub name is "' . $method_name . '"'); } dies_ok {