Files/Virtual.pm

filter: Statementstmt 75.9% 215 / 283 Branchbran 52.2% 71 / 136 Conditioncond 50.0% 43 / 86 MC/DCmcdc 33.3% 16 / 48 Subroutinesub 68.8% 31 / 45 Podpod 16.6% 3 / 18 totaltotal 61.5% 379 / 616 SCAR 63.3
CC
104
Cov
65%
TRACE
72.0
READ
56.0
GETC
30.0
CRAP 561.9
↑ Summary Files.pm »
1 package Inline::Files::Virtual;
2 8 $VERSION = '0.53';
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Cwd qw(abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # To Do:
8 # - Add an EOF flag and make sure (virtual) system calls treat it right
9 # - Call close on an implicit open.
10 # - Add unlink(). Should behave properly if file is open.
11 # - Support this idiom for multiple FOO:
12 # open FOO;
13 # close FOO;
14 # while (open FOO) {
15 # while (<FOO>) {
16 # }
17 # }
18  
19 # Damian. Let's leave this trace feature in for a while.
20 # The calls to it should be constant folded out of the bytecode anyway,
21 # (when DEBUG is 0) so there's no real performance penalty.
22 # It has helped me find many a bug :)
23 BEGIN {
24 sub DEBUG () { 0 }
25 8 ▶ my ($TRACING, $ARGS) = (1, 1);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 0 ▶ sub TRACING {$ENV{INLINE_FILES_TRACE} || $TRACING}
Subroutine TRACING: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"INLINE_FILES_TRACE"} or $TRACING 0 0 0
27 0 ▶ sub ARGS {$ENV{INLINE_FILES_ARGS} || $ARGS}
Subroutine ARGS: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"INLINE_FILES_ARGS"} or $ARGS 0 0 0
28 sub TRACE {
29 0 ▶ $| = 1;
Subroutine TRACE: not called CC=8 SCAR=42.8
Pod undocumented
30 0 local $^W;
31 0 ▶ return unless TRACING || ARGS;
Branch: 1 branch
BranchTrueFalseTotal
unless TRACING() or ARGS() 0 0 0
Condition0%0/3
TRACING() or ARGS()
l!l&&r!l&&!r
000
MC/DC0%0/2
TRACING() or ARGS()
TRACING() ARGS()
Truth table0%0/3
A or B
A= TRACING()B= ARGS()
ABresult
1X1
011
000
32 0 ▶ print "=" x 79, "\n" if ARGS;
Branch: 1 branch
BranchTrueFalseTotal
if ARGS() 0 0 0
33 0 ▶ print ((caller(1))[3], "\n") if TRACING || ARGS;
Branch: 1 branch
BranchTrueFalseTotal
if TRACING() or ARGS() 0 0 0
Condition0%0/3
TRACING() or ARGS()
l!l&&r!l&&!r
000
MC/DC0%0/2
TRACING() or ARGS()
TRACING() ARGS()
Truth table0%0/3
A or B
A= TRACING()B= ARGS()
ABresult
1X1
011
000
34 0 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
35 0 require Data::Dumper;
36 0 $Data::Dumper::Purity = 1;
37 0 $Data::Dumper::Indent = 1;
38 0 ▶ print Data::Dumper::Dumper(\@_) if ARGS;
Branch: 1 branch
BranchTrueFalseTotal
if ARGS() 0 0 0
39 }
40 }
41  
42 8 my %vfs; # virtual file system
43 my %mfs; # marker-to-virtual-file mapping
44 8 my %afs; # actual file system
45  
46 8 my (%read, %write, %append, %preserve);
47 8 @read{qw( < +> +< )} = ();
48 8 @write{qw( > +> +< >> )} = ();
49 8 @append{qw( >> )} = ();
50 8 @preserve{qw( >> +< < )} = ();
51  
52 0 ▶sub not_input { "Virtual file not open for input\n" }
Subroutine not_input: not called CC=1 SCAR=6.9
Pod undocumented
53 0 ▶sub not_output { "Virtual file not open for output\n" }
Subroutine not_output: not called CC=1 SCAR=6.9
Pod undocumented
54  
55 sub import {
56 8 ▶ DEBUG && TRACE(@_);
Subroutine import: called CC=2 SCAR=6.9
57 8 my $caller = caller;
58 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
59 96 *{"${caller}::$_"} = \&$_
60 8 for (qw( vf_load vf_save vf_marker vf_prefix
61 vf_open vf_close vf_seek vf_tell vf_truncate vf_write
62 DEBUG TRACE
63 ));
64 8 1;
65 }
66  
67 sub vf_load {
68 8 ▶ DEBUG && TRACE(@_);
Subroutine vf_load: called CC=5 SCAR=16.2
Pod documented
69 8 my ($file, $header) = @_;
70 8 my $path = './';
71 8 $file =~ s|\\|/|g;
72 8 ▶ ($path, $file) = ($1, $2) if $file =~ m|^(.*)/(.*)$|;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ m[^(.*)/(.*)$] 8 0 8
73 8 $file = abs_path($path) . "/$file";
74 8 ▶ return @{$afs{$file}{vfiles}} if $afs{$file};
Branch: 1 branch
BranchTrueFalseTotal
if $afs{$file} 0 8 8
75 8 local ($/, *FILE);
76 8 ▶ open FILE, $file or croak "Could not vf_load '$file'";
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $file or croak("Could not vf_load '${file}'") 0 8 8
77 8 my @vdata = split /(?m)($header)/, <FILE>;
78 8 my ($offset,$linecount) = (0,1);
79 8 unshift @vdata, "";
80 8 my ($marker, $data, $vfiles);
81 8 ▶ while (($marker, $data) = splice @vdata,0,2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@vdata, 0, 2)) 20 8 28
82 20 my $vfile = sprintf "$file(%-0.20d)",$offset;
83 20 $vfs{$vfile} =
84 { data => $data,
85 marker => $marker,
86 offset => $offset,
87 line => $linecount,
88 };
89 20 $offset += length($marker) + length($data);
90 20 $linecount += linecount($marker, $data);
91 20 push @$vfiles, $vfile;
92 20 push @{$mfs{$marker}}, $vfile;
93 }
94 8 $afs{$file}{vfiles} = $vfiles;
95 8 return @{$vfiles}[1..$#$vfiles];
96 }
97  
98 8 my $new_counter = 0;
99 sub vf_open (*;$$$) {
100 42 ▶ DEBUG && TRACE(@_);
Subroutine vf_open: called CC=28 SCAR=33.6
Pod undocumented
101 42 my $glob = shift;
102 42 my $file = shift;
103 42 my $symbol = shift;
104  
105 42 my $mode;
106 42 ▶ if ($file && $file =~ /^(?:\|-|-\||>|<|>>|>:.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file and $file =~ /^(?:\|-|-\||>|<|>>|>:.*)$/) 10 32 42
Condition100%3/3
$file and $file =~ /^(?:\|-|-\||>|<|>>|>:.*)$/
!ll&&!rl&&r
23010
MC/DC100%2/2
$file and $file =~ /^(?:\|-|-\||>|<|>>|>:.*)$/
$file $file =~ /^(?:\|-|-\||>|<|>>|>:.*)$/
Truth table100%3/3
A and B
A= $fileB= $file =~ /^(?:\|-|-\||>|<|>>|>:.*)$/
ABresult
0X0
100
111
107 10 $mode = $file;
108 10 $file = $symbol;
109 10 $symbol = shift;
110 }
111  
112 8 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 42 ▶ if (defined $glob) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $glob) { } 34 8 42
114 34 ▶ $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $glob or $glob =~ /::/ 29 5 34
Condition66%2/3
ref $glob or $glob =~ /::/
l!l&&r!l&&!r
0529
MC/DC50%1/2
ref $glob or $glob =~ /::/
ref $glob $glob =~ /::/
Truth table66%2/3
A or B
A= ref $globB= $glob =~ /::/
ABresult
1X1
011
000
115 # The following line somehow manages to cause failure on threaded perls.
116 # The good news is that everything works just fine without it.
117 # $glob = \*{$glob};
118 }
119 else {
120 # autovivify for: open $fh, $filename
121 8 $glob = $_[0] = \do{local *ANON};
122 }
123  
124 42 ▶ if (!$mode) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mode) 32 10 42
125 # Resolve file
126 32 ▶ $file ||= "";
Condition100%2/2
$file ||= ""
l!l
302
MC/DC100%1/1
$file ||= ""
$file
Truth table100%2/2
A
A= $file
Aresult
11
00
127 32 $file =~ s/^([^\w\s\/]*)\s*//i;
128 32 ▶ $mode = $1 || "";
Condition100%2/2
$1 || ''
l!l
1715
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
129  
130 32 ▶ if (!$mode && $file =~ s/\s*\|\s*$//) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $mode and $file =~ s/\s*\|\s*$//) 1 31 32
Condition100%3/3
not $mode and $file =~ s/\s*\|\s*$//
!ll&&!rl&&r
17141
MC/DC100%2/2
not $mode and $file =~ s/\s*\|\s*$//
not $mode $file =~ s/\s*\|\s*$//
Truth table100%3/3
not(A) and B
A= not $modeB= $file =~ s/\s*\|\s*$//
ABresult
0X0
100
111
131 1 ▶ $mode = $mode || "-|";
Condition50%1/2
$mode || '-|'
l!l
01
MC/DC0%0/1
$mode || '-|'
$mode
Truth table50%1/2
A
A= $mode
Aresult
11
00
132 }
133 }
134 42 ▶ unless ($file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file) 7 35 42
135 7 my $scalar = *{$glob}{SCALAR};
136 7 ▶ $file = $scalar ? $$scalar : "";
Branch: 1 branch
BranchTrueFalseTotal
$scalar ? : 7 0 7
137 7 $file =~ s/^([^a-z\s\/]*)\s*//i;
138 7 ▶ $mode = $mode || $1 || "<";
Condition80%4/5
$mode || $1 || '<'
l!l
52
$mode or $1
l!l&&r!l&&!r
502
MC/DC50%1/2
$mode || $1 || '<'
$mode $1
Truth table66%2/3
A or B
A= $modeB= $1
ABresult
1X1
011
000
139 }
140 42 ▶ $mode ||= "<";
Condition100%2/2
$mode ||= "<"
l!l
3012
MC/DC100%1/1
$mode ||= "<"
$mode
Truth table100%2/2
A
A= $mode
Aresult
11
00
141 42 ▶ $file = $mfs{$file}[0] if $file and exists $mfs{$file};
Branch: 1 branch
BranchTrueFalseTotal
if $file and exists $mfs{$file} 0 42 42
Condition66%2/3
$file and exists $mfs{$file}
!ll&&!rl&&r
2400
MC/DC0%0/2
$file and exists $mfs{$file}
$file exists $mfs{$file}
Truth table66%2/3
A and B
A= $fileB= exists $mfs{$file}
ABresult
0X0
100
111
142  
143 # Create a new Inline file (for Inline::Files only)
144 42 ▶ if (not $file and defined $Inline::Files::{get_filename}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $file and defined $Inline::Files::{"get_filename"}) 2 40 42
Condition66%2/3
not $file and defined $Inline::Files::{"get_filename"}
!ll&&!rl&&r
4002
MC/DC50%1/2
not $file and defined $Inline::Files::{"get_filename"}
not $file defined $Inline::Files::{"get_filename"}
Truth table66%2/3
not(A) and B
A= not $fileB= defined $Inline::Files::{"get_filename"}
ABresult
0X0
100
111
145 2 (my $marker = *{$glob}{NAME}) =~ s|.*::(.*)|$1|;
146 2 ▶ if ($marker =~ /^[A-Z](?:_*[A-Z0-9]+)*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($marker =~ /^[A-Z](?:_*[A-Z0-9]+)*$/) 2 0 2
147 2 ▶ if ($file = Inline::Files::get_filename((caller)[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file = Inline::Files::get_filename((caller)[0])) 2 0 2
148 2 $marker = "__${marker}__\n";
149 2 my $vfile = sprintf "$file(NEW%-0.8d)", ++$new_counter;
150 2 $vfs{$vfile} =
151 { data => '',
152 marker => $marker,
153 offset => -1,
154 line => -1,
155 };
156 2 push @{$mfs{$marker}}, $vfile;
157 2 push @{$afs{$file}{vfiles}}, $vfile;
158 2 $file = $vfile;
159 }
160 }
161 }
162  
163 42 ▶ $! = 2, return 0 unless $file; # Can't work at this point; confuses core
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 42 42
164 # Default to CORE::open
165 42 ▶ unless (exists $vfs{$file}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $vfs{$file}) 30 12 42
166 30 return CORE::open($glob, $mode, $file);
167 }
168  
169 12 ▶ my $afile = $file =~ /^(.*)[(](NEW)?\d+[)]$/ ? $1 :
Branch: 1 branch
BranchTrueFalseTotal
$file =~ /^(.*)[(](NEW)?\d+[)]$/ ? : 12 0 12
170 croak "Internal error\n";
171  
172 # If file is virtual, tie it up, and set it up
173 12 my $impl = tie (*$glob, 'Inline::Files::Virtual',
174 $file, $afile, $mode, $symbol);
175  
176 12 $afs{$afile}{changed} = 0;
177 $impl->TRUNCATE() if (exists $write{$mode}
178 12 ▶ and not exists $preserve{$mode});
Branch: 1 branch
BranchTrueFalseTotal
if exists $write{$mode} and not exists $preserve{$mode} 5 7 12
Condition100%3/3
exists $write{$mode} and not exists $preserve{$mode}
!ll&&!rl&&r
525
MC/DC100%2/2
exists $write{$mode} and not exists $preserve{$mode}
exists $write{$mode} not exists $preserve{$mode}
Truth table100%3/3
A and not(B)
A= exists $write{$mode}B= not exists $preserve{$mode}
ABresult
0X0
100
111
179 12 return 1;
180 }
181  
182 sub linecount {
183 20 ▶ DEBUG && TRACE();
Subroutine linecount: called CC=2 SCAR=6.9
Pod undocumented
184 20 my $sum = 0;
185 20 foreach (@_) { $sum += tr/\n// }
186 20 return $sum;
187 }
188  
189 sub vf_save {
190 14 ▶ DEBUG && TRACE(@_);
Subroutine vf_save: called CC=10 SCAR=24.5
Pod documented
191 14 my @files = @_;
192 14 ▶ @files = keys %afs unless @files;
Branch: 1 branch
BranchTrueFalseTotal
unless @files 14 0 14
193 14 for my $file (@files) {
194 14 ▶ next unless $afs{$file}{changed};
Branch: 1 branch
BranchTrueFalseTotal
unless $afs{$file}{"changed"} 10 4 14
195 4 $afs{$file}{changed}=0;
196 4 local *FILE;
197 open FILE, ">$file"
198 7 and print FILE map { my $entry = $vfs{$_};
199 7 ▶ if (length $entry->{data}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $entry->{"data"}) 7 0 7
200 7 chomp $entry->{data};
201 7 $entry->{data} .= "\n";
202 }
203 7 "$entry->{marker}$entry->{data}";
204 4 ▶ } @{$afs{$file}{vfiles}}
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$file" and print FILE map({my $entry = $vfs{$_}; if (length $entry->{"data"}) { chomp $entry->{"data"}; $entry->{"data"} .= "\n"; } ; qq[$entry->{"marker"}$entry->{"data"}];} @{$afs{$file}{"vfiles"};}) and close FILE or $^W and warn "Could not vf_save '${file}'\n$!" and return 0 0 3 3
Condition53%7/13
open(FILE, ">$file") && print(FILE map({my $entry = $vfs{$_}; if (length $entry->{'data'}) { chomp $entry->{'data'}; $entry->{'data'} .= "\n"; } ; "$entry->{'marker'}$entry->{'data'}";} @{$afs{$file}{'vfiles'};})) && close FILE || $^W && warn("Could not vf_save '${file}'\n$!") && (return 0)
l!l&&r!l&&!r
300
open FILE, ">$file" and print FILE map({my $entry = $vfs{$_}; if (length $entry->{"data"}) { chomp $entry->{"data"}; $entry->{"data"} .= "\n"; } ; qq[$entry->{"marker"}$entry->{"data"}];} @{$afs{$file}{"vfiles"};}) and close FILE
!ll&&!rl&&r
103
open FILE, ">$file" and print FILE map({my $entry = $vfs{$_}; if (length $entry->{"data"}) { chomp $entry->{"data"}; $entry->{"data"} .= "\n"; } ; qq[$entry->{"marker"}$entry->{"data"}];} @{$afs{$file}{"vfiles"};})
!ll&&!rl&&r
103
$^W and warn "Could not vf_save '${file}'\n$!" and return 0
!ll
10
$^W and warn "Could not vf_save '${file}'\n$!"
!ll
10
MC/DC0%0/4
open(FILE, ">$file") && print(FILE map({my $entry = $vfs{$_}; if (length $entry->{'data'}) { chomp $entry->{'data'}; $entry->{'data'} .= "\n"; } ; "$entry->{'marker'}$entry->{'data'}";} @{$afs{$file}{'vfiles'};})) && close FILE || $^W && warn("Could not vf_save '${file}'\n$!") && (return 0)
open FILE, ">$file" print FILE map({my $entry = $vfs{$_}; if (length $entry->{"data"}) { chomp $entry->{"data"}; $entry->{"data"} .= "\n"; } ; qq[$entry->{"marker"}$entry->{"data"}];} @{$afs{$file}{"vfiles"};}) close FILE $^W
Truth table14%1/7
A and B and C || D
A= open FILE, ">$file"B= print FILE map({my $entry = $vfs{$_}; if (length $entry->{"data"}) { chomp $entry->{"data"}; $entry->{"data"} .= "\n"; } ; qq[$entry->{"marker"}$entry->{"data"}];} @{$afs{$file}{"vfiles"};})C= close FILED= $^W
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
205 and close FILE
206 or ($^W and warn "Could not vf_save '$file'\n$!")
207 and return 0;
208 }
209 14 return 1;
210 }
211  
212 END {
213 8 ▶ DEBUG && TRACE(@_);
Subroutine END: called CC=1 SCAR=0.0
214 8 vf_save;
215 }
216  
217 sub vf_marker ($) {
218 12 ▶ DEBUG && TRACE(@_);
Subroutine vf_marker: called CC=1 SCAR=0.0
Pod documented
219 12 my ($virtual_filename) = @_;
220 12 return $vfs{$virtual_filename}{marker};
221 }
222  
223 sub vf_prefix ($) {
224 8 ▶ DEBUG && TRACE(@_);
Subroutine vf_prefix: called CC=1 SCAR=0.0
Pod undocumented
225 8 my ($actual_filename) = @_;
226 8 return $vfs{$afs{$actual_filename}{vfiles}[0]}{data};
227 }
228  
229 sub vf_close (*) {
230 28 ▶ DEBUG && TRACE(@_);
Subroutine vf_close: called CC=4 SCAR=13.9
Pod undocumented
231 28 my ($glob) = @_;
232 8 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
233 28 ▶ $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $glob or $glob =~ /::/ 23 5 28
Condition66%2/3
ref $glob or $glob =~ /::/
l!l&&r!l&&!r
5023
MC/DC50%1/2
ref $glob or $glob =~ /::/
ref $glob $glob =~ /::/
Truth table66%2/3
A or B
A= ref $globB= $glob =~ /::/
ABresult
1X1
011
000
234 28 my $impl = tied(*$glob);
235 28 ▶ return CORE::close $glob unless $impl;
Branch: 1 branch
BranchTrueFalseTotal
unless $impl 22 6 28
236 6 return vf_save();
237 }
238  
239 sub vf_seek (*$$) {
240 11 ▶ DEBUG && TRACE(@_);
Subroutine vf_seek: called CC=4 SCAR=14.5
Pod undocumented
241 11 my ($glob, $pos, $whence) = @_;
242 8 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
243 11 ▶ $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $glob or $glob =~ /::/ 11 0 11
Condition33%1/3
ref $glob or $glob =~ /::/
l!l&&r!l&&!r
0011
MC/DC0%0/2
ref $glob or $glob =~ /::/
ref $glob $glob =~ /::/
Truth table33%1/3
A or B
A= ref $globB= $glob =~ /::/
ABresult
1X1
011
000
244 11 my $impl = tied(*$glob);
245 11 ▶ return seek $glob, $pos, $whence unless $impl;
Branch: 1 branch
BranchTrueFalseTotal
unless $impl 0 11 11
246 11 return $impl->SEEK($pos, $whence);
247 }
248  
249 sub vf_tell (*) {
250 0 ▶ DEBUG && TRACE(@_);
Subroutine vf_tell: not called CC=4 SCAR=25.3
Pod undocumented
251 0 my ($glob) = @_;
252 8 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
253 0 ▶ $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $glob or $glob =~ /::/ 0 0 0
Condition0%0/3
ref $glob or $glob =~ /::/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $glob or $glob =~ /::/
ref $glob $glob =~ /::/
Truth table0%0/3
A or B
A= ref $globB= $glob =~ /::/
ABresult
1X1
011
000
254 0 my $impl = tied(*$glob);
255 0 ▶ return tell $glob unless $impl;
Branch: 1 branch
BranchTrueFalseTotal
unless $impl 0 0 0
256 0 return $impl->TELL();
257 }
258  
259 sub vf_truncate (*$) {
260 0 ▶ DEBUG && TRACE(@_);
Subroutine vf_truncate: not called CC=4 SCAR=25.3
Pod undocumented
261 0 my ($glob, $length) = @_;
262 8 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
263 0 ▶ $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $glob or $glob =~ /::/ 0 0 0
Condition0%0/3
ref $glob or $glob =~ /::/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $glob or $glob =~ /::/
ref $glob $glob =~ /::/
Truth table0%0/3
A or B
A= ref $globB= $glob =~ /::/
ABresult
1X1
011
000
264 0 my $impl = tied(*$glob);
265 0 ▶ return truncate $glob, $length unless $impl;
Branch: 1 branch
BranchTrueFalseTotal
unless $impl 0 0 0
266 0 return $impl->TRUNCATE($length);
267 }
268  
269  
270 sub vf_write (*) {
271 0 ▶ DEBUG && TRACE(@_);
Subroutine vf_write: not called CC=4 SCAR=25.3
Pod undocumented
272 0 my ($glob) = @_;
273 8 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
274 0 ▶ $glob = caller() . "::$glob" unless ref($glob) || $glob =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $glob or $glob =~ /::/ 0 0 0
Condition0%0/3
ref $glob or $glob =~ /::/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $glob or $glob =~ /::/
ref $glob $glob =~ /::/
Truth table0%0/3
A or B
A= ref $globB= $glob =~ /::/
ABresult
1X1
011
000
275 0 my $impl = tied(*$glob);
276 0 ▶ return write $glob unless $impl;
Branch: 1 branch
BranchTrueFalseTotal
unless $impl 0 0 0
277 0 return $impl->WRITE();
278 }
279  
280 sub TIEHANDLE {
281 12 ▶ DEBUG && TRACE(@_);
Subroutine TIEHANDLE: called CC=3 SCAR=11.4
282 12 my ($class, $vfile, $afile, $mode, $symbol) = @_;
283 12 ▶ my $vfs_entry = $vfs{$vfile} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $vfs_entry = $vfs{$vfile} or return 0 12 12
284 bless { vfile => $vfs_entry,
285 12 ▶ pos => exists $append{$mode} ? length $vfs_entry->{data} : 0,
Branch: 1 branch
BranchTrueFalseTotal
exists $append{$mode} ? : 0 12 12
286 mode => $mode,
287 symbol => $symbol,
288 afile => $afile,
289 }, $class;
290 }
291  
292 sub STORE {
293 0 ▶ DEBUG && TRACE(@_);
Subroutine STORE: not called CC=1 SCAR=6.9
294 }
295  
296 sub PRINT {
297 6 ▶ DEBUG && TRACE(@_);
Subroutine PRINT: called CC=3 SCAR=11.4
298 6 my($impl,@args) = @_;
299 6 ▶ $^W && warn(not_output), return 1 unless exists $write{$impl->{mode}};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $write{$impl->{"mode"}} 0 6 6
Condition0%0/2
$^W and warn not_output()
!ll
00
MC/DC0%0/1
$^W and warn not_output()
$^W
Truth table0%0/2
A
A= $^W
Aresult
00
11
300 6 my $text = join '', @args;
301 6 substr($impl->{vfile}{data},$impl->{pos},-1) = $text;
302 6 $impl->{pos} += length $text;
303 6 $afs{$impl->{afile}}{changed} = 1;
304 6 return 1;
305 }
306  
307 sub PRINTF {
308 0 ▶ DEBUG && TRACE(@_);
Subroutine PRINTF: not called CC=3 SCAR=24.8
309 0 my($impl,$format,@args) = @_;
310 0 ▶ $^W && warn(not_output), return 1 unless exists $write{$impl->{mode}};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $write{$impl->{"mode"}} 0 0 0
Condition0%0/2
$^W and warn not_output()
!ll
00
MC/DC0%0/1
$^W and warn not_output()
$^W
Truth table0%0/2
A
A= $^W
Aresult
00
11
311 0 my $text = sprintf($format,@args);
312 0 substr($impl->{vfile}{data},$impl->{pos},-1) = $text;
313 0 $impl->{pos} += length $text;
314 0 $afs{$impl->{afile}}{changed} = 1;
315 0 return 1;
316 }
317  
318 8 ▶use vars '$AUTOLOAD';
Subroutine BEGIN: called CC=1 SCAR=0.0
319 sub AUTOLOAD {
320 0 ▶ DEBUG && TRACE(@_);
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
321 0 my $impl = shift;
322 0 croak "$AUTOLOAD not yet implemented";
323 }
324  
325 sub DESTROY {
326 4 ▶ DEBUG && TRACE(@_);
Subroutine DESTROY: called CC=1 SCAR=0.0
327 }
328  
329 # Inline::Files support
330 sub _magic_handle {
331 5 ▶ DEBUG && TRACE(@_);
Subroutine _magic_handle: called CC=3 SCAR=11.0
332 5 my ($impl) = @_;
333 5 ▶ return unless $INC{'Inline/Files.pm'} && $impl->{symbol};
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"Inline/Files.pm"} and $impl->{"symbol"} 1 4 5
Condition66%2/3
$INC{"Inline/Files.pm"} and $impl->{"symbol"}
!ll&&!rl&&r
014
MC/DC50%1/2
$INC{"Inline/Files.pm"} and $impl->{"symbol"}
$INC{"Inline/Files.pm"} $impl->{"symbol"}
Truth table66%2/3
A and B
A= $INC{"Inline/Files.pm"}B= $impl->{"symbol"}
ABresult
0X0
100
111
334 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
335 4 return tie *{$impl->{symbol}}, 'Inline::Files', $impl->{symbol};
336 }
337  
338 sub READ {
339 0 ▶ DEBUG && TRACE(@_);
Subroutine READ: not called CC=7 SCAR=40.3
340 0 my($impl,$buffer,$length,$offset) = @_;
341 0 ▶ $^W && warn(not_input), return unless exists $read{$impl->{mode}};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $read{$impl->{"mode"}} 0 0 0
Condition0%0/2
$^W and warn not_input()
!ll
00
MC/DC0%0/1
$^W and warn not_input()
$^W
Truth table0%0/2
A
A= $^W
Aresult
00
11
342 0 ▶ $offset = $impl->{pos} unless defined $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 0 0
343 0 my $remainder = length($impl->{vfile}{data})-$impl->{pos};
344 0 ▶ $length = $remainder if $remainder < $length;
Branch: 1 branch
BranchTrueFalseTotal
if $remainder < $length 0 0 0
345 0 $_[1] = substr($impl->{vfile}{data},$offset,$length);
346 0 $impl->{pos} += $length;
347 0 ▶ if ($length>=0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($length >= 0) { } 0 0 0
elsif ($impl = _magic_handle($impl)) { } 0 0 0
348 0 return $length
349 }
350 elsif ($impl = _magic_handle($impl)) {
351 0 return $impl->READ($buffer,$length,$offset);
352 }
353 else {
354 0 return;
355 }
356 }
357  
358 sub READLINE {
359 17 ▶ DEBUG && TRACE(@_);
Subroutine READLINE: called CC=13 SCAR=26.0
360 17 my ($impl) = @_;
361 17 ▶ $^W && warn(not_input), return unless exists $read{$impl->{mode}};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $read{$impl->{"mode"}} 0 17 17
Condition0%0/2
$^W and warn not_input()
!ll
00
MC/DC0%0/1
$^W and warn not_input()
$^W
Truth table0%0/2
A
A= $^W
Aresult
00
11
362 17 ▶ my $match = !defined($/) ? '.*'
Branch: 2 branches
BranchTrueFalseTotal
!defined($/) ? : 1 16 17
length $/ ? : 16 0 16
363 : length $/ ? ".*?\Q$/\E|.*"
364 : '.*?\n{2,}';
365 17 my (@lines);
366 17 ▶ my $list_context ||= wantarray;
Condition66%2/3
my $list_context ||= wantarray
l!l&&r!l&&!r
0116
MC/DC50%1/2
my $list_context ||= wantarray
my $list_context wantarray
Truth table66%2/3
A ||= B
A= my $list_contextB= wantarray
ABresult
1X1
011
000
367 17 while (1) {
368 22 ▶ if ($impl->{pos} < length $impl->{vfile}{data} and
Branch: 1 branch
BranchTrueFalseTotal
if ($impl->{'pos'} < length $impl->{'vfile'}{'data'} and $impl->{'vfile'}{'data'} =~ /\A(.{$impl->{'pos'}})($match)/s) { } 17 5 22
Condition66%2/3
$impl->{"pos"} < length $impl->{"vfile"}{"data"} and $impl->{"vfile"}{"data"} =~ /\A(.{$impl->{"pos"}})($match)/s
!ll&&!rl&&r
5017
MC/DC50%1/2
$impl->{"pos"} < length $impl->{"vfile"}{"data"} and $impl->{"vfile"}{"data"} =~ /\A(.{$impl->{"pos"}})($match)/s
$impl->{"pos"} < length $impl->{"vfile"}{"data"} $impl->{"vfile"}{"data"} =~ /\A(.{$impl->{"pos"}})($match)/s
Truth table66%2/3
A and B
A= $impl->{"pos"} < length $impl->{"vfile"}{"data"}B= $impl->{"vfile"}{"data"} =~ /\A(.{$impl->{"pos"}})($match)/s
ABresult
0X0
100
111
369 $impl->{vfile}{data} =~ m{\A(.{$impl->{pos}})($match)}s) {
370 17 $impl->{pos} += length($2);
371 17 push @lines, $2;
372 }
373 else {
374 5 ▶ last unless $impl = _magic_handle($impl);
Branch: 1 branch
BranchTrueFalseTotal
unless $impl = _magic_handle($impl) 1 4 5
375 4 ▶ last unless $impl = $impl->MAGIC;
Branch: 1 branch
BranchTrueFalseTotal
unless $impl = $impl->MAGIC 1 3 4
376 3 next;
377 }
378 17 ▶ last unless $list_context;
Branch: 1 branch
BranchTrueFalseTotal
unless $list_context 15 2 17
379 }
380 17 ▶ return $list_context ? (@lines) :
Branch: 2 branches
BranchTrueFalseTotal
$list_context ? : 1 16 17
@lines ? : 15 1 16
381 @lines ? $lines[0] : undef;
382 }
383  
384 sub MAGIC {
385 3 ▶ DEBUG && TRACE(@_);
Subroutine MAGIC: called CC=1 SCAR=0.0
Pod undocumented
386 3 $_[0];
387 }
388  
389 sub GETC {
390 0 ▶ DEBUG && TRACE(@_);
Subroutine GETC: not called CC=5 SCAR=34.0
391 0 my ($impl) = @_;
392 0 ▶ $^W && warn(not_input), return unless exists $read{$impl->{mode}};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $read{$impl->{"mode"}} 0 0 0
Condition0%0/2
$^W and warn not_input()
!ll
00
MC/DC0%0/1
$^W and warn not_input()
$^W
Truth table0%0/2
A
A= $^W
Aresult
00
11
393 0 my $char = substr($impl->{vfile}{data},$impl->{pos},1);
394 0 $impl->{pos}++;
395 0 ▶ return $char if length $char;
Branch: 1 branch
BranchTrueFalseTotal
if length $char 0 0 0
396 0 ▶ return unless $impl = _magic_handle($impl);
Branch: 1 branch
BranchTrueFalseTotal
unless $impl = _magic_handle($impl) 0 0 0
397 0 return $impl->GETC();
398 }
399  
400 sub TELL {
401 0 ▶ DEBUG && TRACE(@_);
Subroutine TELL: not called CC=1 SCAR=6.9
402 0 my ($impl) = @_;
403 0 return $impl->{pos};
404 }
405  
406 sub SEEK {
407 11 ▶ DEBUG && TRACE(@_);
Subroutine SEEK: called CC=6 SCAR=17.9
408 11 my ($impl, $position, $whence) = @_;
409 11 my $length = length $impl->{vfile}{data};
410 11 my $pos = $impl->{pos};
411 $pos = ( $whence==0 ? $position :
412 $whence==1 ? $position + $impl->{pos} :
413 11 ▶ $whence==2 ? $position + $length :
Branch: 3 branches
BranchTrueFalseTotal
$whence == 0 ? : 3 8 11
$whence == 1 ? : 6 2 8
$whence == 2 ? : 2 0 2
414 return
415 );
416 11 ▶ return if $pos < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 3 8 11
417 8 ▶ $pos = $length if $pos >= $length;
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= $length 1 7 8
418 8 $impl->{pos} = $pos;
419 8 return 1;
420 }
421  
422 sub TRUNCATE {
423 5 ▶ DEBUG && TRACE(@_);
Subroutine TRUNCATE: called CC=3 SCAR=11.2
Pod undocumented
424 5 my ($impl, $length) = @_;
425 5 ▶ $length ||= 0;
Condition50%1/2
$length ||= 0
l!l
05
MC/DC0%0/1
$length ||= 0
$length
Truth table50%1/2
A
A= $length
Aresult
11
00
426 5 substr($impl->{vfile}{data},$length,-1) = "";
427 5 ▶ $impl->{pos} = $length if $length < $impl->{pos};
Branch: 1 branch
BranchTrueFalseTotal
if $length < $impl->{"pos"} 0 5 5
428 5 $afs{$impl->{afile}}{changed} = 1;
429 5 return 1;
430 }
431  
432 8 1;
433  
434 __END__
↑ Summary Files.pm »