aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-07-24 13:41:28 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2017-07-24 13:41:28 +0300
commit73365dbc9cda550963df506ea739cbcd73817106 (patch)
tree50c0ba403bcf4fcdd6aa3e142c04142ce734d009
parent1718b7e87b3ce2d588f2412ac41bea6e7048709f (diff)
downloadposixruncapture-73365dbc9cda550963df506ea739cbcd73817106.tar.gz
posixruncapture-73365dbc9cda550963df506ea739cbcd73817106.tar.bz2
Update docs
-rw-r--r--Capture.xs23
-rw-r--r--lib/POSIX/Run/Capture.pm206
2 files changed, 205 insertions, 24 deletions
diff --git a/Capture.xs b/Capture.xs
index 067180c..19da27b 100644
--- a/Capture.xs
+++ b/Capture.xs
@@ -3,18 +3,6 @@
3MODULE = POSIX::Run::Capture PACKAGE = POSIX::Run::Capture PREFIX = capture_ 3MODULE = POSIX::Run::Capture PACKAGE = POSIX::Run::Capture PREFIX = capture_
4PROTOTYPES: ENABLE 4PROTOTYPES: ENABLE
5 5
6=head2 new POSIX::Run::Capture
7
8 new POSIX::Run::Capture([ $command, @args ]);
9
10 new POSIX::Run::Capture(argv => [ $command, @args ],
11 stdout => sub { ... },
12 stderr => sub { ... },
13 timeout => N)
14
15
16=cut
17
18POSIX::Run::Capture 6POSIX::Run::Capture
19capture_new(package, ...) 7capture_new(package, ...)
20 char *package; 8 char *package;
@@ -66,7 +54,8 @@ capture_new(package, ...)
66 croak("program argument is not a scalar"); 54 croak("program argument is not a scalar");
67 else 55 else
68 prog = val; 56 prog = val;
69 } else if (strcmp(kw, "input") == 0) { 57 } else if (strcmp(kw, "input") == 0
58 || strcmp(kw, "stdin") == 0) {
70 input = val; 59 input = val;
71 } else 60 } else
72 croak("unknown keyword argument %s", kw); 61 croak("unknown keyword argument %s", kw);
@@ -80,6 +69,14 @@ void
80capture_DESTROY(cp) 69capture_DESTROY(cp)
81 POSIX::Run::Capture cp; 70 POSIX::Run::Capture cp;
82 71
72=head2 $obj->set_argv_ref($aref)
73
74Sets command argument vector. The B<$aref> parameter is an array reference.
75
76This is an auxiliary method. Use B<set_argv> instead.
77
78=cut
79
83void 80void
84capture_set_argv_ref(cp, argv) 81capture_set_argv_ref(cp, argv)
85 POSIX::Run::Capture cp; 82 POSIX::Run::Capture cp;
diff --git a/lib/POSIX/Run/Capture.pm b/lib/POSIX/Run/Capture.pm
index dacdcfd..5dedad0 100644
--- a/lib/POSIX/Run/Capture.pm
+++ b/lib/POSIX/Run/Capture.pm
@@ -64,27 +64,211 @@ POSIX::Run::Capture - run command and capture its output
64=head1 SYNOPSIS 64=head1 SYNOPSIS
65 65
66 use POSIX::Run::Capture; 66 use POSIX::Run::Capture;
67
68 67
68 $obj = new POSIX::Run::Capture(argv => [ $command, @args ],
69 program => $prog,
70 stdin => $fh_or_string,
71 stdout => sub { ... },
72 stderr => sub { ... },
73 timeout => $n);
74 $obj->run;
75
76 $num = $obj->errno;
77 $num = $obj->status;
78 $num = $obj->length($chan);
79 $num = $obj->nlines($chan);
80
81 $str = $obj->next_line($chan);
82 $aref = $obj->get_lines($chan);
83 $obj->rewind($chan)
84
85 $obj->set_program($prog);
86 $obj->set_timeout($n);
87 $obj->set_input($fh_or_string);
88
89 $aref = head3 $obj->argv;
90 $str = =head3 $obj->program
91 $num = $obj->timeout;
92
69=head1 DESCRIPTION 93=head1 DESCRIPTION
70 94
71The API is in development. 95This module prefers performance and effectiveness over portability. As its
96name suggests, it can be used only on POSIX systems.
97
98=head2 new POSIX::Run::Capture
99
100Creates a new capture object. There are three possible invocation modes.
101
102 new POSIX::Run::Capture(argv => [ $command, @args ],
103 program => $prog,
104 stdin => $fh_or_string,
105 stdout => sub { ... },
106 stderr => sub { ... },
107 timeout => $n)
108
109When named arguments are used, the following keywords are allowed:
110
111=over 4
112
113=item B<argv>
114
115Defines the command (B<C argv[0]>) and its arguments. In the absense of
116B<program> argument, B<$argv[0]> will be run.
117
118=item B<program>
119
120Sets the pathname of binary file to run.
121
122=item B<stdin> or B<input>
123
124Supplies standard input for the command. The argument can be a string or
125a file handle.
126
127=item B<stdout>
128
129Sets the I<line monitor> function for standard output. Line monitor is
130invoked each time a complete line is read, or the EOF is hit on the standard
131output. The acquired line is passed to the monitor as its argument. The
132following example monitor function prints its argument to STDOUT:
133
134 sub stdout_monitor {
135 my $line = shift;
136 print $line;
137 }
138
139Notice that the last line read can lack the teminating newline character.
140
141=item B<stderr>
142
143Sets the I<line monitor> function for standard error stream. See the
144description above.
145
146=item B<timeout>
147
148Sets execution timeout, in seconds. If the program takes longer than B<$n>
149seconds to terminate, it will be forcibly terminated (by sending the B<SIGKILL>
150signal).
151
152=back
72 153
73=head2 EXPORT 154=head3 new POSIX::Run::Capture([ $command, @args ]);
155
156A simplified way of creating the object, equivalent to
74 157
75None by default. Use B<:std> to export the B<STDOUT> and B<STDERR> constants. 158 new POSIX::Run::Capture(argv => [ $command, @args ]);
159
160=head3 new POSIX::Run::Capture;
161
162Crates an empty capture object.
163
164Whatever constructor is used, the necessary parameters can be set
165or changed later, using B<set_argv>, B<set_program>, B<set_input>,
166and B<set_timeout>.
167
168Monitors can be defined only when creating the object.
169
170=head2 Modifying the object.
171
172The following methods modify the object:
76 173
174=head3 $obj->set_program($prog)
175
176Sets the pathname of the command to run.
77 177
78=head1 SEE ALSO 178=head3 $obj->set_timeout($n)
179
180Sets runtime timeout, in seconds.
181
182=head3 $obj->set_input($fh_or_string)
183
184Sets standard input for the program. Argument must be either a filehandle
185open for reading or a string. The filehandle will be repositioned to its
186beginning prior to use.
187
188=head2 Accessors
189
190The following accessors return parameters associated with the object:
191
192=head3 $obj->argv
193
194Returns a reference to the B<argv> array associated with the object.
195
196=head3 $obj->program
197
198Returns the pathname of the executable program.
199
200=head3 $obj->timeout
201
202Returns the runtime timeout or B<0> if no timeout is set.
203
204=head2 Running the command
205
206=head3 $obj->run
207
208Runs the program. Returns B<1> on successful termination, B<0> otherwise.
209
210=head3 $obj->errno
211
212If the last call to B<run> returned false, this method returns the
213value of the system error number (the C B<errno> variable).
214
215Upon successful return from B<$obj-E<gt>run>, the following accessors can
216be used:
217
218=head3 $obj->status
219
220Returns the termination status of the program. Use the macros from
221B<POSIX :sys_wait_h> to analyze it. E.g.:
222
223 use POSIX qw(:sys_wait_h);
224 if ($obj->run()) {
</