X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F030_method.t;h=a08103850f23d1fd8ab000c513fe80dae110bb19;hb=729fd9ba69ec6f9150504b4c24c46365fba7cdf4;hp=de488519bfe9fe70737a517316b8de60c4245bf2;hpb=aa448b163f4882fc3e4b92a1c1f22e3c9ad9f933;p=gitmo%2FClass-MOP.git diff --git a/t/030_method.t b/t/030_method.t index de48851..a081038 100644 --- a/t/030_method.t +++ b/t/030_method.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 8; +use Test::More tests => 28; use Test::Exception; BEGIN { @@ -11,19 +11,37 @@ BEGIN { use_ok('Class::MOP::Method'); } +my $method = Class::MOP::Method->wrap( + sub { 1 }, + package_name => 'main', + name => '__ANON__', +); +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( - 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 { @@ -36,4 +54,21 @@ dies_ok { dies_ok { Class::MOP::Method->wrap([]) -} '... bad args for &wrap'; \ No newline at end of file +} '... bad args for &wrap'; + +dies_ok { + Class::MOP::Method->wrap(sub { 'FAIL' }) +} '... bad args for &wrap'; + +dies_ok { + Class::MOP::Method->wrap(sub { 'FAIL' }, package_name => 'main') +} '... bad args for &wrap'; + +dies_ok { + Class::MOP::Method->wrap(sub { 'FAIL' }, name => '__ANON__') +} '... bad args for &wrap'; + + + + +