lib/IO/Factotum/ARGV.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 85.7% 24 / 28 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 90.1% 82 / 91 CC 18 SCAR 16.3
CC
18
Cov
91%
EOF
8.5
_next
6.0
_readline
4.0
CRAP 5.1
« blib/lib/Getopt/EX/Factotum.pm ↑ Summary blib/lib/IO/Factotum/Highlight/gnu.pm »
1 package IO::Factotum::ARGV;
2  
3 30 ▶use v5.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 30 require IO::Factotum;
7  
8 30 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
9 30 my $class = shift;
10 30 bless { fh => undef, nr => 0, started => 0 }, $class;
11 }
12  
13 # Open the next file of @ARGV, which is looked at here for the first
14 # time, after the program has taken its options. As with the plain
15 # <>, the standard input is read when there is no file, the name goes
16 # to $ARGV, and a file which can not be opened is skipped.
17 61 ▶sub _next {
Subroutine _next: called CC=6 SCAR=17.9
18 61 my $self = shift;
19 61 $self->{fh} = undef;
20 61 ▶ my @stdin = !$self->{started}++ && !@ARGV ? ('-') : ();
Branch: 1 branch
BranchTrueFalseTotal
!($self->{'started'}++ || @ARGV) ? : 2 59 61
Condition100%3/3
$self->{'started'}++ || @ARGV
l!l&&r!l&&!r
32272
MC/DC100%2/2
$self->{'started'}++ || @ARGV
$self->{'started'}++ @ARGV
Truth table100%3/3
A || B
A= $self->{'started'}++B= @ARGV
ABresult
1X1
011
000
21 61 ▶ while (defined(my $file = @stdin ? shift @stdin : shift @ARGV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $file = @stdin ? shift @stdin : shift @ARGV)) 50 13 63
@stdin ? : 2 61 63
22 50 ▶ if (my $fh = IO::Factotum::open_input($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = IO::Factotum::open_input($file)) 30 2 32
23 30 $main::ARGV = $file;
24 30 return $self->{fh} = $fh;
25 }
26 2 warn "Can't open $file: $!\n";
27 }
28 13 undef;
29 }
30  
31 73 ▶sub _readline {
Subroutine _readline: called CC=4 SCAR=13.9
32 73 my $self = shift;
33 73 while (1) {
34 99 ▶ if (my $fh = $self->{fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = $self->{"fh"}) 65 34 99
35 65 my $line = readline $fh;
36 65 ▶ if (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 47 18 65
37 # $. is that of the handle just read: the lines of the
38 # files are counted on, as the plain <> does
39 47 $. = ++$self->{nr};
40 47 return $line;
41 }
42 }
43 52 ▶ $self->_next or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_next or return undef 26 11 37
44 }
45 }
46  
47 66 ▶sub READLINE {
Subroutine READLINE: called CC=3 SCAR=11.0
48 66 my $self = shift;
49 66 ▶ return $self->_readline unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 62 4 66
50 4 my @lines;
51 4 ▶ while (defined(my $line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->_readline)) 7 2 9
52 7 push @lines, $line;
53 }
54 2 @lines;
55 }
56  
57 # eof() with empty parentheses (2) is the end of the last file, and it
58 # goes on to the next file to see it. The others are the end of the
59 # file being read.
60 13 ▶sub EOF {
Subroutine EOF: called CC=7 SCAR=21.5
61 13 my($self, $how) = @_;
62 13 ▶ if (($how // 0) == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (($how // 0) == 2) 13 0 13
Condition50%1/2
$how // 0
l!l
130
MC/DC0%0/1
$how // 0
$how
Truth table50%1/2
A
A= $how
Aresult
11
00
63 13 while (1) {
64 17 ▶ return '' if $self->{fh} and not eof $self->{fh};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"fh"} and not eof $self->{"fh"} 8 9 17
Condition66%2/3
$self->{"fh"} and not eof $self->{"fh"}
!ll&&!rl&&r
098
MC/DC50%1/2
$self->{"fh"} and not eof $self->{"fh"}
$self->{"fh"} not eof $self->{"fh"}
Truth table66%2/3
A and not(B)
A= $self->{"fh"}B= not eof $self->{"fh"}
ABresult
0X0
100
111
65 9 ▶ $self->_next or return 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->_next or return 1 4 2 6
66 }
67 }
68 0 ▶ not $self->{fh} or eof $self->{fh};
Branch: 1 branch
BranchTrueFalseTotal
not $self->{"fh"} or eof $self->{"fh"} 0 0 0
69 }
70  
71 # close ARGV starts the line numbers again
72 3 ▶sub CLOSE {
Subroutine CLOSE: called CC=2 SCAR=7.0
73 3 my $self = shift;
74 3 my $fh = delete $self->{fh};
75 3 $self->{nr} = 0;
76 3 ▶ $fh ? close $fh : 1;
Branch: 1 branch
BranchTrueFalseTotal
$fh ? : 3 0 3
77 }
78  
79 30 1;
80  
81 __END__
« blib/lib/Getopt/EX/Factotum.pm ↑ Summary blib/lib/IO/Factotum/Highlight/gnu.pm »