line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
################################################################################ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id: StringHandleTier.pm 211 2009-05-25 06:05:50Z aijaz $ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
################################################################################ |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
StringHandleTier - implementation class to which file handles are |
12
|
|
|
|
|
|
|
tied. See TaskForest::StringHandle; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $obj = tie(*STDOUT, 'TaskForest::StringHandleTier'); |
17
|
|
|
|
|
|
|
# STDOUT is now tied to the class |
18
|
|
|
|
|
|
|
print "Booyah!"; # @$obj is ['Booyah!'] |
19
|
|
|
|
|
|
|
$data = $obj->getData; # $data eq 'Booyah!' |
20
|
|
|
|
|
|
|
undef $obj; # get rid of reference to STDOUT |
21
|
|
|
|
|
|
|
untie(*STDOUT); # STDOUT is 'back to normal' |
22
|
|
|
|
|
|
|
print "Hello, world!\n"; # printed to stdout |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
This is a helper class that does the actual tying. Inspired by the |
26
|
|
|
|
|
|
|
examples in Chapter 14 of the Camel book. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
package TaskForest::StringHandleTier; |
31
|
22
|
|
|
22
|
|
122
|
use strict; |
|
22
|
|
|
|
|
50
|
|
|
22
|
|
|
|
|
702
|
|
32
|
22
|
|
|
22
|
|
108
|
use warnings; |
|
22
|
|
|
|
|
46
|
|
|
22
|
|
|
|
|
1714
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
BEGIN { |
35
|
22
|
|
|
22
|
|
121
|
use vars qw($VERSION); |
|
22
|
|
|
|
|
60
|
|
|
22
|
|
|
|
|
2396
|
|
36
|
22
|
|
|
22
|
|
8163
|
$VERSION = '1.30'; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub TIEHANDLE { |
41
|
2
|
|
|
2
|
|
1584
|
my $class = shift; |
42
|
2
|
|
|
|
|
15
|
return bless [], $class; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub PRINT { |
46
|
2
|
|
|
2
|
|
2644
|
my $self = shift; |
47
|
2
|
|
|
|
|
15
|
push (@$self, @_); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub PRINTF { |
51
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
52
|
0
|
|
|
|
|
0
|
my $fmt = shift; |
53
|
0
|
|
|
|
|
0
|
push @$self, sprintf $fmt, @_; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub getData { |
57
|
2
|
|
|
2
|
0
|
2385
|
my $self = shift; |
58
|
2
|
|
|
|
|
9
|
my $d = join("", @$self); |
59
|
2
|
|
|
|
|
6
|
@$self = (); |
60
|
2
|
|
|
|
|
8
|
return $d; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |