bunch of stuff
[gitmo/Class-MOP.git] / t / 030_method.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 18;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Class::MOP');    
11     use_ok('Class::MOP::Method');
12 }
13
14 my $method = Class::MOP::Method->new(sub { 1 });
15 is($method->meta, Class::MOP::Method->meta, '... instance and class both lead to the same meta');
16
17 is($method->package_name, 'main', '... our package is main::');
18 is($method->name, '__ANON__', '... our sub name is __ANON__');
19
20 my $meta = Class::MOP::Method->meta;
21 isa_ok($meta, 'Class::MOP::Class');
22
23 foreach my $method_name (qw(
24     new
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 . '"');  
32 }
33
34 dies_ok {
35     Class::MOP::Method->new()
36 } '... bad args for &wrap';
37
38 dies_ok {
39     Class::MOP::Method->new('Fail')
40 } '... bad args for &wrap';
41
42 dies_ok {
43     Class::MOP::Method->new([])
44 } '... bad args for &wrap';