1Net::CLI::Interact::RolUes:e:rPrCoomnpttr(i3b)uted PerlNDeotc:u:mCeLnIt:a:tIinotneract::Role::Prompt(3)
2
3
4
6 Net::CLI::Interact::Role::Prompt - Command-line prompt management
7
9 This is another core component of Net::CLI::Interact, and its role is
10 to keep track of the current prompt on the connected command line
11 interface. The idea is that most CLI have a prompt where you issue
12 commands, and are returned some output which this module gathers. The
13 prompt is a demarcation between each command and its response data.
14
15 Note that although we "keep track" of the prompt, Net::CLI::Interact is
16 not a state machine, and the choice of command issued to the connected
17 device bears no relation to the current (or last matched) prompt.
18
20 set_prompt( $prompt_name )
21 This method will be used most commonly by applications to select and
22 set a prompt from the Phrasebook which matches the current context of
23 the connected CLI session. This allows a sequence of commands to be
24 sent which share the same Prompt.
25
26 The name you pass in is looked up in the loaded Phrasebook and the
27 entry's regular expression stored internally. An exception is thrown if
28 the named Prompt is not known.
29
30 Typically you would either refer to a Prompt in a Macro, or set the
31 prompt you are expecting once for a sequence of commands in a
32 particular CLI context.
33
34 When a Macro completes and it has been defined in the Phrasebook with
35 an explicit named Prompt at the end, we can assume the user is
36 indicating some change of context. Therefore the "prompt" is
37 automatically updated on such occasions to have the regular expression
38 from that named Prompt.
39
40 prompt_re
41 Returns the current Prompt in the form of a regular expression
42 reference. The Prompt is used as a default to catch the end of command
43 response output, when a Macro has not been set up with explicit Prompt
44 matching.
45
46 Typically you would either refer to a Prompt in a Macro, or set the
47 prompt you are expecting once for a sequence of commands in a
48 particular CLI context.
49
50 unset_prompt
51 Use this method to empty the current "prompt" setting (see above). The
52 effect is that the module will automatically set the Prompt for itself
53 based on the last line of output received from the connected CLI. Do
54 not use this option unless you know what you are doing.
55
56 has_set_prompt
57 Returns True if there is currently a Prompt set, otherwise returns
58 False.
59
60 prompt_looks_like( $name )
61 Returns True if the current prompt matches the given named prompt. This
62 is useful when you wish to make a more specific check on the current
63 prompt.
64
65 find_prompt( $wake_up? )
66 A helper method that consumes output from the connected CLI session
67 until a line matches any one of the named Prompts in the loaded
68 Phrasebook, at which point no more output is consumed. As a consequence
69 the "prompt" will be set (see above).
70
71 This might be used when you're connecting to a device which maintains
72 CLI state between session disconnects (for example a serial console),
73 and you need to discover the current state. However, "find_prompt" is
74 executed automatically for you if you call a "cmd" or "macro" before
75 any interaction with the CLI.
76
77 The current device output will be scanned against all known named
78 Prompts. If nothing is found, the default behaviour is to die. Passing
79 a positive number to the method (as $wake_up) will instead send the
80 content of our "wake_up_msg" slot (see below), typically a carriage
81 return, and try to match again. The idea is that by sending one
82 carriage return, the connected device will print its CLI prompt. This
83 "send and try to match" process will be repeated up to "$wake_up"
84 times.
85
86 wake_up_msg
87 Text sent to a device within the "find_prompt" method if no output has
88 so far matched any known named Prompt. Default is the value of the
89 output record separator from the Transport (one newline).
90
91 last_prompt
92 Returns the Prompt which most recently was matched and terminated
93 gathering of output from the connected CLI. This is a simple text
94 string.
95
96 last_prompt_re
97 Returns the text which was most recently matched and terminated
98 gathering of output from the connected CLI, as a quote-escaped regular
99 expression with line start and end anchors.
100
101
102
103perl v5.28.1 2019-02-02Net::CLI::Interact::Role::Prompt(3)