Codebase list libcapture-tiny-perl / 1339709
skip reading back in void context David Golden 12 years ago
4 changed file(s) with 39 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
00 Revision history for Capture-Tiny
11
22 {{$NEXT}}
3
4 Added
5
6 - When capture or tee are called in void context, Capture::Tiny
7 skips reading back from the capture handles if it can do so safely
38
49 0.17_52 2012-03-09 11:45:19 EST5EDT
510
33 "David Golden <dagolden@cpan.org>"
44 ],
55 "dynamic_config" : 1,
6 "generated_by" : "Dist::Zilla version 4.300009, CPAN::Meta::Converter version 2.120630",
6 "generated_by" : "Dist::Zilla version 4.300015, CPAN::Meta::Converter version 2.120630",
77 "license" : [
88 "apache_2_0"
99 ],
5757 "provides" : {
5858 "Capture::Tiny" : {
5959 "file" : "lib/Capture/Tiny.pm",
60 "version" : "0.17_52"
60 "version" : "0.17_53"
6161 }
6262 },
6363 "release_status" : "testing",
7373 "web" : "https://github.com/dagolden/capture-tiny"
7474 }
7575 },
76 "version" : "0.17_52"
76 "version" : "0.17_53"
7777 }
7878
55
66 =head1 VERSION
77
8 version 0.17_52
8 version 0.17_53
99
1010 =head1 SYNOPSIS
1111
7878 filehandles during a capture operation will give unpredictable results.
7979 Existing IO layers on them may be changed by the capture.
8080
81 When called in void context, C<<< capture >>> saves memory and time by
82 not reading back from the capture handles.
83
8184 =head2 capture_stdout
8285
8386 ($stdout, @result) = capture_stdout \&code;
113116
114117 The C<<< tee >>> function works just like C<<< capture >>>, except that output is captured
115118 as well as passed on to the original STDOUT and STDERR.
119
120 When called in void context, C<<< tee >>> saves memory and time by
121 not reading back from the capture handles, except when the
122 original STDOUT OR STDERR were tied or opened to a scalar
123 handle.
116124
117125 =head2 tee_stdout
118126
370370 _unproxy( %proxy_std );
371371 # _debug( "# killing tee subprocesses ...\n" ) if $do_tee;
372372 _kill_tees( $stash ) if $do_tee;
373 # return captured output
373 # return captured output, but shortcut in void context
374 # unless we have to echo output to tied/scalar handles;
374375 my %got;
375 for ( keys %do ) {
376 _relayer($stash->{capture}{$_}, $layers{$_});
377 $got{$_} = _slurp($_, $stash);
378 # _debug("# slurped " . length($got{$_}) . " bytes from $_\n");
379 }
380 print CT_ORIG_STDOUT $got{stdout}
381 if $do_stdout && $do_tee && $localize{stdout};
382 print CT_ORIG_STDERR $got{stderr}
383 if $do_stderr && $do_tee && $localize{stderr};
376 if ( defined wantarray or ($do_tee && keys %localize) ) {
377 for ( keys %do ) {
378 _relayer($stash->{capture}{$_}, $layers{$_});
379 $got{$_} = _slurp($_, $stash);
380 # _debug("# slurped " . length($got{$_}) . " bytes from $_\n");
381 }
382 print CT_ORIG_STDOUT $got{stdout}
383 if $do_stdout && $do_tee && $localize{stdout};
384 print CT_ORIG_STDERR $got{stderr}
385 if $do_stderr && $do_tee && $localize{stderr};
386 }
384387 $? = $exit_code;
385388 $@ = $inner_error if $inner_error;
386389 die $outer_error if $outer_error;
387390 # _debug( "# ending _capture_tee with (@_)...\n" );
391 return unless defined wantarray;
388392 my @return;
389393 push @return, $got{stdout} if $do_stdout;
390394 push @return, $got{stderr} if $do_stderr;
469473 filehandles during a capture operation will give unpredictable results.
470474 Existing IO layers on them may be changed by the capture.
471475
476 When called in void context, {capture} saves memory and time by
477 not reading back from the capture handles.
478
472479 == capture_stdout
473480
474481 ($stdout, @result) = capture_stdout \&code;
504511
505512 The {tee} function works just like {capture}, except that output is captured
506513 as well as passed on to the original STDOUT and STDERR.
514
515 When called in void context, {tee} saves memory and time by
516 not reading back from the capture handles, except when the
517 original STDOUT OR STDERR were tied or opened to a scalar
518 handle.
507519
508520 == tee_stdout
509521