line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Message::Passing::Role::CLIComponent; |
2
|
3
|
|
|
3
|
|
14
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
114
|
|
3
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
115
|
|
4
|
|
|
|
|
|
|
use Package::Variant |
5
|
3
|
|
|
|
|
30
|
importing => ['Moo::Role'], |
6
|
3
|
|
|
3
|
|
1767
|
subs => [ qw(has around before after with) ]; |
|
3
|
|
|
|
|
4664
|
|
7
|
3
|
|
|
3
|
|
2239
|
use MooX::Options; |
|
3
|
|
|
|
|
3422
|
|
|
3
|
|
|
|
|
19
|
|
8
|
3
|
|
|
3
|
|
1881
|
use MooX::Types::MooseLike::Base qw/ Str /; |
|
3
|
|
|
|
|
13502
|
|
|
3
|
|
|
|
|
286
|
|
9
|
3
|
|
|
3
|
|
25
|
use JSON (); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
59
|
|
10
|
3
|
|
|
3
|
|
1465
|
use Try::Tiny qw/ try /; |
|
3
|
|
|
|
|
2235
|
|
|
3
|
|
|
|
|
955
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub make_variant { |
13
|
21
|
|
|
21
|
0
|
24945
|
my ($class, $target_package, %arguments) = @_; |
14
|
21
|
|
|
|
|
39
|
my $p = shift; |
15
|
|
|
|
|
|
|
|
16
|
21
|
|
|
|
|
28
|
my $name = $arguments{name}; |
17
|
21
|
|
|
|
|
31
|
my $has_default = exists $arguments{default}; |
18
|
21
|
100
|
|
|
|
45
|
my $default = $has_default ? $arguments{default} : undef; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
option "$name" => ( |
21
|
|
|
|
|
|
|
isa => Str, |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
# required => "$has_default" ? 0 : 1, |
24
|
21
|
100
|
|
10
|
|
69
|
"$has_default" ? ( default => sub { "$default" } ) : (), |
|
10
|
|
|
|
|
356
|
|
25
|
|
|
|
|
|
|
format => 's', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
option "${name}_options" => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
10
|
|
|
10
|
|
338
|
default => sub { {} }, |
31
|
14
|
|
|
14
|
|
367
|
isa => sub { ref($_[0]) eq 'HASH' }, |
32
|
|
|
|
|
|
|
coerce => sub { |
33
|
14
|
|
|
14
|
|
162
|
my $str = shift; |
34
|
14
|
100
|
|
|
|
37
|
if (! ref $str) { |
35
|
|
|
|
|
|
|
try { |
36
|
3
|
|
|
|
|
105
|
$str = JSON->new->relaxed->decode($str) |
37
|
3
|
|
|
|
|
21
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
14
|
|
|
|
|
278
|
$str; |
40
|
|
|
|
|
|
|
}, |
41
|
21
|
|
|
|
|
13783
|
format => 's', |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Message::Passing::Role::CLIComponent - Package::Variant providing 'foo' and 'foo_options' attributes |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
package My::Message::Passing::Script; |
54
|
|
|
|
|
|
|
use Moo; |
55
|
|
|
|
|
|
|
use MooX::Options; |
56
|
|
|
|
|
|
|
use Message::Passing::Role::CLIComponent; |
57
|
|
|
|
|
|
|
use Message::Passing::DSL; |
58
|
|
|
|
|
|
|
use namespace::clean -except => 'meta'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
with |
61
|
|
|
|
|
|
|
CLIComponent( name => 'input', default => 'STDIN' ), |
62
|
|
|
|
|
|
|
'Message::Passing::Role::Script'; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub build_chain { |
65
|
|
|
|
|
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
message_chain { |
67
|
|
|
|
|
|
|
input example => ( %{ $self->input_options }, output_to => 'test_out', class => $self->input, ); |
68
|
|
|
|
|
|
|
output test_out => ( ... ); |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__PACKAGE__->start unless caller; |
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 DESCRIPTION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
A L role producer, which is used to provide a pair of attributes for name/options |
78
|
|
|
|
|
|
|
as per the L script. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 ROLE PARAMETERS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 name |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
The name of the main attribute. An additional attribute called C<< "${name}_options" >> will also be added, |
85
|
|
|
|
|
|
|
which coerces a hashref from JSON. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 default |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
A default value for the main attribute. If this is not supplied, than the attribute will be required. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SPONSORSHIP |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This module exists due to the wonderful people at Suretec Systems Ltd. |
94
|
|
|
|
|
|
|
who sponsored its development for its |
95
|
|
|
|
|
|
|
VoIP division called SureVoIP for use with |
96
|
|
|
|
|
|
|
the SureVoIP API - |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 AUTHOR, COPYRIGHT AND LICENSE |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
See L. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |