line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MemHandle::Tie; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
5
|
1
|
|
|
1
|
|
767
|
use IO::Seekable; |
|
1
|
|
|
|
|
6755
|
|
|
1
|
|
|
|
|
56
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
1
|
|
|
1
|
|
25
|
use 5.000; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
285
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
14
|
|
|
|
|
|
|
@EXPORT = qw( |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
$VERSION = '0.06'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Preloaded methods go here. |
21
|
|
|
|
|
|
|
sub TIEHANDLE { |
22
|
1
|
|
|
1
|
|
2
|
my( $class, $mem ) = @_; |
23
|
1
|
|
50
|
|
|
11
|
$class = ref( $class ) || $class || 'MemHandle::Tie'; |
24
|
1
|
|
|
|
|
5
|
my $self = {mem => $mem, |
25
|
|
|
|
|
|
|
pos => length($mem)}; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
5
|
bless( $self, $class ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub WRITE { |
31
|
0
|
|
|
0
|
|
0
|
my( $self, $buf, $len, $offset ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#$self->{mem} .= substr( $buf, $len, $offset ); |
34
|
0
|
|
|
|
|
0
|
substr( $self->{mem}, $self->{pos}, $len ) = substr( $buf, $len, $offset ); |
35
|
0
|
|
|
|
|
0
|
$self->{pos} += $len; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
$len; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub READLINE { |
41
|
1
|
|
|
1
|
|
8
|
my $self = shift; |
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
8
|
if ( $self->{pos} >= length( $self->{mem} ) ) { |
|
|
50
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
return undef; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ( wantarray() ) { |
47
|
0
|
|
|
|
|
0
|
my @lines = split( $/, substr( $self->{mem}, $self->{pos} ) ); |
48
|
0
|
|
|
|
|
0
|
$self->{pos} = length( $self->{mem} ); |
49
|
0
|
|
|
|
|
0
|
return map("$_$/",@lines); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
1
|
|
|
|
|
6
|
my $i = index( substr( $self->{mem}, $self->{pos} ), $/, $self->{pos} ); |
53
|
1
|
|
|
|
|
3
|
my $line; |
54
|
|
|
|
|
|
|
|
55
|
1
|
50
|
|
1
|
|
855
|
if ( $i != $[ - 1 ) { |
|
1
|
|
|
|
|
354
|
|
|
1
|
|
|
|
|
630
|
|
|
1
|
|
|
|
|
9
|
|
56
|
0
|
|
|
|
|
0
|
$i++; # can't go off the deep end or $i would be $[ - 1 |
57
|
0
|
|
|
|
|
0
|
$line = substr( $self->{mem}, $self->{pos}, $i - $self->{pos} ); |
58
|
0
|
|
|
|
|
0
|
$self->{pos} = $i |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
1
|
|
|
|
|
3
|
$line = substr( $self->{mem}, $self->{pos} ); |
62
|
1
|
|
|
|
|
3
|
$self->{pos} = length( $self->{mem} ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
3
|
return $line; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub READ { |
70
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
71
|
0
|
|
|
|
|
0
|
local *MemHandle::Tie::buf = \shift; |
72
|
0
|
|
|
|
|
0
|
my( $len, $offset ) = @_; |
73
|
0
|
|
|
|
|
0
|
my $leftlen = length( $self->{mem} ) - $self->{pos}; |
74
|
0
|
0
|
|
|
|
0
|
if ( $len > $leftlen ) { |
75
|
0
|
|
|
|
|
0
|
$len = $leftlen; |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
0
|
substr( $MemHandle::Tie::buf, $offset, $len ) = substr( $self->{mem}, $self->{pos}, $len ); |
78
|
0
|
|
|
|
|
0
|
$self->{pos} += $len; |
79
|
0
|
|
|
|
|
0
|
$len; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub GETC { |
83
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
84
|
0
|
0
|
|
|
|
0
|
if ( $self->{pos} < length( $self->{mem} ) ) { |
85
|
0
|
|
|
|
|
0
|
my $char = substr( $self->{mem}, $self->{pos}, 1 ); |
86
|
0
|
|
|
|
|
0
|
$self->{pos}++; |
87
|
0
|
|
|
|
|
0
|
return $char; |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
0
|
return undef; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub PRINT { |
93
|
1
|
|
|
1
|
|
19
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
4
|
my $lines = join('', @_); |
96
|
1
|
|
|
|
|
3
|
my $len = length( $lines ); |
97
|
1
|
|
|
|
|
9
|
substr( $self->{mem}, $self->{pos}, $len ) = $lines; |
98
|
1
|
|
|
|
|
3
|
$self->{pos} += $len; |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
3
|
1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub PRINTF { |
104
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
my $str = sprintf( shift, @_ ); |
107
|
0
|
|
|
|
|
0
|
my $len = length( $str ); |
108
|
0
|
|
|
|
|
0
|
substr( $self->{mem}, $self->{pos}, $len ) = $str; |
109
|
0
|
|
|
|
|
0
|
$self->{pos} += $len; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
0
|
1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub CLOSE { |
115
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
116
|
0
|
|
|
|
|
0
|
untie $self; |
117
|
0
|
|
|
|
|
0
|
$self; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub SEEK { |
121
|
1
|
|
|
1
|
|
3
|
my( $self, $pos, $whence ) = @_; |
122
|
|
|
|
|
|
|
|
123
|
1
|
50
|
|
|
|
4
|
if ( $whence == SEEK_SET ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
elsif ( $whence == SEEK_CUR ) { |
126
|
0
|
|
|
|
|
0
|
$pos += $self->{$pos}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
elsif ( $whence == SEEK_END ) { |
129
|
0
|
|
|
|
|
0
|
$pos += length( $self->{mem} ); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else { |
132
|
0
|
|
|
|
|
0
|
return 0; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
1
|
50
|
|
|
|
5
|
if ( $pos <= length( $self->{mem} ) ) { |
136
|
1
|
|
|
|
|
22
|
$self->{pos} = $pos; |
137
|
1
|
|
|
|
|
4
|
return 1; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
0
|
return 0; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub TELL { |
144
|
0
|
|
|
0
|
|
0
|
my( $self ) = @_; |
145
|
0
|
|
|
|
|
0
|
$self->{pos}; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub mem { |
149
|
1
|
|
|
1
|
0
|
3
|
my( $self, $mem ) = @_; |
150
|
|
|
|
|
|
|
|
151
|
1
|
50
|
|
|
|
3
|
if ( defined $mem ) { |
152
|
0
|
|
|
|
|
0
|
$self->{mem} = $mem; |
153
|
0
|
|
|
|
|
0
|
$self->{pos} = length( $mem ); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
1
|
|
|
|
|
4
|
$self->{mem}; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |
162
|
|
|
|
|
|
|
__END__ |