Commit | Line | Data |
b2e1304d |
1 | package HTTP::Request::AsCGI; |
2 | |
3 | use strict; |
4 | use warnings; |
090cc060 |
5 | use bytes; |
b2e1304d |
6 | use base 'Class::Accessor::Fast'; |
7 | |
26e3d92b |
8 | use Carp qw[croak]; |
9 | use HTTP::Response qw[]; |
10 | use IO::Handle qw[]; |
5889d784 |
11 | use IO::File qw[SEEK_SET]; |
26e3d92b |
12 | use Symbol qw[]; |
b2e1304d |
13 | |
5889d784 |
14 | __PACKAGE__->mk_accessors( qw[ is_setuped |
15 | is_prepared |
16 | is_restored |
17 | |
18 | should_dup |
19 | should_restore |
20 | should_rewind |
21 | should_setup_content |
22 | |
23 | environment |
24 | request |
25 | stdin |
26 | stdout |
27 | stderr ] ); |
b2e1304d |
28 | |
26e3d92b |
29 | our $VERSION = 0.6_01; |
b2e1304d |
30 | |
31 | sub new { |
26e3d92b |
32 | my $class = ref $_[0] ? ref shift : shift; |
33 | my $params = {}; |
4e0afe7d |
34 | |
26e3d92b |
35 | if ( @_ % 2 == 0 ) { |
36 | $params = { @_ }; |
37 | } |
38 | else { |
39 | $params = { request => shift, environment => { @_ } }; |
40 | } |
41 | |
42 | return bless( {}, $class )->initialize($params); |
43 | } |
44 | |
45 | sub initialize { |
46 | my ( $self, $params ) = @_; |
47 | |
48 | if ( exists $params->{request} ) { |
49 | $self->request( $params->{request} ); |
50 | } |
51 | else { |
52 | croak("Mandatory parameter 'request' is missing."); |
2d51e42f |
53 | } |
4e0afe7d |
54 | |
26e3d92b |
55 | if ( exists $params->{environment} ) { |
56 | $self->environment( $params->{environment} ); |
57 | } |
58 | else { |
59 | $self->environment( {} ); |
60 | } |
61 | |
62 | if ( exists $params->{stdin} ) { |
63 | $self->stdin( $params->{stdin} ); |
64 | } |
65 | else { |
66 | $self->stdin( IO::File->new_tmpfile ); |
67 | } |
68 | |
69 | if ( exists $params->{stdout} ) { |
70 | $self->stdout( $params->{stdout} ); |
71 | } |
72 | else { |
73 | $self->stdout( IO::File->new_tmpfile ); |
74 | } |
75 | |
76 | if ( exists $params->{stderr} ) { |
77 | $self->stderr( $params->{stderr} ); |
78 | } |
4d6e304a |
79 | |
26e3d92b |
80 | if ( exists $params->{dup} ) { |
81 | $self->should_dup( $params->{dup} ? 1 : 0 ); |
82 | } |
83 | else { |
84 | $self->should_dup(1); |
4d6e304a |
85 | } |
26e3d92b |
86 | |
87 | if ( exists $params->{restore} ) { |
88 | $self->should_restore( $params->{restore} ? 1 : 0 ); |
89 | } |
90 | else { |
91 | $self->should_restore(1); |
92 | } |
93 | |
94 | if ( exists $params->{rewind} ) { |
95 | $self->should_rewind( $params->{rewind} ? 1 : 0 ); |
96 | } |
97 | else { |
98 | $self->should_rewind(1); |
99 | } |
100 | |
5889d784 |
101 | if ( exists $params->{content} ) { |
102 | $self->should_setup_content( $params->{content} ? 1 : 0 ); |
103 | } |
104 | else { |
105 | $self->should_setup_content(1); |
106 | } |
107 | |
26e3d92b |
108 | $self->prepare; |
109 | |
110 | return $self; |
111 | } |
112 | |
113 | *enviroment = \&environment; |
114 | |
115 | sub has_stdin { return defined $_[0]->stdin } |
116 | sub has_stdout { return defined $_[0]->stdout } |
117 | sub has_stderr { return defined $_[0]->stderr } |
118 | |
119 | sub prepare { |
120 | my $self = shift; |
121 | |
122 | my $environment = $self->environment; |
123 | my $request = $self->request; |
b2e1304d |
124 | |
30efa07d |
125 | my $host = $request->header('Host'); |
126 | my $uri = $request->uri->clone; |
26e3d92b |
127 | |
30efa07d |
128 | $uri->scheme('http') unless $uri->scheme; |
129 | $uri->host('localhost') unless $uri->host; |
130 | $uri->port(80) unless $uri->port; |
a3875fc6 |
131 | $uri->host_port($host) unless !$host || ( $host eq $uri->host_port ); |
4e0afe7d |
132 | |
ca38286c |
133 | $uri = $uri->canonical; |
30efa07d |
134 | |
26e3d92b |
135 | my %cgi = ( |
b2e1304d |
136 | GATEWAY_INTERFACE => 'CGI/1.1', |
30efa07d |
137 | HTTP_HOST => $uri->host_port, |
a3875fc6 |
138 | HTTPS => ( $uri->scheme eq 'https' ) ? 'ON' : 'OFF', # not in RFC 3875 |
139 | PATH_INFO => $uri->path, |
140 | QUERY_STRING => $uri->query || '', |
141 | SCRIPT_NAME => '/', |
142 | SERVER_NAME => $uri->host, |
143 | SERVER_PORT => $uri->port, |
144 | SERVER_PROTOCOL => $request->protocol || 'HTTP/1.1', |
145 | SERVER_SOFTWARE => "HTTP-Request-AsCGI/$VERSION", |
146 | REMOTE_ADDR => '127.0.0.1', |
147 | REMOTE_HOST => 'localhost', |
148 | REMOTE_PORT => int( rand(64000) + 1000 ), # not in RFC 3875 |
149 | REQUEST_URI => $uri->path_query, # not in RFC 3875 |
26e3d92b |
150 | REQUEST_METHOD => $request->method |
151 | ); |
b2e1304d |
152 | |
26e3d92b |
153 | foreach my $key ( keys %cgi ) { |
154 | |
155 | unless ( exists $environment->{ $key } ) { |
156 | $environment->{ $key } = $cgi{ $key }; |
157 | } |
158 | } |
159 | |
160 | foreach my $field ( $self->request->headers->header_field_names ) { |
b2e1304d |
161 | |
ca38286c |
162 | my $key = uc("HTTP_$field"); |
2aaf55bc |
163 | $key =~ tr/-/_/; |
ca38286c |
164 | $key =~ s/^HTTP_// if $field =~ /^Content-(Length|Type)$/; |
b2e1304d |
165 | |
26e3d92b |
166 | unless ( exists $environment->{ $key } ) { |
167 | $environment->{ $key } = $self->request->headers->header($field); |
b2e1304d |
168 | } |
169 | } |
170 | |
26e3d92b |
171 | unless ( $environment->{SCRIPT_NAME} eq '/' && $environment->{PATH_INFO} ) { |
172 | $environment->{PATH_INFO} =~ s/^\Q$environment->{SCRIPT_NAME}\E/\//; |
173 | $environment->{PATH_INFO} =~ s/^\/+/\//; |
174 | } |
175 | |
176 | $self->is_prepared(1); |
177 | } |
178 | |
179 | sub setup { |
180 | my $self = shift; |
181 | |
5889d784 |
182 | $self->setup_content; |
26e3d92b |
183 | $self->setup_stdin; |
184 | $self->setup_stdout; |
185 | $self->setup_stderr; |
186 | $self->setup_environment; |
187 | |
188 | if ( $INC{'CGI.pm'} ) { |
189 | CGI::initialize_globals(); |
ca38286c |
190 | } |
191 | |
26e3d92b |
192 | $self->is_setuped(1); |
ca38286c |
193 | |
194 | return $self; |
b2e1304d |
195 | } |
196 | |
5889d784 |
197 | sub setup_content { |
b2e1304d |
198 | my $self = shift; |
199 | |
5889d784 |
200 | if ( $self->should_setup_content && $self->has_stdin ) { |
26e3d92b |
201 | |
5889d784 |
202 | if ( $self->request->content_length ) { |
26e3d92b |
203 | |
5889d784 |
204 | my $content = $self->request->content_ref; |
26e3d92b |
205 | |
5889d784 |
206 | if ( ref $content eq 'SCALAR' ) { |
26e3d92b |
207 | |
5889d784 |
208 | if ( defined $$content && length $$content ) { |
26e3d92b |
209 | |
5889d784 |
210 | print( { $self->stdin } $$content ) |
211 | or croak("Couldn't write request content to stdin handle: '$!'"); |
b2e1304d |
212 | |
5889d784 |
213 | if ( $self->should_rewind ) { |
b2e1304d |
214 | |
5889d784 |
215 | seek( $self->stdin, 0, SEEK_SET ) |
216 | or croak("Couldn't seek stdin handle: '$!'"); |
217 | } |
218 | } |
219 | } |
220 | else { |
221 | croak("Can't handle request content of '$content'"); |
222 | } |
26e3d92b |
223 | } |
5889d784 |
224 | } |
225 | } |
226 | |
227 | sub setup_stdin { |
228 | my $self = shift; |
229 | |
230 | if ( $self->has_stdin ) { |
26e3d92b |
231 | |
232 | if ( $self->should_dup ) { |
233 | |
234 | if ( $self->should_restore ) { |
235 | |
236 | open( my $stdin, '<&STDIN' ) |
237 | or croak("Couldn't dup STDIN: '$!'"); |
238 | |
239 | $self->{restore}->{stdin} = $stdin; |
240 | } |
241 | |
242 | STDIN->fdopen( $self->stdin, '<' ) |
6faa5a50 |
243 | or croak("Couldn't dup stdin handle to STDIN: '$!'"); |
26e3d92b |
244 | } |
245 | else { |
246 | |
247 | my $stdin = Symbol::qualify_to_ref('STDIN'); |
248 | |
249 | if ( $self->should_restore ) { |
250 | |
251 | $self->{restore}->{stdin} = *$stdin; |
252 | $self->{restore}->{stdin_ref} = \*$stdin; |
253 | } |
b2e1304d |
254 | |
5889d784 |
255 | *$stdin = $self->stdin; |
26e3d92b |
256 | } |
b2e1304d |
257 | |
5889d784 |
258 | binmode( $self->stdin ); |
26e3d92b |
259 | binmode( STDIN ); |
b2e1304d |
260 | } |
26e3d92b |
261 | } |
262 | |
263 | sub setup_stdout { |
264 | my $self = shift; |
265 | |
266 | if ( $self->has_stdout ) { |
b2e1304d |
267 | |
26e3d92b |
268 | if ( $self->should_dup ) { |
ca38286c |
269 | |
26e3d92b |
270 | if ( $self->should_restore ) { |
271 | |
272 | open( my $stdout, '>&STDOUT' ) |
273 | or croak("Couldn't dup STDOUT: '$!'"); |
274 | |
275 | $self->{restore}->{stdout} = $stdout; |
276 | } |
277 | |
278 | STDOUT->fdopen( $self->stdout, '>' ) |
6faa5a50 |
279 | or croak("Couldn't dup stdout handle to STDOUT: '$!'"); |
26e3d92b |
280 | } |
281 | else { |
30efa07d |
282 | |
26e3d92b |
283 | my $stdout = Symbol::qualify_to_ref('STDOUT'); |
090cc060 |
284 | |
26e3d92b |
285 | if ( $self->should_restore ) { |
441eeb04 |
286 | |
26e3d92b |
287 | $self->{restore}->{stdout} = *$stdout; |
288 | $self->{restore}->{stdout_ref} = \*$stdout; |
289 | } |
76391122 |
290 | |
5889d784 |
291 | *$stdout = $self->stdout; |
26e3d92b |
292 | } |
76391122 |
293 | |
a3875fc6 |
294 | binmode( $self->stdout ); |
295 | binmode( STDOUT); |
296 | } |
26e3d92b |
297 | } |
090cc060 |
298 | |
26e3d92b |
299 | sub setup_stderr { |
300 | my $self = shift; |
30efa07d |
301 | |
26e3d92b |
302 | if ( $self->has_stderr ) { |
090cc060 |
303 | |
26e3d92b |
304 | if ( $self->should_dup ) { |
441eeb04 |
305 | |
26e3d92b |
306 | if ( $self->should_restore ) { |
090cc060 |
307 | |
26e3d92b |
308 | open( my $stderr, '>&STDERR' ) |
309 | or croak("Couldn't dup STDERR: '$!'"); |
4e0afe7d |
310 | |
26e3d92b |
311 | $self->{restore}->{stderr} = $stderr; |
312 | } |
b2e1304d |
313 | |
26e3d92b |
314 | STDERR->fdopen( $self->stderr, '>' ) |
6faa5a50 |
315 | or croak("Couldn't dup stderr handle to STDERR: '$!'"); |
26e3d92b |
316 | } |
317 | else { |
b2e1304d |
318 | |
26e3d92b |
319 | my $stderr = Symbol::qualify_to_ref('STDERR'); |
320 | |
321 | if ( $self->should_restore ) { |
322 | |
323 | $self->{restore}->{stderr} = *$stderr; |
324 | $self->{restore}->{stderr_ref} = \*$stderr; |
325 | } |
326 | |
5889d784 |
327 | *$stderr = $self->stderr; |
26e3d92b |
328 | } |
329 | |
330 | binmode( $self->stderr ); |
331 | binmode( STDERR ); |
332 | } |
b2e1304d |
333 | } |
334 | |
5889d784 |
335 | sub setup_environment { |
336 | my $self = shift; |
337 | |
338 | no warnings 'uninitialized'; |
339 | |
340 | if ( $self->should_restore ) { |
341 | $self->{restore}->{environment} = { %ENV }; |
342 | } |
343 | |
344 | %ENV = %{ $self->environment }; |
345 | } |
346 | |
780060e5 |
347 | sub response { |
4d6e304a |
348 | my $self = shift; |
349 | my %params = ( headers_only => 0, sync => 0, @_ ); |
780060e5 |
350 | |
6faa5a50 |
351 | return undef unless $self->has_stdout; |
780060e5 |
352 | |
5889d784 |
353 | if ( $self->should_rewind ) { |
354 | |
355 | seek( $self->stdout, 0, SEEK_SET ) |
356 | or croak("Couldn't seek stdout handle: '$!'"); |
357 | } |
780060e5 |
358 | |
6faa5a50 |
359 | my $message = undef; |
360 | my $response = HTTP::Response->new( 200, 'OK' ); |
361 | $response->protocol('HTTP/1.1'); |
362 | |
decf17dc |
363 | while ( my $line = $self->stdout->getline ) { |
6faa5a50 |
364 | $message .= $line; |
365 | last if $message =~ /\x0d?\x0a\x0d?\x0a$/; |
780060e5 |
366 | } |
26e3d92b |
367 | |
6faa5a50 |
368 | if ( !$message ) { |
369 | |
370 | $response->code(500); |
371 | $response->message('Internal Server Error'); |
372 | $response->date( time ); |
373 | $response->content( $response->error_as_HTML ); |
374 | $response->content_type('text/html'); |
375 | $response->content_length( length $response->content ); |
decf17dc |
376 | |
6faa5a50 |
377 | return $response; |
780060e5 |
378 | } |
379 | |
6faa5a50 |
380 | my $Token = qr/[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]/; |
381 | my $Version = qr/HTTP\/[0-9]+\.[0-9]+/; |
decf17dc |
382 | |
6faa5a50 |
383 | if ( $message =~ s/^($Version)[\x09\x20]+(\d{3})[\x09\x20]+([\x20-\xFF]*)\x0D?\x0A//o ) { |
decf17dc |
384 | |
6faa5a50 |
385 | $response->protocol($1); |
386 | $response->code($2); |
387 | $response->message($3); |
4e0afe7d |
388 | } |
decf17dc |
389 | |
6faa5a50 |
390 | $message =~ s/\x0D?\x0A[\x09\x20]+/\x20/gs; |
decf17dc |
391 | |
6faa5a50 |
392 | foreach ( split /\x0D?\x0A/, $message ) { |
780060e5 |
393 | |
6faa5a50 |
394 | if ( /^($Token+)[\x09\x20]*:[\x09\x20]*([\x20-\xFF]+)[\x09\x20]*$/o ) { |
395 | $response->headers->push_header( $1 => $2 ); |
396 | } |
397 | else { |
398 | # XXX what should we do on bad headers? |
399 | } |
780060e5 |
400 | } |
26e3d92b |
401 | |
6faa5a50 |
402 | my $status = $response->header('Status'); |
780060e5 |
403 | |
6faa5a50 |
404 | if ( $status && $status =~ /^(\d{3})[\x09\x20]+([\x20-\xFF]+)$/ ) { |
405 | $response->code($1); |
406 | $response->message($2); |
407 | } |
4e0afe7d |
408 | |
6faa5a50 |
409 | if ( !$response->date ) { |
410 | $response->date(time); |
4e0afe7d |
411 | } |
780060e5 |
412 | |
4d6e304a |
413 | if ( $params{headers_only} ) { |
4e0afe7d |
414 | |
4d6e304a |
415 | if ( $params{sync} ) { |
4e0afe7d |
416 | |
4d6e304a |
417 | my $position = tell( $self->stdout ) |
418 | or croak("Couldn't get file position from stdout handle: '$!'"); |
4e0afe7d |
419 | |
4d6e304a |
420 | sysseek( $self->stdout, $position, SEEK_SET ) |
421 | or croak("Couldn't seek stdout handle: '$!'"); |
422 | } |
4e0afe7d |
423 | |
4d6e304a |
424 | return $response; |
780060e5 |
425 | } |
4e0afe7d |
426 | |
4d6e304a |
427 | my $content = undef; |
428 | my $content_length = 0; |
429 | |
430 | while () { |
431 | |
6faa5a50 |
432 | my $r = $self->stdout->read( $content, 65536, $content_length ); |
4e0afe7d |
433 | |
4d6e304a |
434 | if ( defined $r ) { |
435 | |
436 | $content_length += $r; |
437 | |
438 | last unless $r; |
439 | } |
440 | else { |
6faa5a50 |
441 | croak("Couldn't read response content from stdin handle: '$!'"); |
780060e5 |
442 | } |
4d6e304a |
443 | } |
444 | |
445 | if ( $content_length ) { |
446 | |
447 | $response->content_ref(\$content); |
4e0afe7d |
448 | |
4d6e304a |
449 | if ( !$response->content_length ) { |
450 | $response->content_length($content_length); |
decf17dc |
451 | } |
780060e5 |
452 | } |
453 | |
780060e5 |
454 | return $response; |
455 | } |
456 | |
b2e1304d |
457 | sub restore { |
458 | my $self = shift; |
4e0afe7d |
459 | |
26e3d92b |
460 | if ( $self->should_restore ) { |
461 | |
462 | $self->restore_environment; |
463 | $self->restore_stdin; |
464 | $self->restore_stdout; |
465 | $self->restore_stderr; |
466 | |
467 | $self->{restore} = {}; |
468 | |
469 | $self->is_restored(1); |
cef1c068 |
470 | } |
b2e1304d |
471 | |
26e3d92b |
472 | return $self; |
473 | } |
474 | |
475 | sub restore_environment { |
476 | my $self = shift; |
477 | |
478 | no warnings 'uninitialized'; |
b2e1304d |
479 | |
26e3d92b |
480 | %ENV = %{ $self->{restore}->{environment} }; |
481 | } |
482 | |
483 | sub restore_stdin { |
484 | my $self = shift; |
12852959 |
485 | |
26e3d92b |
486 | if ( $self->has_stdin ) { |
30efa07d |
487 | |
26e3d92b |
488 | my $stdin = $self->{restore}->{stdin}; |
30efa07d |
489 | |
26e3d92b |
490 | if ( $self->should_dup ) { |
491 | |
492 | STDIN->fdopen( $stdin, '<' ) |
493 | or croak("Couldn't restore STDIN: '$!'"); |
494 | } |
495 | else { |
496 | |
497 | my $stdin_ref = $self->{restore}->{stdin_ref}; |
5889d784 |
498 | *$stdin_ref = $stdin; |
26e3d92b |
499 | } |
090cc060 |
500 | |
26e3d92b |
501 | if ( $self->should_rewind ) { |
502 | |
503 | seek( $self->stdin, 0, SEEK_SET ) |
504 | or croak("Couldn't seek stdin handle: '$!'"); |
505 | } |
a3875fc6 |
506 | } |
26e3d92b |
507 | } |
508 | |
509 | sub restore_stdout { |
510 | my $self = shift; |
511 | |
512 | if ( $self->has_stdout ) { |
513 | |
514 | my $stdout = $self->{restore}->{stdout}; |
515 | |
516 | if ( $self->should_dup ) { |
517 | |
518 | STDOUT->flush |
519 | or croak("Couldn't flush STDOUT: '$!'"); |
520 | |
521 | STDOUT->fdopen( $stdout, '>' ) |
522 | or croak("Couldn't restore STDOUT: '$!'"); |
523 | } |
524 | else { |
12852959 |
525 | |
26e3d92b |
526 | my $stdout_ref = $self->{restore}->{stdout_ref}; |
5889d784 |
527 | *$stdout_ref = $stdout; |
26e3d92b |
528 | } |
30efa07d |
529 | |
26e3d92b |
530 | if ( $self->should_rewind ) { |
090cc060 |
531 | |
26e3d92b |
532 | seek( $self->stdout, 0, SEEK_SET ) |
533 | or croak("Couldn't seek stdout handle: '$!'"); |
534 | } |
6f5fb9a7 |
535 | } |
26e3d92b |
536 | } |
12852959 |
537 | |
26e3d92b |
538 | sub restore_stderr { |
539 | my $self = shift; |
090cc060 |
540 | |
26e3d92b |
541 | if ( $self->has_stderr ) { |
542 | |
543 | my $stderr = $self->{restore}->{stderr}; |
544 | |
545 | if ( $self->should_dup ) { |
546 | |
547 | STDERR->flush |
548 | or croak("Couldn't flush STDERR: '$!'"); |
549 | |
550 | STDERR->fdopen( $stderr, '>' ) |
551 | or croak("Couldn't restore STDERR: '$!'"); |
552 | } |
553 | else { |
554 | |
555 | my $stderr_ref = $self->{restore}->{stderr_ref}; |
5889d784 |
556 | *$stderr_ref = $stderr; |
26e3d92b |
557 | } |
558 | |
559 | if ( $self->should_rewind ) { |
560 | |
561 | seek( $self->stderr, 0, SEEK_SET ) |
562 | or croak("Couldn't seek stderr handle: '$!'"); |
563 | } |
564 | } |
b2e1304d |
565 | } |
566 | |
567 | sub DESTROY { |
568 | my $self = shift; |
26e3d92b |
569 | |
6faa5a50 |
570 | if ( $self->should_restore && $self->is_setuped && !$self->is_restored ) { |
571 | $self->restore; |
26e3d92b |
572 | } |
b2e1304d |
573 | } |
574 | |
575 | 1; |
576 | |
577 | __END__ |
578 | |
579 | =head1 NAME |
580 | |
26e3d92b |
581 | HTTP::Request::AsCGI - Setup a CGI environment from a HTTP::Request |
b2e1304d |
582 | |
583 | =head1 SYNOPSIS |
584 | |
bd7813ac |
585 | use CGI; |
586 | use HTTP::Request; |
587 | use HTTP::Request::AsCGI; |
26e3d92b |
588 | |
bd7813ac |
589 | my $request = HTTP::Request->new( GET => 'http://www.host.com/' ); |
590 | my $stdout; |
26e3d92b |
591 | |
bd7813ac |
592 | { |
593 | my $c = HTTP::Request::AsCGI->new($request)->setup; |
594 | my $q = CGI->new; |
26e3d92b |
595 | |
bd7813ac |
596 | print $q->header, |
597 | $q->start_html('Hello World'), |
598 | $q->h1('Hello World'), |
599 | $q->end_html; |
26e3d92b |
600 | |
bd7813ac |
601 | $stdout = $c->stdout; |
26e3d92b |
602 | |
603 | # environment and descriptors will automatically be restored |
2d51e42f |
604 | # when $c is destructed. |
bd7813ac |
605 | } |
26e3d92b |
606 | |
bd7813ac |
607 | while ( my $line = $stdout->getline ) { |
608 | print $line; |
609 | } |
26e3d92b |
610 | |
b2e1304d |
611 | =head1 DESCRIPTION |
612 | |
26e3d92b |
613 | Provides a convinient way of setting up an CGI environment from a HTTP::Request. |
2d51e42f |
614 | |
b2e1304d |
615 | =head1 METHODS |
616 | |
26e3d92b |
617 | =over 4 |
b2e1304d |
618 | |
2d51e42f |
619 | =item new ( $request [, key => value ] ) |
620 | |
621 | Contructor, first argument must be a instance of HTTP::Request |
ca38286c |
622 | followed by optional pairs of environment key and value. |
b2e1304d |
623 | |
26e3d92b |
624 | =item environment |
bd7813ac |
625 | |
26e3d92b |
626 | Returns a hashref containing the environment that will be used in setup. |
2d51e42f |
627 | Changing the hashref after setup has been called will have no effect. |
628 | |
b2e1304d |
629 | =item setup |
630 | |
2d51e42f |
631 | Setups the environment and descriptors. |
632 | |
b2e1304d |
633 | =item restore |
634 | |
26e3d92b |
635 | Restores the environment and descriptors. Can only be called after setup. |
2d51e42f |
636 | |
b2e1304d |
637 | =item request |
638 | |
2d51e42f |
639 | Returns the request given to constructor. |
640 | |
780060e5 |
641 | =item response |
642 | |
2d51e42f |
643 | Returns a HTTP::Response. Can only be called after restore. |
644 | |
b2e1304d |
645 | =item stdin |
646 | |
2d51e42f |
647 | Accessor for handle that will be used for STDIN, must be a real seekable |
648 | handle with an file descriptor. Defaults to a tempoary IO::File instance. |
649 | |
b2e1304d |
650 | =item stdout |
651 | |
2d51e42f |
652 | Accessor for handle that will be used for STDOUT, must be a real seekable |
653 | handle with an file descriptor. Defaults to a tempoary IO::File instance. |
654 | |
b2e1304d |
655 | =item stderr |
656 | |
2d51e42f |
657 | Accessor for handle that will be used for STDERR, must be a real seekable |
658 | handle with an file descriptor. |
b2e1304d |
659 | |
2d51e42f |
660 | =back |
b2e1304d |
661 | |
74fbb9dd |
662 | =head1 SEE ALSO |
663 | |
664 | =over 4 |
665 | |
666 | =item examples directory in this distribution. |
667 | |
668 | =item L<WWW::Mechanize::CGI> |
669 | |
670 | =item L<Test::WWW::Mechanize::CGI> |
671 | |
672 | =back |
673 | |
2d51e42f |
674 | =head1 THANKS TO |
17b370b0 |
675 | |
676 | Thomas L. Shinnick for his valuable win32 testing. |
677 | |
b2e1304d |
678 | =head1 AUTHOR |
679 | |
680 | Christian Hansen, C<ch@ngmedia.com> |
681 | |
682 | =head1 LICENSE |
683 | |
26e3d92b |
684 | This library is free software. You can redistribute it and/or modify |
b2e1304d |
685 | it under the same terms as perl itself. |
686 | |
687 | =cut |