InnerFile.pm

filter: Statementstmt 59.2% 67 / 113 Branchbran 52.3% 22 / 42 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 35.2% 12 / 34 Podpod 100% 21 / 21 totaltotal 56.3% 124 / 220 CC 24 SCAR 15.3
CC
24
Cov
57%
GETC
20.0
seek
6.8
new
6.1
CRAP 4.6
« AtomicFile.pm ↑ Summary Scalar.pm »
1 package IO::InnerFile;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '2.113';
8  
9 2 ▶sub new {
Subroutine new: called CC=5 SCAR=18.1
Pod documented
10 2 my ($class, $fh, $start, $lg) = @_;
11 2 ▶ $start = 0 if (!$start or ($start < 0));
Branch: 1 branch
BranchTrueFalseTotal
if not $start or $start < 0 0 2 2
Condition33%1/3
not $start or $start < 0
l!l&&r!l&&!r
002
MC/DC0%0/2
not $start or $start < 0
not $start $start < 0
Truth table33%1/3
not(A) or B
A= not $startB= $start < 0
ABresult
1X1
011
000
12 2 ▶ $lg = 0 if (!$lg or ($lg < 0));
Branch: 1 branch
BranchTrueFalseTotal
if not $lg or $lg < 0 0 2 2
Condition33%1/3
not $lg or $lg < 0
l!l&&r!l&&!r
002
MC/DC0%0/2
not $lg or $lg < 0
not $lg $lg < 0
Truth table33%1/3
not(A) or B
A= not $lgB= $lg < 0
ABresult
1X1
011
000
13  
14 ### Create the underlying "object":
15 2 my $a = {
16 FH => $fh,
17 CRPOS => 0,
18 START => $start,
19 LG => $lg,
20 };
21  
22 ### Create a new filehandle tied to this object:
23 2 $fh = gensym;
24 2 tie(*$fh, $class, $a);
25 2 return bless($fh, $class);
26 }
27  
28 2 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
29 2 my ($class, $data) = @_;
30 2 return bless($data, $class);
31 }
32  
33 4 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.2
34 4 my ($self) = @_;
35 4 ▶ $self->close() if (ref($self) eq 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $self eq "SCALAR" 0 4 4
36 }
37  
38 0 ▶sub set_length { tied(${$_[0]})->{LG} = $_[1]; }
Subroutine set_length: not called CC=1 SCAR=6.9
Pod documented
39 0 ▶sub get_length { tied(${$_[0]})->{LG}; }
Subroutine get_length: not called CC=1 SCAR=6.9
Pod documented
40 0 ▶sub add_length { tied(${$_[0]})->{LG} += $_[1]; }
Subroutine add_length: not called CC=1 SCAR=6.9
Pod documented
41  
42 0 ▶sub set_start { tied(${$_[0]})->{START} = $_[1]; }
Subroutine set_start: not called CC=1 SCAR=6.9
Pod documented
43 0 ▶sub get_start { tied(${$_[0]})->{START}; }
Subroutine get_start: not called CC=1 SCAR=6.9
Pod documented
44 0 ▶sub set_end { tied(${$_[0]})->{LG} = $_[1] - tied(${$_[0]})->{START}; }
Subroutine set_end: not called CC=1 SCAR=6.9
Pod documented
45 0 ▶sub get_end { tied(${$_[0]})->{LG} + tied(${$_[0]})->{START}; }
Subroutine get_end: not called CC=1 SCAR=6.9
Pod documented
46  
47 0 ▶sub write { shift->WRITE(@_) }
Subroutine write: not called CC=1 SCAR=6.9
Pod documented
48 0 ▶sub print { shift->PRINT(@_) }
Subroutine print: not called CC=1 SCAR=6.9
Pod documented
49 0 ▶sub printf { shift->PRINTF(@_) }
Subroutine printf: not called CC=1 SCAR=6.9
Pod documented
50 0 ▶sub flush { "0 but true"; }
Subroutine flush: not called CC=1 SCAR=6.9
Pod documented
51 0 ▶sub fileno { }
Subroutine fileno: not called CC=1 SCAR=0.0
Pod documented
52 0 ▶sub binmode { 1; }
Subroutine binmode: not called CC=1 SCAR=6.9
Pod documented
53 0 ▶sub getc { return GETC(tied(${$_[0]}) ); }
Subroutine getc: not called CC=1 SCAR=6.9
Pod documented
54 0 ▶sub read { return READ( tied(${$_[0]}), @_[1,2,3] ); }
Subroutine read: not called CC=1 SCAR=6.9
Pod documented
55 0 ▶sub readline { return READLINE( tied(${$_[0]}) ); }
Subroutine readline: not called CC=1 SCAR=6.9
Pod documented
56  
57 0 ▶sub getline { return READLINE( tied(${$_[0]}) ); }
Subroutine getline: not called CC=1 SCAR=6.9
Pod documented
58 1 ▶sub close { return CLOSE(tied(${$_[0]}) ); }
Subroutine close: called CC=1 SCAR=0.0
Pod documented
59  
60 1 ▶sub seek {
Subroutine seek: called CC=6 SCAR=19.1
Pod documented
61 1 my ($self, $ofs, $whence) = @_;
62 1 $self = tied( $$self );
63  
64 1 ▶ $self->{CRPOS} = $ofs if ($whence == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $whence == 0 1 0 1
65 1 ▶ $self->{CRPOS}+= $ofs if ($whence == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $whence == 1 0 1 1
66 1 ▶ $self->{CRPOS} = $self->{LG} + $ofs if ($whence == 2);
Branch: 1 branch
BranchTrueFalseTotal
if $whence == 2 0 1 1
67  
68 1 ▶ $self->{CRPOS} = 0 if ($self->{CRPOS} < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CRPOS"} < 0 0 1 1
69 1 ▶ $self->{CRPOS} = $self->{LG} if ($self->{CRPOS} > $self->{LG});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CRPOS"} > $self->{"LG"} 0 1 1
70 1 return 1;
71 }
72  
73 0 ▶sub tell {
Subroutine tell: not called CC=1 SCAR=6.9
Pod documented
74 0 return tied(${$_[0]})->{CRPOS};
75 }
76  
77 0 ▶sub WRITE {
Subroutine WRITE: not called CC=1 SCAR=6.9
78 0 die "inner files can only open for reading\n";
79 }
80  
81 0 ▶sub PRINT {
Subroutine PRINT: not called CC=1 SCAR=6.9
82 0 die "inner files can only open for reading\n";
83 }
84  
85 0 ▶sub PRINTF {
Subroutine PRINTF: not called CC=1 SCAR=6.9
86 0 die "inner files can only open for reading\n";
87 }
88  
89 0 ▶sub GETC {
Subroutine GETC: not called CC=4 SCAR=30.0
90 0 my ($self) = @_;
91 0 ▶ return 0 if ($self->{CRPOS} >= $self->{LG});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CRPOS"} >= $self->{"LG"} 0 0 0
92  
93 0 my $data;
94  
95 ### Save and seek...
96 0 my $old_pos = $self->{FH}->tell;
97 0 $self->{FH}->seek($self->{CRPOS}+$self->{START}, 0);
98  
99 ### ...read...
100 0 my $lg = $self->{FH}->read($data, 1);
101 0 $self->{CRPOS} += $lg;
102  
103 ### ...and restore:
104 0 $self->{FH}->seek($old_pos, 0);
105  
106 0 ▶ $self->{LG} = $self->{CRPOS} unless ($lg);
Branch: 1 branch
BranchTrueFalseTotal
unless $lg 0 0 0
107 0 ▶ return ($lg ? $data : undef);
Branch: 1 branch
BranchTrueFalseTotal
$lg ? : 0 0 0
108 }
109  
110 1 ▶sub READ {
Subroutine READ: called CC=5 SCAR=16.5
111 1 my ($self, $undefined, $lg, $ofs) = @_;
112 1 $undefined = undef;
113  
114 1 ▶ return 0 if ($self->{CRPOS} >= $self->{LG});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CRPOS"} >= $self->{"LG"} 0 1 1
115 1 ▶ $lg = $self->{LG} - $self->{CRPOS} if ($self->{CRPOS} + $lg > $self->{LG});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CRPOS"} + $lg > $self->{"LG"} 0 1 1
116 1 ▶ return 0 unless ($lg);
Branch: 1 branch
BranchTrueFalseTotal
unless $lg 0 1 1
117  
118 ### Save and seek...
119 1 my $old_pos = $self->{FH}->tell;
120 1 $self->{FH}->seek($self->{CRPOS}+$self->{START}, 0);
121  
122 ### ...read...
123 1 $lg = $self->{FH}->read($_[1], $lg, $_[3] );
124 1 $self->{CRPOS} += $lg;
125  
126 ### ...and restore:
127 1 $self->{FH}->seek($old_pos, 0);
128  
129 1 ▶ $self->{LG} = $self->{CRPOS} unless ($lg);
Branch: 1 branch
BranchTrueFalseTotal
unless $lg 0 1 1
130 1 return $lg;
131 }
132  
133 5 ▶sub READLINE {
Subroutine READLINE: called CC=3 SCAR=11.0
134 5 my ($self) = @_;
135 5 ▶ return $self->_readline_helper() unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 4 1 5
136 1 my @arr;
137 1 ▶ while(defined(my $line = $self->_readline_helper())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->_readline_helper)) 2 1 3
138 2 push(@arr, $line);
139 }
140 1 return @arr;
141 }
142  
143 7 ▶sub _readline_helper {
Subroutine _readline_helper: called CC=5 SCAR=16.3
144 7 my ($self) = @_;
145 7 ▶ return undef if ($self->{CRPOS} >= $self->{LG});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CRPOS"} >= $self->{"LG"} 2 5 7
146  
147 # Handle slurp mode (CPAN ticket #72710)
148 5 ▶ if (! defined($/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $/) 1 4 5
149 1 my $text;
150 1 $self->READ($text, $self->{LG} - $self->{CRPOS});
151 1 return $text;
152 }
153  
154 ### Save and seek...
155 4 my $old_pos = $self->{FH}->tell;
156 4 $self->{FH}->seek($self->{CRPOS}+$self->{START}, 0);
157  
158 ### ...read...
159 4 my $text = $self->{FH}->getline;
160  
161 ### ...and restore:
162 4 $self->{FH}->seek($old_pos, 0);
163  
164 #### If we detected a new EOF ...
165 4 ▶ unless (defined $text) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text) 0 4 4
166 0 $self->{LG} = $self->{CRPOS};
167 0 return undef;
168 }
169  
170 4 my $lg=length($text);
171  
172 4 ▶ $lg = $self->{LG} - $self->{CRPOS} if ($self->{CRPOS} + $lg > $self->{LG});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CRPOS"} + $lg > $self->{"LG"} 0 4 4
173 4 $self->{CRPOS} += $lg;
174  
175 4 return substr($text, 0,$lg);
176 }
177  
178 1 ▶sub CLOSE { %{$_[0]}=(); }
Subroutine CLOSE: called CC=1 SCAR=0.0
179  
180  
181  
182 1 1;
183 __END__
« AtomicFile.pm ↑ Summary Scalar.pm »