File: invocation-plugin-initargs.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 (82 lines) | stat: -rw-r--r-- 1,648 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use strict;
use warnings;
use Test::Fatal;
use Test::More tests => 7;

use MooseX::Runnable::Invocation;

my $initargs;

{ package Class;
  use Moose;
  with 'MooseX::Runnable';
  sub run { 42 }
}

{ package Plugin;
  use Moose::Role;
  with 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs';

  has 'init' => ( is => 'ro', required => 1 );

  sub _build_initargs_from_cmdline {
      my $class = shift;
      $initargs = join ',', @_;
      return { init => 'args' };
  }
}

{ package Argless;
  use Moose::Role;
}

{ package Plugin2;
  use Moose::Role;
  with 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs';

  sub _build_initargs_from_cmdline {
      return { init => 'fails' };
  }
}

my $i;
is exception {
    $i = MooseX::Runnable::Invocation->new(
        class => 'Class',
        plugins => {
            '+Plugin' => [qw/foo bar baz/],
        },
    );
}, undef, 'created invocation without dying';

ok $i, 'created invocation ok';
ok $i->run, 'ran ok';
is $initargs, 'foo,bar,baz', 'got initargs';

like exception {
    MooseX::Runnable::Invocation->new(
        class => 'Class',
        plugins => {
            '+Argless' => ['args go here'],
        },
    );
}, qr/Perhaps/, 'argless + args = error';

is exception {
    MooseX::Runnable::Invocation->new(
        class => 'Class',
        plugins => {
            '+Argless' => [],
        },
    );
}, undef, 'argless + no args = ok';

is exception {
    MooseX::Runnable::Invocation->new(
        class => 'Class',
        plugins => {
            '+Plugin' => [],
            '+Plugin2' => [],
        },
    );
}, undef, 'two plugins with args compose OK';