bunch of stuff
[gitmo/Class-MOP.git] / t / 031_method_modifiers.t
CommitLineData
de19f115 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More no_plan => 18;
7use Test::Exception;
8
9BEGIN {
10 use_ok('Class::MOP');
11 use_ok('Class::MOP::Method');
12}
13
14my $trace = '';
15
16my $method = Class::MOP::Method->new(sub { $trace .= 'primary' });
17isa_ok($method, 'Class::MOP::Method');
18
19$method->();
20is($trace, 'primary', '... got the right return value from method');
21$trace = '';
22
23my $wrapped = $method->wrap();
24isa_ok($wrapped, 'Class::MOP::Method');
25
26$wrapped->();
27is($trace, 'primary', '... got the right return value from the wrapped method');
28$trace = '';
29
30lives_ok {
31 $wrapped->add_before_modifier(sub { $trace .= 'before -> ' });
32} '... added the before modifier okay';
33
34$wrapped->();
35is($trace, 'before -> primary', '... got the right return value from the wrapped method (w/ before)');
36$trace = '';
37
38lives_ok {
39 $wrapped->add_after_modifier(sub { $trace .= ' -> after' });
40} '... added the after modifier okay';
41
42$wrapped->();
43is($trace, 'before -> primary -> after', '... got the right return value from the wrapped method (w/ before)');
44$trace = '';