line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IO::Catch; |
2
|
1
|
|
|
1
|
|
25895
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
78
|
|
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
|
|
4
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
125
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$VERSION = '0.02'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub TIEHANDLE { |
31
|
2
|
|
|
2
|
|
23
|
my($class, $var) = @_; |
32
|
2
|
50
|
|
|
|
8
|
croak "Need a variable name to tie to" unless $var; |
33
|
2
|
|
|
|
|
13
|
return bless { var => $var }, $class; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub PRINT { |
37
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
104
|
|
38
|
0
|
|
|
0
|
|
|
my($self) = shift; |
39
|
0
|
|
|
|
|
|
${'main::'.$self->{var}} = "" |
|
0
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
unless defined ${'main::'.$self->{var}}; |
41
|
0
|
|
|
|
|
|
${'main::'.$self->{var}} .= join '', @_; |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub PRINTF { |
45
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
170
|
|
46
|
0
|
|
|
0
|
|
|
my($self) = shift; |
47
|
0
|
|
|
|
|
|
my $tmpl = shift; |
48
|
0
|
|
|
|
|
|
${'main::'.$self->{var}} = "" |
|
0
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
unless defined ${'main::'.$self->{var}}; |
50
|
0
|
|
|
|
|
|
${'main::'.$self->{var}} .= sprintf $tmpl, @_; |
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
0
|
|
|
sub OPEN {} # XXX Hackery in case the user redirects |
54
|
0
|
|
|
0
|
|
|
sub CLOSE {} # XXX STDERR/STDOUT. This is not the behavior we want. |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
0
|
|
|
sub READ {} |
57
|
0
|
|
|
0
|
|
|
sub READLINE {} |
58
|
0
|
|
|
0
|
|
|
sub GETC {} |
59
|
0
|
|
|
0
|
|
|
sub BINMODE {} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |