| 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
Condition100%3/3
$self->{'started'}++ || @ARGV
MC/DC100%2/2
$self->{'started'}++ || @ARGV
$self->{'started'}++
@ARGV
Truth table100%3/3
A || B
A= $self->{'started'}++B= @ARGV
| |||||||||||||||||||||||||||||
| 21 | 61 | ▶ | while (defined(my $file = @stdin ? shift @stdin : shift @ARGV)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 22 | 50 | ▶ | if (my $fh = IO::Factotum::open_input($file)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 35 | 65 | my $line = readline $fh; | |||||||||||||||||||||||||||
| 36 | 65 | ▶ | if (defined $line) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 50 | 4 | my @lines; | |||||||||||||||||||||||||||
| 51 | 4 | ▶ | while (defined(my $line = $self->_readline)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition50%1/2
$how // 0
MC/DC0%0/1
$how // 0
$how
Truth table50%1/2
A
A= $how
| |||||||||||||||||||||||||||||
| 63 | 13 | while (1) { | |||||||||||||||||||||||||||
| 64 | 17 | ▶ | return '' if $self->{fh} and not eof $self->{fh}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"fh"} and not eof $self->{"fh"}
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"}
| |||||||||||||||||||||||||||||
| 65 | 9 | ▶ | $self->_next or return 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | not $self->{fh} or eof $self->{fh}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 30 | 1; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||