line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Egg::Util::STDIO; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: STDIO.pm 337 2008-05-14 12:30:09Z lushe $ |
6
|
|
|
|
|
|
|
# |
7
|
1
|
|
|
1
|
|
453
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
8
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
9
|
1
|
|
|
1
|
|
1797
|
use IO::Scalar; |
|
1
|
|
|
|
|
5141
|
|
|
1
|
|
|
|
|
71
|
|
10
|
1
|
|
|
1
|
|
7
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
297
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION= '3.00'; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
0
|
1
|
|
sub out { shift->_stdio(*STDOUT, @_) } |
15
|
0
|
|
|
0
|
1
|
|
sub in { shift->_stdio(*STDIN, @_) } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _stdio { |
18
|
0
|
|
|
0
|
|
|
my($class, $handle, $e)= splice @_, 0, 3; |
19
|
0
|
|
0
|
|
|
|
my $code= shift || croak q{ I want code. }; |
20
|
0
|
0
|
|
|
|
|
ref($code) eq 'CODE' || croak q{ I want CODE reference. }; |
21
|
0
|
|
0
|
|
|
|
my $q= shift || ""; |
22
|
0
|
0
|
|
|
|
|
$q= $$q if ref($q) eq 'SCALAR'; |
23
|
0
|
|
|
|
|
|
eval { |
24
|
0
|
|
|
|
|
|
tie $handle, 'IO::Scalar', \$q; |
25
|
0
|
|
|
|
|
|
$code->($e, @_); |
26
|
0
|
|
|
|
|
|
untie $handle; |
27
|
|
|
|
|
|
|
}; |
28
|
0
|
|
|
|
|
|
Egg::Util::STDIO::result->new($handle, \$q, $@); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package Egg::Util::STDIO::result; |
32
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
33
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
34
|
1
|
|
|
1
|
|
4
|
use base qw/Class::Accessor::Fast/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
222
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ result error /); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
0
|
|
|
0
|
|
|
my($class, $handle, $result, $error)= @_; |
40
|
0
|
0
|
0
|
|
|
|
$error= q{'STDOUT' is not output.} |
|
|
|
0
|
|
|
|
|
41
|
|
|
|
|
|
|
if ($handle=~m{STDOUT} and ! $error and ! defined($$result)); |
42
|
0
|
|
0
|
|
|
|
bless { result=> $$result, error=> ($error || undef) }, $class; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 NAME |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Egg::Util::STDIO - Module to use IO::Scalar easily. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SYNOPSIS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Egg::Util::STDIO; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $res= Egg::Util::STDIO->out(0, sub { |
58
|
|
|
|
|
|
|
print "Hellow"; |
59
|
|
|
|
|
|
|
}); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
print $res->result; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 DESCRIPTION |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
L<IO::Scalar> It is a module to use it for easy. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 METHODS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 out ([CONTEXT], [CODE_REF]) |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
STDOUT is obtained and the Egg::Util::STDIO::result object is returned. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
It is not especially necessary though the thing that the object of the project is passed is |
74
|
|
|
|
|
|
|
assumed to CONTEXT. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
CODE_REF is always necessary. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 in ([CONTEXT], [CODE_REF]) |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
STDIN is obtained and the Egg::Util::STDIO::result object is returned. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
It is not especially necessary though the thing that the object of the project is passed is |
83
|
|
|
|
|
|
|
assumed to CONTEXT. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
CODE_REF is always necessary. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 RESULT METHODS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 new |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Constructor. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 result |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
The obtained data is returned. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 error |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
When the error occurs, the message is returned. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SEE ALSO |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L<Egg::Release>, |
104
|
|
|
|
|
|
|
L<IO::Scalar>, |
105
|
|
|
|
|
|
|
L<Class::Accessor::Fast>, |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 AUTHOR |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
116
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
117
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|