line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
69618
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
96
|
|
2
|
2
|
50
|
|
2
|
|
11
|
BEGIN{ if (not $] < 5.006) { require warnings; warnings->import } } |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
167
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Tie::Handle::Offset; |
5
|
|
|
|
|
|
|
# ABSTRACT: Tied handle that hides the beginning of a file |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.004'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1007
|
use Tie::Handle; |
|
2
|
|
|
|
|
3996
|
|
|
2
|
|
|
|
|
217
|
|
10
|
|
|
|
|
|
|
our @ISA = qw/Tie::Handle/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
13
|
|
|
|
|
|
|
# Glob slot accessor |
14
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub offset { |
17
|
22
|
|
|
22
|
1
|
38
|
my $self = shift; |
18
|
22
|
100
|
|
|
|
49
|
if ( @_ ) { |
19
|
6
|
|
|
|
|
8
|
return ${*$self}{offset} = shift; |
|
6
|
|
|
|
|
41
|
|
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
else { |
22
|
16
|
|
|
|
|
24
|
return ${*$self}{offset}; |
|
16
|
|
|
|
|
96
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
27
|
|
|
|
|
|
|
# Tied handle methods |
28
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub TIEHANDLE |
31
|
|
|
|
|
|
|
{ |
32
|
3
|
|
|
3
|
|
752
|
my $class = shift; |
33
|
3
|
|
|
|
|
4
|
my $params; |
34
|
3
|
100
|
|
|
|
11
|
$params = pop if ref $_[-1] eq 'HASH'; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
2
|
|
14
|
my $self = \do { no warnings 'once'; local *HANDLE}; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1210
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
12
|
|
37
|
3
|
|
|
|
|
6
|
bless $self,$class; |
38
|
|
|
|
|
|
|
|
39
|
3
|
50
|
|
|
|
13
|
$self->OPEN(@_) if (@_); |
40
|
3
|
100
|
|
|
|
13
|
if ( $params->{offset} ) { |
41
|
2
|
|
|
|
|
10
|
seek( $self, $self->offset( $params->{offset} ), 0 ); |
42
|
|
|
|
|
|
|
} |
43
|
3
|
|
|
|
|
16
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub TELL { |
47
|
7
|
|
|
7
|
|
1024
|
my $cur = tell($_[0]) - $_[0]->offset; |
48
|
|
|
|
|
|
|
# XXX shouldn't ever be less than zero, but just in case... |
49
|
7
|
100
|
|
|
|
32
|
return $cur > 0 ? $cur : 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub SEEK { |
53
|
9
|
|
|
9
|
|
30
|
my ($self, $pos, $whence) = @_; |
54
|
9
|
|
|
|
|
12
|
my $rc; |
55
|
9
|
100
|
66
|
|
|
41
|
if ( $whence == 0 || $whence == 1 ) { # pos from start, cur |
|
|
100
|
|
|
|
|
|
56
|
4
|
|
|
|
|
11
|
$rc = seek($self, $pos + $self->offset, $whence); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
elsif ( _size($self) + $pos < $self->offset ) { # from end |
59
|
3
|
|
|
|
|
6
|
$rc = ''; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
2
|
|
|
|
|
16
|
$rc = seek($self,$pos,$whence); |
63
|
|
|
|
|
|
|
} |
64
|
9
|
|
|
|
|
43
|
return $rc; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub OPEN |
68
|
|
|
|
|
|
|
{ |
69
|
3
|
|
|
3
|
|
10
|
$_[0]->offset(0); |
70
|
3
|
50
|
|
|
|
11
|
$_[0]->CLOSE if defined($_[0]->FILENO); |
71
|
3
|
50
|
|
|
|
124
|
@_ == 2 ? open($_[0], $_[1]) : open($_[0], $_[1], $_[2]); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _size { |
75
|
5
|
|
|
5
|
|
8
|
my ($self) = @_; |
76
|
5
|
|
|
|
|
9
|
my $cur = tell($self); |
77
|
5
|
|
|
|
|
43
|
seek($self,0,2); # end |
78
|
5
|
|
|
|
|
13
|
my $size = tell($self); |
79
|
5
|
|
|
|
|
30
|
seek($self,$cur,0); # reset |
80
|
5
|
|
|
|
|
19
|
return $size; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
84
|
|
|
|
|
|
|
# Methods copied from Tie::StdHandle to avoid dependency on Perl 5.8.9/5.10.0 |
85
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
0
|
|
0
|
sub EOF { eof($_[0]) } |
88
|
3
|
|
|
3
|
|
23
|
sub FILENO { fileno($_[0]) } |
89
|
0
|
|
|
0
|
|
0
|
sub CLOSE { close($_[0]) } |
90
|
0
|
|
|
0
|
|
0
|
sub BINMODE { binmode($_[0]) } |
91
|
0
|
|
|
0
|
|
0
|
sub READ { read($_[0],$_[1],$_[2]) } |
92
|
8
|
|
|
8
|
|
17
|
sub READLINE { my $fh = $_[0]; <$fh> } |
|
8
|
|
|
|
|
131
|
|
93
|
0
|
|
|
0
|
|
|
sub GETC { getc($_[0]) } |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub WRITE |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
0
|
|
|
my $fh = $_[0]; |
98
|
0
|
|
|
|
|
|
print $fh substr($_[1],0,$_[2]) |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# vim: ts=2 sts=2 sw=2 et: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |