| 1 | # ABSTRACT: Reader class for YAML::PP representing input data | ||||||||||||||||||||
| 2 | 52 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 52 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | package YAML::PP::Reader; | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 52 | our $VERSION = 'v0.41.1'; # TRIAL VERSION | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 3 | ▶ | sub input { return $_[0]->{input} } | ||||||||||||||||||
|
Subroutine
input: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 9 | 0 | ▶ | sub set_input { $_[0]->{input} = $_[1] } | ||||||||||||||||||
|
Subroutine
set_input: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 12457 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 12 | 12457 | my ($class, %args) = @_; | |||||||||||||||||||
| 13 | 12457 | my $input = delete $args{input}; | |||||||||||||||||||
| 14 | 12457 | return bless { | |||||||||||||||||||
| 15 | input => $input, | ||||||||||||||||||||
| 16 | }, $class; | ||||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | ▶ | sub read { | ||||||||||||||||||
|
Subroutine
read: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 20 | 1 | my ($self) = @_; | |||||||||||||||||||
| 21 | 1 | ▶ | my $pos = pos $self->{input} || 0; | ||||||||||||||||||
|
Condition50%1/2
pos $self->{'input'} || 0
MC/DC0%0/1
pos $self->{'input'} || 0
pos $self->{'input'}
Truth table50%1/2
A
A= pos $self->{'input'}
| |||||||||||||||||||||
| 22 | 1 | my $yaml = substr($self->{input}, $pos); | |||||||||||||||||||
| 23 | 1 | $self->{input} = ''; | |||||||||||||||||||
| 24 | 1 | return $yaml; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 40445 | ▶ | sub readline { | ||||||||||||||||||
|
Subroutine
readline: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 28 | 40445 | my ($self) = @_; | |||||||||||||||||||
| 29 | 40445 | ▶ | unless (length $self->{input}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 4450 | return; | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | 35995 | ▶ | if ( $self->{input} =~ m/\G([^\r\n]*(?:\n|\r\n|\r|\z))/g ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 35995 | my $line = $1; | |||||||||||||||||||
| 34 | 35995 | ▶ | unless (length $line) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | 7458 | $self->{input} = ''; | |||||||||||||||||||
| 36 | 7458 | return; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | 28537 | return $line; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | 0 | return; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | package YAML::PP::Reader::File; | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 52 | ▶ | use Scalar::Util qw/ openhandle /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 52 | our @ISA = qw/ YAML::PP::Reader /; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 52 | ▶ | use Carp qw/ croak /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 28 | ▶ | sub open_handle { | ||||||||||||||||||
|
Subroutine
open_handle: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 52 | 28 | ▶ | if (openhandle( $_[0]->{input} )) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 1 | return $_[0]->{input}; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | open my $fh, '<:encoding(UTF-8)', $_[0]->{input} | ||||||||||||||||||||
| 56 | 27 | ▶ | or croak "Could not open '$_[0]->{input}' for reading: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 27 | return $fh; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | ▶ | sub read { | ||||||||||||||||||
|
Subroutine
read: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 61 | 0 | ▶ | my $fh = $_[0]->{filehandle} ||= $_[0]->open_handle; | ||||||||||||||||||
|
Condition0%0/3
$_[0]{"filehandle"} ||= $_[0]->open_handle
MC/DC0%0/2
$_[0]{"filehandle"} ||= $_[0]->open_handle
$_[0]{"filehandle"}
$_[0]->open_handle
Truth table0%0/3
A ||= B
A= $_[0]{"filehandle"}B= $_[0]->open_handle
| |||||||||||||||||||||
| 62 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 0 | my @yaml = <$fh>; | |||||||||||||||||||
| 64 | 0 | return @yaml; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||
| 67 | 0 | local $/; | |||||||||||||||||||
| 68 | 0 | my $yaml = <$fh>; | |||||||||||||||||||
| 69 | 0 | return $yaml; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 10613 | ▶ | sub readline { | ||||||||||||||||||
|
Subroutine
readline: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 74 | 10613 | ▶ | my $fh = $_[0]->{filehandle} ||= $_[0]->open_handle; | ||||||||||||||||||
|
Condition66%2/3
$_[0]{"filehandle"} ||= $_[0]->open_handle
MC/DC0%0/2
$_[0]{"filehandle"} ||= $_[0]->open_handle
$_[0]{"filehandle"}
$_[0]->open_handle
Truth table66%2/3
A ||= B
A= $_[0]{"filehandle"}B= $_[0]->open_handle
| |||||||||||||||||||||
| 75 | 10613 | return scalar <$fh>; | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 52 | 1; | |||||||||||||||||||