| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package IO::Catch; | 
| 2 | 1 |  |  | 1 |  | 2150 | use strict; | 
|  | 1 |  |  |  |  | 0 |  | 
|  | 1 |  |  |  |  | 23 |  | 
| 3 | 1 |  |  | 1 |  | 2 | use Carp qw(croak); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 36 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =head1 NAME | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | IO::Catch - capture STDOUT and STDERR into global variables | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 AUTHOR | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | Max Maischein ( corion at cpan.org ) | 
| 12 |  |  |  |  |  |  | All code ripped from pod2test by M. Schwern | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | # pre-5.8.0's warns aren't caught by a tied STDERR. | 
| 17 |  |  |  |  |  |  | use vars qw($_STDOUT_, $_STDERR_); | 
| 18 |  |  |  |  |  |  | tie *STDOUT, 'IO::Catch', '_STDOUT_' or die $!; | 
| 19 |  |  |  |  |  |  | tie *STDERR, 'IO::Catch', '_STDERR_' or die $!; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | # now you can access $main::_STDOUT_ and $_STDERR_ | 
| 22 |  |  |  |  |  |  | # to see the output. | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =cut | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 1 |  |  | 1 |  | 2 | use vars qw($VERSION); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 80 |  | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | $VERSION = '0.02'; | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | sub TIEHANDLE { | 
| 31 | 1 |  |  | 1 |  | 5 | my($class, $var) = @_; | 
| 32 | 1 | 50 |  |  |  | 3 | croak "Need a variable name to tie to" unless $var; | 
| 33 | 1 |  |  |  |  | 4 | return bless { var => $var }, $class; | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | sub PRINT  { | 
| 37 | 1 |  |  | 1 |  | 3 | no strict 'refs'; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 79 |  | 
| 38 | 0 |  |  | 0 |  |  | my($self) = shift; | 
| 39 | 0 |  |  |  |  |  | ${'main::'.$self->{var}} = "" | 
| 40 | 0 | 0 |  |  |  |  | unless defined ${'main::'.$self->{var}}; | 
|  | 0 |  |  |  |  |  |  | 
| 41 | 0 |  |  |  |  |  | ${'main::'.$self->{var}} .= join '', @_; | 
|  | 0 |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | sub PRINTF { | 
| 45 | 1 |  |  | 1 |  | 3 | no strict 'refs'; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 104 |  | 
| 46 | 0 |  |  | 0 |  |  | my($self) = shift; | 
| 47 | 0 |  |  |  |  |  | my $tmpl = shift; | 
| 48 | 0 |  |  |  |  |  | ${'main::'.$self->{var}} = "" | 
| 49 | 0 | 0 |  |  |  |  | unless defined ${'main::'.$self->{var}}; | 
|  | 0 |  |  |  |  |  |  | 
| 50 | 0 |  |  |  |  |  | ${'main::'.$self->{var}} .= sprintf $tmpl, @_; | 
|  | 0 |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  | 0 |  |  | sub OPEN  {}    # XXX Hackery in case the user redirects | 
| 54 |  |  |  | 0 |  |  | sub CLOSE {}    # XXX STDERR/STDOUT.  This is not the behavior we want. | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  | 0 |  |  | sub READ {} | 
| 57 |  |  |  | 0 |  |  | sub READLINE {} | 
| 58 |  |  |  | 0 |  |  | sub GETC {} | 
| 59 |  |  |  | 0 |  |  | sub BINMODE {} | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | 1; |