adding more crap
[gitmo/Class-MOP.git] / t / 003_methods.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More no_plan => 1;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Class::MOP');   
11     use_ok('Class::MOP::Class');        
12 }
13
14 {   
15     package Foo;
16     
17     # import a sub
18     use Scalar::Util 'blessed'; 
19     
20     # define a sub in package
21     sub bar { 'Foo::bar' } 
22 }
23
24 my $Foo = Foo->meta;
25
26 my $foo = sub { 'Foo::foo' };
27
28 lives_ok {
29     $Foo->add_method('foo' => $foo);
30 } '... we added the method successfully';
31
32 ok($Foo->has_method('foo'), '... Foo->has_method(foo) (defined with Sub::Name)');
33 ok(!$Foo->has_method('blessed'), '... !Foo->has_method(blessed) (imported into Foo)');
34 ok($Foo->has_method('bar'), '... Foo->has_method(bar) (defined in Foo)');
35
36 is($Foo->get_method('foo'), $foo, '... Foo->get_method(foo) == \&foo');
37
38 is(Foo->foo(), 'Foo::foo', '... Foo->foo() returns "Foo::foo"');