| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package IPC::Run::SafeHandles; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21786
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
44
|
|
|
5
|
1
|
|
|
1
|
|
1090
|
use IO::Handle (); |
|
|
1
|
|
|
|
|
8825
|
|
|
|
1
|
|
|
|
|
25
|
|
|
6
|
1
|
|
|
1
|
|
1679
|
use List::MoreUtils 'any'; |
|
|
1
|
|
|
|
|
2677
|
|
|
|
1
|
|
|
|
|
195
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
IPC::Run::SafeHandles - Use IPC::Run and IPC::Run3 safely |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use IPC::Run::SafeHandles; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
L and L are both very upset when you try to use |
|
23
|
|
|
|
|
|
|
them under environments where you have STDOUT and/or STDERR tied to |
|
24
|
|
|
|
|
|
|
something else, such as under fastcgi. |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
The module adds safe-guarding code when you call L or |
|
27
|
|
|
|
|
|
|
L under such environment to make sure it always works. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
If you intend to release your code to work under normal envionrment |
|
30
|
|
|
|
|
|
|
as well as under fastcgi, simply use this module I the C |
|
31
|
|
|
|
|
|
|
modules are loaded in your code. |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $wrapper_context = []; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _wrap_it { |
|
38
|
1
|
|
|
1
|
|
10
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
400
|
|
|
39
|
0
|
|
|
0
|
|
0
|
my $typeglob = shift; |
|
40
|
0
|
|
|
|
|
0
|
my $caller = shift; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
my $original = *$typeglob{CODE}; |
|
43
|
0
|
|
|
|
|
0
|
my $unwrap = 0; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $wrapper = sub { |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
goto &$original unless $ENV{FCGI_ROLE} |
|
48
|
0
|
0
|
0
|
0
|
|
0
|
|| any { $_ eq 'via'} PerlIO::get_layers(*STDOUT), PerlIO::get_layers(*STDERR); |
|
|
0
|
|
|
|
|
0
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
my $stdout = IO::Handle->new; |
|
51
|
0
|
|
|
|
|
0
|
$stdout->fdopen( 1, 'w' ); |
|
52
|
0
|
|
|
|
|
0
|
local *STDOUT = $stdout; |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
my $stderr = IO::Handle->new; |
|
55
|
0
|
|
|
|
|
0
|
$stderr->fdopen( 2, 'w' ); |
|
56
|
0
|
|
|
|
|
0
|
local *STDERR = $stderr; |
|
57
|
0
|
|
|
|
|
0
|
$original->(@_); |
|
58
|
0
|
|
|
|
|
0
|
}; |
|
59
|
1
|
|
|
1
|
|
7
|
no warnings 'redefine'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
210
|
|
|
60
|
0
|
|
|
|
|
0
|
my $callerglob = $typeglob; $callerglob =~ s/IPC::Run3?/$caller/; |
|
|
0
|
|
|
|
|
0
|
|
|
61
|
0
|
|
|
|
|
0
|
*{$typeglob} = $wrapper; |
|
|
0
|
|
|
|
|
0
|
|
|
62
|
0
|
|
|
|
|
0
|
*{$callerglob} = $wrapper; |
|
|
0
|
|
|
|
|
0
|
|
|
63
|
|
|
|
|
|
|
push @$wrapper_context, |
|
64
|
1
|
|
|
1
|
|
7
|
bless(sub { no warnings 'redefine'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
263
|
|
|
65
|
0
|
|
|
0
|
|
0
|
*{$callerglob} = $original; |
|
|
0
|
|
|
|
|
0
|
|
|
66
|
0
|
|
|
|
|
0
|
*{$typeglob} = $original }, __PACKAGE__); |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub import { |
|
70
|
1
|
|
|
1
|
|
12
|
my $caller = caller(); |
|
71
|
1
|
50
|
|
|
|
6
|
_wrap_it('IPC::Run::run', $caller) if $INC{'IPC/Run.pm'}; |
|
72
|
1
|
50
|
|
|
|
5
|
_wrap_it('IPC::Run3::run3', $caller) if $INC{'IPC/Run3.pm'}; |
|
73
|
|
|
|
|
|
|
|
|
74
|
1
|
50
|
|
|
|
4
|
unless (@$wrapper_context) { |
|
75
|
1
|
|
|
|
|
172
|
Carp::carp "Use of IPC::Run::SafeHandles without using IPC::Run or IPC::Run3 first"; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 unimport |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
When unimport, the original L and/or L functions |
|
82
|
|
|
|
|
|
|
are restored. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub unimport { |
|
87
|
0
|
|
|
0
|
|
|
$wrapper_context = []; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
0
|
|
|
sub DESTROY { $_[0]->() } |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 AUTHOR |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Chia-liang Kao, C<< >> |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 BUGS |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
99
|
|
|
|
|
|
|
C, or through the web interface at |
|
100
|
|
|
|
|
|
|
L. |
|
101
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
102
|
|
|
|
|
|
|
your bug as I make changes. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SUPPORT |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
perldoc IPC::Run::SafeHandles |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
You can also look for information at: |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=over 4 |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
L |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
L |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * Search CPAN |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=back |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Copyright 2007 Chia-liang Kao, all rights reserved. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
139
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; # End of IPC::Run::SafeHandles |