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