File: basic.t

package info (click to toggle)
libmoosex-runnable-perl 0.10-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 400 kB
  • sloc: perl: 1,034; makefile: 5; sh: 1
file content (56 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use strict;
use warnings;
use Test::Fatal;
use Test::More tests => 8;

use ok 'MooseX::Runnable';
use ok 'MooseX::Runnable::Invocation';

{ package Class;
  use Moose;
  with 'MooseX::Runnable';

  sub run {
      my ($self, @args) = @_;
      my $result;
      $result += $_ for @args;
      return $result;
  }
}

my $invocation = MooseX::Runnable::Invocation->new(
    class => 'Class',
);

ok $invocation;

my $code;
is exception {
    $code = $invocation->run(1,2,3);
}, undef, 'run lived';

is $code, 6, 'run worked';

{ package MooseX::Runnable::Invocation::Plugin::ExitFixer;
  use Moose::Role;

  around run => sub {
      my ($next, $self, @args) = @_;
      my $code = $self->$next(@args);
      if($code){ return 0 }
      else { confess "Exited with error." }
  };
}

$invocation = MooseX::Runnable::Invocation->new(
    class   => 'Class',
    plugins => {'+MooseX::Runnable::Invocation::Plugin::ExitFixer' => []},
);

ok $invocation;

is exception {
    $code = $invocation->run(1,2,3);
}, undef, 'run lived';

is $code, 0, 'run worked, and plugin changed the return code';