Commit | Line | Data |
c527660e |
1 | use strict; |
2 | use warnings; |
3 | use Test::Exception; |
4 | use Test::More tests => 8; |
5 | |
6 | use ok 'MooseX::Runnable'; |
7 | use ok 'MooseX::Runnable::Invocation'; |
8 | |
9 | { package Class; |
10 | use Moose; |
11 | with 'MooseX::Runnable'; |
12 | |
13 | sub run { |
14 | my ($self, @args) = @_; |
15 | my $result; |
16 | $result += $_ for @args; |
17 | return $result; |
18 | } |
19 | } |
20 | |
21 | my $invocation = MooseX::Runnable::Invocation->new( |
22 | class => 'Class', |
23 | ); |
24 | |
25 | ok $invocation; |
26 | |
27 | my $code; |
28 | lives_ok { |
29 | $code = $invocation->run(1,2,3); |
30 | } 'run lived'; |
31 | |
32 | is $code, 6, 'run worked'; |
33 | |
34 | { package MooseX::Runnable::Invocation::Plugin::ExitFixer; |
35 | use Moose::Role; |
36 | |
37 | around run => sub { |
38 | my ($next, $self, @args) = @_; |
39 | my $code = $self->$next(@args); |
40 | if($code){ return 0 } |
41 | else { confess "Exited with error." } |
42 | }; |
43 | } |
44 | |
45 | $invocation = MooseX::Runnable::Invocation->new( |
46 | class => 'Class', |
47 | plugins => ['+MooseX::Runnable::Invocation::Plugin::ExitFixer'], |
48 | ); |
49 | |
50 | ok $invocation; |
51 | |
52 | lives_ok { |
53 | $code = $invocation->run(1,2,3); |
54 | } 'run lived'; |
55 | |
56 | is $code, 0, 'run worked, and plugin changed the return code'; |