Interact/Action.pm

filter: Statementstmt 62.1% 23 / 37 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 4 / 8 Podpod 66.6% 2 / 3 totaltotal 47.5% 29 / 61 CC 6 SCAR 21.4
CC
6
Cov
48%
BUILDARGS
20.0
clone
6.0
num_params
6.0
CRAP 8.5
« Interact/Logger.pm ↑ Summary Interact/Role/Iterator.pm »
1 package Net::CLI::Interact::Action;
2 {
3 1 $Net::CLI::Interact::Action::VERSION = '2.143070';
4 }
5  
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Sub::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use MooX::Types::MooseLike::Base qw(Any Bool Str ArrayRef InstanceOf RegexpRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Net::CLI::Interact::ActionSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 has 'type' => (
12 is => 'ro',
13 isa => quote_sub(
14 q{ die "$_[0] not send/match" unless $_[0] =~ m/^(?:send|match)$/ }),
15 required => 1,
16 );
17  
18 1 has 'value' => (
19 is => 'ro',
20 isa => Any, # FIXME 'Str|ArrayRef[RegexpRef]',
21 required => 1,
22 );
23  
24 1 has 'no_ors' => (
25 is => 'ro',
26 isa => Bool,
27 default => quote_sub('0'),
28 );
29  
30 1 has 'continuation' => (
31 is => 'rw',
32 isa => InstanceOf['Net::CLI::Interact::ActionSet'],
33 );
34  
35 has 'params' => (
36 is => 'rw',
37 isa => ArrayRef,
38 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 1 );
40  
41 1 has 'response' => (
42 is => 'rw',
43 isa => Str,
44 default => quote_sub(q{''}),
45 );
46  
47 1 has 'response_stash' => (
48 is => 'rw',
49 isa => Str,
50 default => quote_sub(q{''}),
51 );
52  
53 1 has 'prompt_hit' => (
54 is => 'rw',
55 isa => RegexpRef,
56 );
57  
58 sub BUILDARGS {
59 0 ▶ my ($class, @rest) = @_;
Subroutine BUILDARGS: not called CC=4 SCAR=30.0
Pod undocumented
60  
61 # accept single hash ref or naked hash
62 0 ▶ my $params = (ref {} eq ref $rest[0] ? $rest[0] : {@rest});
Branch: 1 branch
BranchTrueFalseTotal
ref {} eq ref $rest[0] ? : 0 0 0
63  
64 0 ▶ if (exists $params->{continuation} and ref [] eq ref $params->{continuation}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"continuation"} and ref [] eq ref $params->{"continuation"}) 0 0 0
Condition0%0/3
exists $params->{"continuation"} and ref [] eq ref $params->{"continuation"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $params->{"continuation"} and ref [] eq ref $params->{"continuation"}
exists $params->{"continuation"} ref [] eq ref $params->{"continuation"}
Truth table0%0/3
A and B
A= exists $params->{"continuation"}B= ref [] eq ref $params->{"continuation"}
ABresult
0X0
100
111
65 $params->{continuation} = Net::CLI::Interact::ActionSet->new({
66 actions => $params->{continuation},
67 0 });
68 }
69  
70 0 return $params;
71 }
72  
73 # Only a shallow copy so all the reference based slots still
74 # share data with the original Action's slots.
75 #
76 # I asked in #web-simple and was told that if the object is more magical than
77 # a simple hashref, then someone is trying to be far too clever. agreed!
78 sub clone {
79 0 ▶ my $self = shift;
Subroutine clone: not called CC=2 SCAR=17.9
Pod documented
80 0 ▶ bless({ %{$self}, %{(shift) || {}} }, ref $self)
Branch: 1 branch
BranchTrueFalseTotal
shift() or {} 0 0 0
81 }
82  
83 # count the number of sprintf parameters used in the value
84 sub num_params {
85 0 ▶ my $self = shift;
Subroutine num_params: not called CC=2 SCAR=17.9
Pod documented
86 0 ▶ return 0 if ref $self->value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->value 0 0 0
87 # this tricksy little number comes from the Perl FAQ
88 0 my $count = () = $self->value =~ m/(?<!%)%/g;
89 0 return $count;
90 }
91  
92 1 1;
93  
94 # ABSTRACT: Sent data or matched response from connected device
95  
96  
97 __END__
98 =pod
99  
100 =head1 NAME
101  
102 Net::CLI::Interact::Action - Sent data or matched response from connected device
103  
104 =head1 VERSION
105  
106 version 2.143070
107  
108 =head1 DESCRIPTION
109  
110 This class is used internally by L<Net::CLI::Interact> and it's unlikely that
111 an end-user will need to make use of Action objects directly. The interface is
112 documented here as a matter of record.
113  
114 An Action object represents I<either> some kind of text or command to send to
115 a connected device, I<or> a regular expression matching the response from a
116 connected device. Such Actions are built up into ActionSets which describe a
117 conversation with the connected device.
118  
119 If the Action is a C<send> type, then after execution it can be cloned and
120 augmented with the response text of the command. If the response is likely to
121 be paged, then the Action may also store instruction in how to trigger and
122 consume the pages.
123  
124 =head1 INTERFACE
125  
126 =head2 type
127  
128 Denotes the kind of Action, which may be C<send> or C<match>.
129  
130 =head2 value
131  
132 In the case of C<send>, a String command to send to the device. In the case of
133 C<match>, a regular expression reference to match response from the device. In
134 special circumstances an array reference of regular expression references is
135 also valid, and each will be checked for a match against the device response.
136  
137 =head2 no_ors
138  
139 Only applies to the C<send> kind. Whether to skip appending the I<output
140 record separator> (newline) to the C<send> command when sent to the connected
141 device.
142  
143 =head2 continuation
144  
145 Only applies to the C<send> kind. When response output is likely to be paged,
146 this stores an L<ActionSet|Net::CLI::Interact::ActionSet> that contains two
147 Actions: one for the C<match> which indicates output has paused at the end of
148 a page, and one for the C<send> command which triggers printing of the next
149 page.
150  
151 =head2 params
152  
153 Only applies to the C<send> kind, and contains a list of parameters which are
154 substituted into the C<value> using Perl's C<sprintf> function. Insufficient
155 parameters causes C<sprintf> to die.
156  
157 =head2 num_params
158  
159 Only applies to the C<send> kind, and returns the number of parameters which
160 are required for the current C<value>. Used for error checking when setting
161 C<params>.
162  
163 =head2 response
164  
165 A stash for the returned prompt which matched and triggered the end of this
166 action.
167  
168 =head2 response_stash
169  
170 A stash for the returned output following a C<send> command, but not including
171 the matched prompt which ended the action. This slot is used by the C<match>
172 action as it slurps output, but the content is then transferred over to the
173 partner C<send> in the ActionSet.
174  
175 =head2 prompt_hit
176  
177 When a command is successfully issued, the response is terminated by a prompt.
178 However that prompt can be one of a list, defined in the Action. This slot
179 records the regular expression from that list which was actually matched.
180  
181 =head2 clone
182  
183 Returns a new Action, which is a shallow clone of the existing one. All the
184 reference based slots will share data, but you can add (for example) a
185 C<response> without affecting the original Action. Used when preparing to
186 execute an Action which has been retrieved from the
187 L<Phrasebook|Net::CLI::Interact::Phrasebook>.
188  
189 =head1 AUTHOR
190  
191 Oliver Gorwits <oliver@cpan.org>
192  
193 =head1 COPYRIGHT AND LICENSE
194  
195 This software is copyright (c) 2014 by Oliver Gorwits.
196  
197 This is free software; you can redistribute it and/or modify it under
198 the same terms as the Perl 5 programming language system itself.
199  
200 =cut
201  
« Interact/Logger.pm ↑ Summary Interact/Role/Iterator.pm »