working without XS
[gitmo/Class-MOP.git] / t / 030_method.t
CommitLineData
cbd9f942 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
8048fe76 6use Test::More tests => 25;
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__');
d41e86f2 19is($method->fully_qualified_name, 'main::__ANON__', '... our subs full name is main::__ANON__');
22286063 20
8048fe76 21dies_ok { Class::MOP::Method->wrap } '... cant call this method without some code';
22dies_ok { Class::MOP::Method->wrap([]) } '... cant call this method without some code';
23dies_ok { Class::MOP::Method->wrap(bless {} => 'Fail') } '... cant call this method without some code';
24
25dies_ok { Class::MOP::Method->name } '... cant call this method with a class';
26dies_ok { Class::MOP::Method->package_name } '... cant call this method with a class';
27dies_ok { Class::MOP::Method->fully_qualified_name } '... cant call this method with a class';
28
cbd9f942 29my $meta = Class::MOP::Method->meta;
30isa_ok($meta, 'Class::MOP::Class');
31
de19f115 32foreach my $method_name (qw(
a4258ffd 33 wrap
de19f115 34 package_name
35 name
36 )) {
37 ok($meta->has_method($method_name), '... Class::MOP::Method->has_method(' . $method_name . ')');
38 my $method = $meta->get_method($method_name);
39 is($method->package_name, 'Class::MOP::Method', '... our package is Class::MOP::Method');
40 is($method->name, $method_name, '... our sub name is "' . $method_name . '"');
cbd9f942 41}
42
43dies_ok {
a4258ffd 44 Class::MOP::Method->wrap()
cbd9f942 45} '... bad args for &wrap';
46
47dies_ok {
a4258ffd 48 Class::MOP::Method->wrap('Fail')
cbd9f942 49} '... bad args for &wrap';
50
51dies_ok {
a4258ffd 52 Class::MOP::Method->wrap([])
cbd9f942 53} '... bad args for &wrap';