line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Message::Passing::Role::CLIComponent; |
2
|
3
|
|
|
3
|
|
20
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
127
|
|
3
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
190
|
|
4
|
|
|
|
|
|
|
use Package::Variant |
5
|
3
|
|
|
|
|
26
|
importing => ['Moo::Role'], |
6
|
3
|
|
|
3
|
|
3023
|
subs => [ qw(has around before after with) ]; |
|
3
|
|
|
|
|
5436
|
|
7
|
3
|
|
|
3
|
|
11045
|
use MooX::Options; |
|
3
|
|
|
|
|
6239
|
|
|
3
|
|
|
|
|
21
|
|
8
|
3
|
|
|
3
|
|
2749
|
use MooX::Types::MooseLike::Base qw/ Str /; |
|
3
|
|
|
|
|
15854
|
|
|
3
|
|
|
|
|
339
|
|
9
|
3
|
|
|
3
|
|
30
|
use JSON (); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
60
|
|
10
|
3
|
|
|
3
|
|
2318
|
use Try::Tiny qw/ try /; |
|
3
|
|
|
|
|
2642
|
|
|
3
|
|
|
|
|
1031
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub make_variant { |
13
|
21
|
|
|
21
|
0
|
34177
|
my ($class, $target_package, %arguments) = @_; |
14
|
21
|
|
|
|
|
35
|
my $p = shift; |
15
|
|
|
|
|
|
|
|
16
|
21
|
|
|
|
|
41
|
my $name = $arguments{name}; |
17
|
21
|
|
|
|
|
36
|
my $has_default = exists $arguments{default}; |
18
|
21
|
100
|
|
|
|
61
|
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
|
|
79
|
"$has_default" ? ( default => sub { "$default" } ) : (), |
|
10
|
|
|
|
|
465
|
|
25
|
|
|
|
|
|
|
format => 's', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
option "${name}_options" => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
10
|
|
|
10
|
|
471
|
default => sub { {} }, |
31
|
14
|
|
|
14
|
|
580
|
isa => sub { ref($_[0]) eq 'HASH' }, |
32
|
|
|
|
|
|
|
coerce => sub { |
33
|
14
|
|
|
14
|
|
356
|
my $str = shift; |
34
|
14
|
100
|
|
|
|
46
|
if (! ref $str) { |
35
|
|
|
|
|
|
|
try { |
36
|
3
|
|
|
|
|
107
|
$str = JSON->new->relaxed->decode($str) |
37
|
3
|
|
|
|
|
19
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
14
|
|
|
|
|
342
|
$str; |
40
|
|
|
|
|
|
|
}, |
41
|
21
|
|
|
|
|
24765
|
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 |