next-method
[gitmo/Moose.git] / t / 011_next_method.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 4;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Moose');           
11 }
12
13 {
14     package Foo;
15     use Moose;
16     
17     sub hello {
18         return 'Foo::hello';
19     }
20     
21     package Bar;
22     use Moose;
23     
24     extends 'Foo';
25     
26     sub hello {
27         return 'Bar::hello -> ' . next_method();
28     }
29     
30     package Baz;
31     use Moose;
32     
33     extends 'Bar';
34     
35     sub hello {
36         return 'Baz::hello -> ' . next_method();
37     }  
38     
39     sub goodbye {
40         return 'Baz::goodbye -> ' . next_method();
41     }      
42 }
43
44 my $baz = Baz->new;
45 isa_ok($baz, 'Baz');
46
47 is($baz->hello, 'Baz::hello -> Bar::hello -> Foo::hello', '... next_method did the right thing');
48
49 dies_ok {
50     $baz->goodbye
51 } '... no next method found, so we die';
52