Interact/Phrasebook.pm

filter: Statementstmt 16.3% 24 / 147 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 21.7% 5 / 23 Podpod 75.0% 6 / 8 totaltotal 13.6% 35 / 257 CC 41 SCAR 42.8
CC
41
Cov
11%
load_phrasebooks
240.0
_resolve_matches
56.0
_gather_pb_from
42.0
CRAP 72.2
↑ Summary Interact/Role/Prompt.pm »
1 package Net::CLI::Interact::Phrasebook;
2 {
3 1 $Net::CLI::Interact::Phrasebook::VERSION = '2.143070';
4 }
5  
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooX::Types::MooseLike::Base qw(InstanceOf Str Any HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Net::CLI::Interact::ActionSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 has 'logger' => (
13 is => 'ro',
14 isa => InstanceOf['Net::CLI::Interact::Logger'],
15 required => 1,
16 );
17  
18 1 has 'personality' => (
19 is => 'rw',
20 isa => Str,
21 required => 1,
22 );
23  
24 1 has 'library' => (
25 is => 'lazy',
26 isa => Any, # FIXME 'Str|ArrayRef[Str]',
27 );
28  
29 sub _build_library {
30 1 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 my (undef, $directory, undef) = fileparse(
32 0 ▶ $INC{ 'Net/CLI/Interact.pm' }
Subroutine _build_library: not called CC=1 SCAR=6.9
33 );
34 0 return [ Path::Class::Dir->new($directory)
35 ->subdir("Interact", "phrasebook")->stringify ];
36 }
37  
38 has 'add_library' => (
39 is => 'rw',
40 isa => Any, # FIXME 'Str|ArrayRef[Str]',
41 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 1 );
43  
44 has '_prompt' => (
45 is => 'ro',
46 isa => HashRef[InstanceOf['Net::CLI::Interact::ActionSet']],
47 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 1 );
49  
50 sub prompt {
51 0 ▶ my ($self, $name) = @_;
Subroutine prompt: not called CC=2 SCAR=17.9
Pod documented
52 0 ▶ die "unknown prompt [$name]" unless $self->has_prompt($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_prompt($name) 0 0 0
53 0 return $self->_prompt->{$name};
54 }
55  
56 0 ▶sub prompt_names { return keys %{ (shift)->_prompt } }
Subroutine prompt_names: not called CC=1 SCAR=6.9
Pod documented
57  
58 sub has_prompt {
59 0 ▶ my ($self, $name) = @_;
Subroutine has_prompt: not called CC=3 SCAR=24.8
Pod documented
60 0 ▶ die "missing prompt name!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
61 unless defined $name and length $name;
62 0 return exists $self->_prompt->{$name};
63 }
64  
65 has '_macro' => (
66 is => 'ro',
67 isa => HashRef[InstanceOf['Net::CLI::Interact::ActionSet']],
68 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 1 );
70  
71 sub macro {
72 0 ▶ my ($self, $name) = @_;
Subroutine macro: not called CC=2 SCAR=17.9
Pod documented
73 0 ▶ die "unknown macro [$name]" unless $self->has_macro($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_macro($name) 0 0 0
74 0 return $self->_macro->{$name};
75 }
76  
77 0 ▶sub macro_names { return keys %{ (shift)->_macro } }
Subroutine macro_names: not called CC=1 SCAR=6.9
Pod documented
78  
79 sub has_macro {
80 0 ▶ my ($self, $name) = @_;
Subroutine has_macro: not called CC=3 SCAR=24.8
Pod documented
81 0 ▶ die "missing macro name!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
82 unless defined $name and length $name;
83 0 return exists $self->_macro->{$name};
84 }
85  
86 # matches which are prompt names are resolved to RegexpRefs
87 # and regexp provided by the user are inflated into RegexpRefs
88 sub _resolve_matches {
89 0 ▶ my ($self, $actions) = @_;
Subroutine _resolve_matches: not called CC=7 SCAR=40.3
90  
91 0 foreach my $a (@$actions) {
92 0 ▶ next unless $a->{type} eq 'match';
Branch: 1 branch
BranchTrueFalseTotal
unless $a->{"type"} eq "match" 0 0 0
93 0 ▶ next unless ref $a->{value} eq ref [];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $a->{"value"} eq ref [] 0 0 0
94  
95 0 my @newvals = ();
96 0 foreach my $v (@{ $a->{value} }) {
97 0 ▶ if ($v =~ m{^/} and $v =~ m{/$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ m[^/] and $v =~ m[/$]) { } 0 0 0
Condition0%0/3
$v =~ m[^/] and $v =~ m[/$]
!ll&&!rl&&r
000
MC/DC0%0/2
$v =~ m[^/] and $v =~ m[/$]
$v =~ m[^/] $v =~ m[/$]
Truth table0%0/3
A and B
A= $v =~ m[^/]B= $v =~ m[/$]
ABresult
0X0
100
111
98 0 $v =~ s{^/}{}; $v =~ s{/$}{};
99 0 push @newvals, qr/$v/;
100 }
101 else {
102 0 push @newvals, @{ $self->prompt($v)->first->value };
103 }
104 }
105  
106 0 $a->{value} = \@newvals;
107 }
108  
109 0 return $actions;
110 }
111  
112 # inflate the hashref into action objects
113 sub _bake {
114 0 ▶ my ($self, $data) = @_;
Subroutine _bake: not called CC=3 SCAR=24.8
115  
116 0 ▶ return unless ref $data eq ref {} and keys %$data;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq ref {} and keys %$data 0 0 0
Condition0%0/3
ref $data eq ref {} and keys %$data
!ll&&!rl&&r
000
MC/DC0%0/2
ref $data eq ref {} and keys %$data
ref $data eq ref {} keys %$data
Truth table0%0/3
A and B
A= ref $data eq ref {}B= keys %$data
ABresult
0X0
100
111
117 0 $self->logger->log('phrasebook', 'debug', 'storing', $data->{type}, $data->{name});
118  
119 0 my $slot = '_'. lc $data->{type};
120 $self->$slot->{$data->{name}}
121 = Net::CLI::Interact::ActionSet->new({
122 actions => $self->_resolve_matches($data->{actions})
123 0 });
124 }
125  
126 sub BUILD {
127 0 ▶ my $self = shift;
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
128 0 $self->load_phrasebooks;
129 }
130  
131 # parse phrasebook files and load action objects
132 sub load_phrasebooks {
133 0 ▶ my $self = shift;
Subroutine load_phrasebooks: not called CC=15 SCAR=54.8
Pod undocumented
134 0 my $data = {};
135 0 my $stash = { prompt => [], macro => [] };
136  
137 0 foreach my $file ($self->_find_phrasebooks) {
138 0 $self->logger->log('phrasebook', 'info', 'reading phrasebook', $file);
139 0 my @lines = $file->slurp;
140 0 ▶ while ($_ = shift @lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = shift @lines) 0 0 0
141 # Skip comments and empty lines
142 0 ▶ next if m/^(?:#|\s*$)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^(?:#|\s*$)/ 0 0 0
143  
144 0 ▶ if (m{^(prompt|macro)\s+(\w+)\s*$}) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^(prompt|macro)\s+(\w+)\s*$/) { } 0 0 0
elsif (/^\w/) { } 0 0 0
145 0 ▶ if (scalar keys %$data) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$data) 0 0 0
146 0 push @{ $stash->{$data->{type}} }, $data;
147 }
148 0 $data = {type => $1, name => $2};
149 0 next;
150 }
151 # skip new sections we don't yet understand
152 elsif (m{^\w}) {
153 0 ▶ $_ = shift @lines until m{^(?:prompt|macro)};
Branch: 1 branch
BranchTrueFalseTotal
/^(?:prompt|macro)/ or do { $_ = shift @lines } 0 0 0
154 0 unshift @lines, $_;
155 0 next;
156 }
157  
158 0 ▶ if (m{^\s+send\s+(.+)$}) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s+send\s+(.+)$/) 0 0 0
159 0 my $value = $1;
160 0 $value =~ s/^["']//; $value =~ s/["']$//;
161 0 push @{ $data->{actions} }, {
162 type => 'send', value => $value,
163 };
164 0 next;
165 }
166  
167 0 ▶ if (m{^\s+put\s+(.+)$}) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s+put\s+(.+)$/) 0 0 0
168 0 my $value = $1;
169 0 $value =~ s/^["']//; $value =~ s/["']$//;
170 0 push @{ $data->{actions} }, {
171 type => 'send', value => $value, no_ors => 1,
172 };
173 0 next;
174 }
175  
176 0 ▶ if (m{^\s+match\s+(.+)\s*$}) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s+match\s+(.+)\s*$/) 0 0 0
177 0 my @vals = split m/\s+or\s+/, $1;
178 0 ▶ if (scalar @vals) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @vals) 0 0 0
179 0 push @{ $data->{actions} },
180 {type => 'match', value => \@vals};
181 0 next;
182 }
183 }
184  
185 0 ▶ if (m{^\s+follow\s+/(.+)/\s+with\s+(.+)\s*$}) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[^\s+follow\s+/(.+)/\s+with\s+(.+)\s*$]) 0 0 0
186 0 my ($match, $send) = ($1, $2);
187 0 $send =~ s/^["']//; $send =~ s/["']$//;
188 $data->{actions}->[-1]->{continuation} = [
189 0 {type => 'match', value => [qr/$match/]},
190 {type => 'send', value => eval "qq{$send}", no_ors => 1}
191 ];
192 0 next;
193 }
194  
195 0 die "don't know what to do with this phrasebook line:\n", $_;
196 }
197 # last entry in the file needs baking
198 0 push @{ $stash->{$data->{type}} }, $data;
199 0 $data = {};
200 }
201  
202 # bake the prompts before the macros, to allow macros to reference
203 # prompts which appear later in the same file.
204 0 foreach my $t (qw/prompt macro/) {
205 0 foreach my $d (@{ $stash->{$t} }) {
206 0 $self->_bake($d);
207 }
208 }
209 }
210  
211 # finds the path of Phrasebooks within the Library leading to Personality
212 sub _find_phrasebooks {
213 0 ▶ my $self = shift;
Subroutine _find_phrasebooks: not called CC=4 SCAR=30.0
214 0 ▶ my @libs = (ref $self->library ? @{$self->library} : ($self->library));
Branch: 1 branch
BranchTrueFalseTotal
ref $self->library ? : 0 0 0
215 0 ▶ my @alib = (ref $self->add_library ? @{$self->add_library} : ($self->add_library));
Branch: 1 branch
BranchTrueFalseTotal
ref $self->add_library ? : 0 0 0
216  
217 # first find the (relative) path for the requested personality
218 # then within each of @libs gather the files along that path
219  
220 0 my $target = $self->_find_personality_in( @libs, @alib );
221 0 my @files = $self->_gather_pb_from( $target, @libs, @alib );
222  
223 0 ▶ die (sprintf "Personality [%s] contains no phrasebook files!\n",
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @files 0 0 0
224 $self->personality) unless scalar @files;
225 0 return @files;
226 }
227  
228 sub _find_personality_in {
229 0 ▶ my ($self, @libs) = @_;
Subroutine _find_personality_in: not called CC=3 SCAR=24.8
230 0 my $target = undef;
231  
232 0 foreach my $lib (@libs) {
233 Path::Class::Dir->new($lib)->recurse(callback => sub {
234 0 ▶ return unless $_[0]->is_dir;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->is_dir 0 0 0
235 0 ▶ $target = Path::Class::Dir->new($_[0])->relative($lib)
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->dir_list(-1) eq $self->personality 0 0 0
236 if $_[0]->dir_list(-1) eq $self->personality
237 0 });
238 0 ▶ last if defined $target;
Branch: 1 branch
BranchTrueFalseTotal
if defined $target 0 0 0
239 }
240 0 return $target;
241 }
242  
243 sub _gather_pb_from {
244 0 ▶ my ($self, $target, @libs) = @_;
Subroutine _gather_pb_from: not called CC=6 SCAR=37.4
245 0 my @files = ();
246  
247 0 ▶ return () unless $target->isa('Path::Class::Dir') and $target->is_relative;
Branch: 1 branch
BranchTrueFalseTotal
unless $target->isa("Path::Class::Dir") and $target->is_relative 0 0 0
Condition0%0/3
$target->isa("Path::Class::Dir") and $target->is_relative
!ll&&!rl&&r
000
MC/DC0%0/2
$target->isa("Path::Class::Dir") and $target->is_relative
$target->isa("Path::Class::Dir") $target->is_relative
Truth table0%0/3
A and B
A= $target->isa("Path::Class::Dir")B= $target->is_relative
ABresult
0X0
100
111
248  
249 0 foreach my $lib (@libs) {
250 0 my $root = Path::Class::Dir->new($lib);
251  
252 0 foreach my $part ($target->dir_list) {
253 0 $root = $root->subdir($part);
254 # $self->logger->log('phrasebook', 'debug', sprintf 'searching in [%s]', $root);
255 0 ▶ last if not -d $root->stringify;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $root->stringify 0 0 0
256  
257 push @files,
258 0 sort {$a->basename cmp $b->basename}
259 0 grep { not $_->is_dir } $root->children(no_hidden => 1);
260 }
261 }
262 0 return @files;
263 }
264  
265 1 1;
266  
267 # ABSTRACT: Load command phrasebooks from a Library
268  
269  
270 __END__
271 =pod
272  
273 =head1 NAME
274  
275 Net::CLI::Interact::Phrasebook - Load command phrasebooks from a Library
276  
277 =head1 VERSION
278  
279 version 2.143070
280  
281 =head1 DESCRIPTION
282  
283 A command phrasebook is where you store the repeatable sequences of commands
284 which can be sent to connected network devices. An example would be a command
285 to show the configuration of a device: storing this in a phrasebook (sometimes
286 known as a dictionary) saves time and effort.
287  
288 This module implements the loading and preparing of phrasebooks from an
289 on-disk file-based hierarchical library, and makes them available to the
290 application as smart objects for use in L<Net::CLI::Interact> sessions.
291 Entries in the phrasebook will be one of the following types:
292  
293 =over 4
294  
295 =item Prompt
296  
297 Named regular expressions that match the content of a single line of text in
298 the output returned from a connected device. They are a demarcation between
299 commands sent and responses returned.
300  
301 =item Macro
302  
303 Alternating sequences of command statements sent to the device, and regular
304 expressions to match the response. There are different kinds of Macro,
305 explained below.
306  
307 =back
308  
309 The named regular expressions used in Prompts and Macros are known as I<Match>
310 statements. The command statements in Macros which are sent to the device are
311 known as I<Send> statements. That is, Prompts and Macros are built from one or
312 more Match and Send statements.
313  
314 Each Send or Match statement becomes an instance of the
315 L<Net::CLI::Interact::Action> class. These are built up into Prompts and
316 Macros, which become instances of the L<Net::CLI::Interact::ActionSet> class.
317  
318 =head1 USAGE
319  
320 A phrasebook is a plain text file containing named Prompts or Macros. Each
321 file exists in a directory hierarchy, such that files "deeper" in the
322 hierarchy have their entries override the similarly named entries higher up.
323 For example:
324  
325 /dir1/file1
326 /dir1/file2
327 /dir1/dir2/file3
328  
329 Entries in C<file3> sharing a name with any entries from C<file1> or C<file2>
330 will take precedence. Those in C<file2> will also override entries in
331 C<file1>, because asciibetical sorting places the files in that order, and
332 later definitions with the same name and type override earlier ones.
333  
334 When this module is loaded, a I<personality> key is required. This locates a
335 directory on disk, and then the files in that directory and all its ancestors
336 in the hierarchy are loaded. The directories to search are specified by two
337 I<Library> options (see below). All phrasebooks matching the given
338 I<personality> are loaded, allowing a user to override or augment the default,
339 shipped phrasebooks.
340  
341 =head1 INTERFACE
342  
343 =head2 new( \%options )
344  
345 This takes the following options, and returns a loaded phrasebook object:
346  
347 =over 4
348  
349 =item C<< personality => $directory >> (required)
350  
351 The name of a directory component on disk. Any files higher in the libraries
352 hierarchy are also loaded, but entries in files contained within this
353 directory, or "closer" to it, will take precedence.
354  
355 =item C<< library => $directory | \@directories >>
356  
357 First library hierarchy, specified either as a single directory or a list of
358 directories that are searched in order. The idea is that this option be set in
359 your application code, perhaps specifying some directory of phrasebooks
360 shipped with the distribution.
361  
362 =item C<< add_library => $directory | \@directories >>
363  
364 Second library hierarchy, specified either as a single directory or a list of
365 directories that are searched in order. This parameter is for the end-user to
366 provide the location(s) of their own phrasebook(s). Any entries found via this
367 path will override those found via the first C<library> path.
368  
369 =back
370  
371 =head2 prompt( $name )
372  
373 Returns the Prompt associated to the given C<$name>, or throws an exception if
374 no such prompt can be found. The returned object is an instance of
375 L<Net::CLI::Interact::ActionSet>.
376  
377 =head2 has_prompt( $name )
378  
379 Returns true if a prompt of the given C<$name> exists in the loaded phrasebooks.
380  
381 =head2 prompt_names
382  
383 Returns a list of the names of the current loaded Prompts.
384  
385 =head2 macro( $name )
386  
387 Returns the Macro associated to the given C<$name>, or throws an exception if
388 no such macro can be found. The returned object is an instance of
389 L<Net::CLI::Interact::ActionSet>.
390  
391 =head2 has_macro( $name )
392  
393 Returns true if a macro of the given C<$name> exists in the loaded phrasebooks.
394  
395 =head2 macro_names
396  
397 Returns a list of the names of the current loaded Macros.
398  
399 =head1 PHRASEBOOK FORMAT
400  
401 =head2 Prompt
402  
403 A Prompt is a named regular expression which matches the content of a single
404 line of text. Here is an example:
405  
406 prompt configure
407 match /\(config[^)]*\)# ?$/
408  
409 On the first line is the keyword C<prompt> followed by the name of the Prompt,
410 which must be a valid Perl identifier (letters, numbers, underscores only).
411  
412 On the immediately following line is the keyword C<match> followed by a
413 regular expression, enclosed in two forward-slash characters. Currently, no
414 alternate bookend characters are supported, nor are regular expression
415 modifiers (such as C<xism>) outside of the match, but you can of course
416 include them within.
417  
418 The Prompt is used to find out when the connected CLI has emitted all of the
419 response to a command. Try to make the Prompt as specific as possible,
420 including line-end anchors. Remember that it will be matched against one line
421 of text, only.
422  
423 =head2 Macro
424  
425 In general, Macros are alternating sequences of commands to send to the
426 connected CLI, and regular expressions to match the end of the returned
427 response. Macros are useful for issuing commands which have intermediate
428 prompts, or confirmation steps. They also support the I<slurping> of
429 additional output when the connected CLI has split the response into pages.
430  
431 At its simplest a Macro can be just one command:
432  
433 macro show_int_br
434 send show ip int br
435 match /> ?$/
436  
437 On the first line is the keyword C<macro> followed by the name of the Macro,
438 which must be a valid Perl identifier (letters, numbers, underscores only).
439  
440 On the immediately following line is the keyword C<send> followed by a space
441 and then any text up until the end of the line, and if you want to include
442 whitespace at the beginning or end of the command, use quotes. This text is
443 sent to the connected CLI as a single command statement. The next line
444 contains the keyword C<match> followed by the Prompt (regular expression)
445 which will terminate gathering of returned output from the sent command.
446  
447 Macros support the following features:
448  
449 =over 4
450  
451 =item Automatic Matching
452  
453 Normally, you ought always to specify C<send> statements along with a
454 following C<match> statement so that the module can tell when the output from
455 your command has ended. However you can omit any Match and the module will
456 insert either the current C<prompt> value if set by the user, or the last
457 Prompt from the last Macro. So the previous example could be re-written as:
458  
459 macro show_int_br
460 send show ip int br
461  
462 You can have as many C<send> statements as you like, and the Match statements
463 will be inserted for you:
464  
465 macro show_int_br_and_timestamp
466 send show ip int br
467 send show clock
468  
469 However it is recommended that this type of sequence be implemented as
470 individual commands (or separate Macros) rather than a single Macro, as it
471 will be easier for you to retrieve the command response(s). Normally the
472 Automatic Matching is used just to allow missing off of the final Match
473 statement when it's the same as the current Prompt.
474  
475 =item Format Interpolation
476  
477 Each C<send> statement is in fact run through Perl's C<sprintf> command, so
478 variables may be interpolated into the statement using standard C<"%"> fields.
479 For example:
480  
481 macro show_int_x
482 send show interface %s
483  
484 The method for passing variables into the module upon execution of this Macro
485 is documented in L<Net::CLI::Interact::Role::Engine>. This feature is useful
486 for username/password prompts.
487  
488 =item Named Match References
489  
490 If you're going to use the same Match (regular expression) in a number of
491 Macros, then set it up as a Prompt (see above) and refer to it by name,
492 instead:
493  
494 prompt priv_exec
495 match /# ?$/
496
497 macro to_priv_exec
498 send enable
499 match /[Pp]assword: ?$/
500 send %s
501 match priv_exec
502  
503 As you can see, in the case of the last Match, we have the keyword C<match>
504 followed by the name of a defined Prompt. To match multiple defined Prompts
505 use this syntax (with as many named references as you like):
506  
507 macro to_privileged
508 send enable
509 match username_prompt or priv_exec
510  
511 =item Continuations
512  
513 Sometimes the connected CLI will not know it's talking to a program and so
514 paginate the output (that is, split it into pages). There is usually a
515 keypress required between each page. This is supported via the following
516 syntax:
517  
518 macro show_run
519 send show running-config
520 follow / --More-- / with ' '
521  
522 On the line following the C<send> statement is the keyword C<follow> and a
523 regular expression enclosed in forward-slashes. This is the Match which will,
524 if seen in the command output, trigger the continuation. On the line you then
525 have the keyword C<with> followed by a space and some text, until the end of
526 the line. If you need to enclose whitespace use quotes, as in the example.
527  
528 The module will send the continuation text and gobble the matched prompt from
529 the emitted output so you only have one complete piece of text returned, even
530 if split over many pages. The sent text can contain metacharacters such as
531 C<\n> for a newline.
532  
533 Note that in the above example the C<follow> statement should be seen as an
534 extension of the C<send> statement. There is still an implicit Match prompt
535 added at the end of this Macro, as per Automatic Matching, above.
536  
537 =item Line Endings
538  
539 Normally all sent command statements are appended with a newline (or the value
540 of C<ors>, if set). To suppress that feature, use the keyword C<put> instead
541 of C<send>. However this does not prevent the Format Interpolation via
542 C<sprintf> as described above (simply use C<"%%"> to get a literal C<"%">).
543  
544 =back
545  
546 =head1 AUTHOR
547  
548 Oliver Gorwits <oliver@cpan.org>
549  
550 =head1 COPYRIGHT AND LICENSE
551  
552 This software is copyright (c) 2014 by Oliver Gorwits.
553  
554 This is free software; you can redistribute it and/or modify it under
555 the same terms as the Perl 5 programming language system itself.
556  
557 =cut
558  
↑ Summary Interact/Role/Prompt.pm »