| 1 | package Message::Passing::Role::CLIComponent; | ||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | use Package::Variant | ||||||||||
| 5 | 3 | importing => ['Moo::Role'], | |||||||||
| 6 | 3 | ▶ | subs => [ qw(has around before after with) ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use MooX::Options; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use MooX::Types::MooseLike::Base qw/ Str /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use JSON (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use Try::Tiny qw/ try /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | sub make_variant { | ||||||||||
| 13 | 21 | ▶ | my ($class, $target_package, %arguments) = @_; | ||||||||
|
Subroutine
make_variant: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 14 | 21 | my $p = shift; | |||||||||
| 15 | |||||||||||
| 16 | 21 | my $name = $arguments{name}; | |||||||||
| 17 | 21 | my $has_default = exists $arguments{default}; | |||||||||
| 18 | 21 | ▶ | my $default = $has_default ? $arguments{default} : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | |||||||||||
| 20 | option "$name" => ( | ||||||||||
| 21 | isa => Str, | ||||||||||
| 22 | is => 'ro', | ||||||||||
| 23 | # required => "$has_default" ? 0 : 1, | ||||||||||
| 24 | 21 | ▶ | "$has_default" ? ( default => sub { "$default" } ) : (), | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 25 | format => 's', | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | option "${name}_options" => ( | ||||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | 10 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 14 | ▶ | isa => sub { ref($_[0]) eq 'HASH' }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 32 | coerce => sub { | ||||||||||
| 33 | 14 | ▶ | my $str = shift; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 34 | 14 | ▶ | if (! ref $str) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | try { | ||||||||||
| 36 | 3 | ▶ | $str = JSON->new->relaxed->decode($str) | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 3 | }; | |||||||||
| 38 | } | ||||||||||
| 39 | 14 | $str; | |||||||||
| 40 | }, | ||||||||||
| 41 | 21 | format => 's', | |||||||||
| 42 | ); | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 3 | 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<Package::Variant> role producer, which is used to provide a pair of attributes for name/options | ||||||||||
| 78 | as per the L<message-pass> 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 | <http://www.suretecsystems.com/> who sponsored its development for its | ||||||||||
| 95 | VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with | ||||||||||
| 96 | the SureVoIP API - | ||||||||||
| 97 | <http://www.surevoip.co.uk/support/wiki/api_documentation> | ||||||||||
| 98 | |||||||||||
| 99 | =head1 AUTHOR, COPYRIGHT AND LICENSE | ||||||||||
| 100 | |||||||||||
| 101 | See L<Message::Passing>. | ||||||||||
| 102 | |||||||||||
| 103 | =cut | ||||||||||