better
[gitmo/Class-MOP.git] / t / 030_method.t
CommitLineData
cbd9f942 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
de19f115 6use Test::More tests => 18;
cbd9f942 7use Test::Exception;
8
9BEGIN {
727919c5 10 use_ok('Class::MOP');
cbd9f942 11 use_ok('Class::MOP::Method');
12}
13
a4258ffd 14my $method = Class::MOP::Method->wrap(sub { 1 });
de19f115 15is($method->meta, Class::MOP::Method->meta, '... instance and class both lead to the same meta');
16
17is($method->package_name, 'main', '... our package is main::');
18is($method->name, '__ANON__', '... our sub name is __ANON__');
22286063 19
cbd9f942 20my $meta = Class::MOP::Method->meta;
21isa_ok($meta, 'Class::MOP::Class');
22
de19f115 23foreach my $method_name (qw(
a4258ffd 24 wrap
de19f115 25 package_name
26 name
27 )) {
28 ok($meta->has_method($method_name), '... Class::MOP::Method->has_method(' . $method_name . ')');
29 my $method = $meta->get_method($method_name);
30 is($method->package_name, 'Class::MOP::Method', '... our package is Class::MOP::Method');
31 is($method->name, $method_name, '... our sub name is "' . $method_name . '"');
cbd9f942 32}
33
34dies_ok {
a4258ffd 35 Class::MOP::Method->wrap()
cbd9f942 36} '... bad args for &wrap';
37
38dies_ok {
a4258ffd 39 Class::MOP::Method->wrap('Fail')
cbd9f942 40} '... bad args for &wrap';
41
42dies_ok {
a4258ffd 43 Class::MOP::Method->wrap([])
cbd9f942 44} '... bad args for &wrap';