| 1 | |||||||||||||||||||||||||||||||||||||||||||||||
| 2 | package Biblio::SICI; | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | $Biblio::SICI::VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||||||
| 5 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # ABSTRACT: Provides methods for assembling, parsing, manipulating and serialising SICIs | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Sub::Quote; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Biblio::SICI::ItemSegment; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Biblio::SICI::ContributionSegment; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Biblio::SICI::ControlSegment; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Biblio::SICI::Util qw( calculate_check_char ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | has 'item' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | isa => quote_sub(q{ die unless ( defined $_[0] and $_[0]->isa('Biblio::SICI::ItemSegment') ) }), | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | builder => | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | quote_sub(q{ my ($self) = @_; return Biblio::SICI::ItemSegment->new( _sici => $self ); }), | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | has 'contribution' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | isa => quote_sub( | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | q{ die unless ( defined $_[0] and $_[0]->isa('Biblio::SICI::ContributionSegment') ) }), | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | builder => quote_sub( | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | q{ my ($self) = @_; return Biblio::SICI::ContributionSegment->new( _sici => $self ); }), | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | has 'control' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | isa => quote_sub( | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | q{ my ($val) = @_; die unless ( defined $val and $val->isa('Biblio::SICI::ControlSegment') ) } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | builder => quote_sub( | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | q{ my ($self) = @_; return Biblio::SICI::ControlSegment->new( _sici => $self ); }), | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | has 'mode' => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | isa => quote_sub(q{ my ($val) = @_; die unless ( $val eq 'strict' or $val eq 'lax' ) }), | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | ▶ | coerce => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | my ($val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | $val = join( '', split( " ", lc($val) ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | return $val if ( $val eq 'strict' or $val eq 'lax' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$val eq "strict" or $val eq "lax"
MC/DC0%0/2
$val eq "strict" or $val eq "lax"
$val eq "strict"
$val eq "lax"
Truth table33%1/3
A or B
A= $val eq "strict"B= $val eq "lax"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | return 'lax'; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | default => quote_sub(q{ "lax" }), | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | has 'parsedString' => ( is => 'rwp', init_arg => undef, ); | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 58 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=70 SCAR=60.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 58 | my ( $self, $string ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 58 | ▶ | my $strictMode = $self->mode() eq 'strict' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 58 | ▶ | if ( defined $string ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 58 | $string =~ s/\r/ /go; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 58 | $string =~ s/\n/ /go; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 58 | $string = join( '', split( " ", $string ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 58 | ▶ | unless ($string) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $strictMode ? die 'no string to parse' : return ( undef, undef, ['no string to parse'] ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 58 | $self->_set_parsedString($string); | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 58 | my $checkChar = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 58 | ▶ | if ( $string =~ /;([0-9])(?:-.)?\Z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 58 | ▶ | if ( "$1" ne "2" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | $strictMode | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ? die 'unsupported SICI version' | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | : return ( undef, undef, ['unsupported SICI version'] ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 58 | $self->control()->version(2); | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 58 | ▶ | if ( $string =~ s/;2-(.)\Z// ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 58 | $checkChar = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 58 | my $parserProblems = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 58 | my @chars = split( //, $string ); | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 58 | my $tmp = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 58 | ▶ | while ( exists( $chars[0] ) and $chars[0] !~ /[(<]/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $chars[0] and not $chars[0] =~ /[(<]/
MC/DC50%1/2
exists $chars[0] and not $chars[0] =~ /[(<]/
exists $chars[0]
not $chars[0] =~ /[(<]/
Truth table66%2/3
A and not(B)
A= exists $chars[0]B= not $chars[0] =~ /[(<]/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 522 | $tmp .= shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 58 | ▶ | if ( $tmp and exists( $chars[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$tmp and exists $chars[0]
MC/DC0%0/2
$tmp and exists $chars[0]
$tmp
exists $chars[0]
Truth table33%1/3
A and B
A= $tmpB= exists $chars[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 58 | ▶ | if ( $chars[0] eq '(' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # warn 'ISSN candidate: ' . $tmp; | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 58 | $self->item()->issn($tmp); | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 58 | shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | elsif ( $chars[0] eq '<' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | push @{$parserProblems}, "item information missing"; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # warn 'Missing item info'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # warn 'Enumeration candidate: ' . $tmp; | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ( $tmp =~ /\A([A-Z0-9\/]+):([A-Z0-9\/]+)(?::([+*]))?\Z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $self->item()->volume($1); | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $self->item()->issue($2); | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | $self->item()->supplOrIdx($3) if $3; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | elsif ($tmp) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $self->item()->enumeration($tmp); | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | goto CONTRIB; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | $strictMode ? die 'unparsable string' : return ( undef, undef, ['unparsable string'] ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } ## end if ( $tmp and exists( ...)) | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | $strictMode ? die 'unparsable string' : return ( undef, undef, ['unparsable string'] ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 58 | $tmp = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 58 | ▶ | while ( exists( $chars[0] ) and $chars[0] ne ')' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $chars[0] and $chars[0] ne ")"
MC/DC50%1/2
exists $chars[0] and $chars[0] ne ")"
exists $chars[0]
$chars[0] ne ")"
Truth table66%2/3
A and B
A= exists $chars[0]B= $chars[0] ne ")"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 379 | $tmp .= shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 58 | ▶ | if ( $tmp and exists( $chars[0] ) and $chars[0] eq ')' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
$tmp and exists $chars[0] and $chars[0] eq ")"
$tmp and exists $chars[0]
MC/DC33%1/3
$tmp and exists $chars[0] and $chars[0] eq ")"
$tmp
exists $chars[0]
$chars[0] eq ")"
Truth table50%2/4
A and B and C
A= $tmpB= exists $chars[0]C= $chars[0] eq ")"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # warn 'Chronology candidate: ' . $tmp; | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 57 | $self->item()->chronology($tmp); | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 57 | shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | ▶ | elsif ( exists( $chars[0] ) and $chars[0] eq ')' ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
exists $chars[0] and $chars[0] eq ")"
MC/DC0%0/2
exists $chars[0] and $chars[0] eq ")"
exists $chars[0]
$chars[0] eq ")"
Truth table33%1/3
A and B
A= exists $chars[0]B= $chars[0] eq ")"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | $strictMode ? die 'unparsable string' : return ( undef, undef, ['unparsable string'] ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 58 | $tmp = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 58 | ▶ | while ( exists( $chars[0] ) and $chars[0] ne '<' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $chars[0] and $chars[0] ne "<"
MC/DC50%1/2
exists $chars[0] and $chars[0] ne "<"
exists $chars[0]
$chars[0] ne "<"
Truth table66%2/3
A and B
A= exists $chars[0]B= $chars[0] ne "<"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 218 | $tmp .= shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 58 | ▶ | if ( $tmp and exists( $chars[0] ) and $chars[0] eq '<' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
$tmp and exists $chars[0] and $chars[0] eq "<"
$tmp and exists $chars[0]
MC/DC33%1/3
$tmp and exists $chars[0] and $chars[0] eq "<"
$tmp
exists $chars[0]
$chars[0] eq "<"
Truth table50%2/4
A and B and C
A= $tmpB= exists $chars[0]C= $chars[0] eq "<"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # warn 'Enumeration candidate: ' . $tmp; | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 55 | ▶ | if ( $tmp =~ /\A([A-Z0-9\/]+):([A-Z0-9\/]+)(?::([+*]))?\Z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 39 | $self->item()->volume($1); | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 39 | $self->item()->issue($2); | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 39 | ▶ | $self->item()->supplOrIdx($3) if $3; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | elsif ($tmp) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 16 | $self->item()->enumeration($tmp); | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 55 | shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | ▶ | elsif ( exists( $chars[0] ) and $chars[0] eq '<' ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
exists $chars[0] and $chars[0] eq "<"
MC/DC0%0/2
exists $chars[0] and $chars[0] eq "<"
exists $chars[0]
$chars[0] eq "<"
Truth table33%1/3
A and B
A= exists $chars[0]B= $chars[0] eq "<"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | $strictMode ? die 'unparsable string' : return ( undef, undef, ['unparsable string'] ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 58 | CONTRIB: | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | $tmp = ''; | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 58 | ▶ | while ( exists( $chars[0] ) and $chars[0] ne '>' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $chars[0] and $chars[0] ne ">"
MC/DC50%1/2
exists $chars[0] and $chars[0] ne ">"
exists $chars[0]
$chars[0] ne ">"
Truth table66%2/3
A and B
A= exists $chars[0]B= $chars[0] ne ">"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 278 | $tmp .= shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 58 | ▶ | if ( $tmp and exists( $chars[0] ) and $chars[0] eq '>' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
$tmp and exists $chars[0] and $chars[0] eq ">"
$tmp and exists $chars[0]
MC/DC33%1/3
$tmp and exists $chars[0] and $chars[0] eq ">"
$tmp
exists $chars[0]
$chars[0] eq ">"
Truth table50%2/4
A and B and C
A= $tmpB= exists $chars[0]C= $chars[0] eq ">"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # warn 'Contribution candidate: ' . $tmp; | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 28 | ▶ | if ( $tmp =~ /\A::(.+)\Z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 2 | $self->contribution()->localNumber($1); | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | elsif ( $tmp =~ /\A:([^:]+)(?::(.+))?\Z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | $self->contribution()->titleCode($1); | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | $self->contribution()->localNumber($2) if $2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | elsif ( $tmp =~ /\A([^:]+):([^:]+)(?::(.+))?\Z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 25 | $self->contribution()->location($1); | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | 25 | $self->contribution()->titleCode($2); | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | 25 | ▶ | $self->contribution()->localNumber($3) if $3; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $self->contribution()->location($tmp); | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 28 | shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | ▶ | elsif ( exists( $chars[0] ) and $chars[0] eq '>' ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
exists $chars[0] and $chars[0] eq ">"
MC/DC0%0/2
exists $chars[0] and $chars[0] eq ">"
exists $chars[0]
$chars[0] eq ">"
Truth table33%1/3
A and B
A= exists $chars[0]B= $chars[0] eq ">"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 30 | shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | $strictMode ? die 'unparsable string' : return ( undef, undef, ['unparsable string'] ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 58 | my $csi = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | 58 | ▶ | if ( exists( $chars[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 58 | $csi = shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 58 | ▶ | if ( exists( $chars[0] ) and $chars[0] eq '.' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
exists $chars[0] and $chars[0] eq "."
MC/DC0%0/2
exists $chars[0] and $chars[0] eq "."
exists $chars[0]
$chars[0] eq "."
Truth table33%1/3
A and B
A= exists $chars[0]B= $chars[0] eq "."
| |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 58 | shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | elsif ( exists( $chars[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | shift(@chars) while ( $chars[0] ne '.' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 58 | ▶ | if ( exists( $chars[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 58 | $self->control()->dpi( shift @chars ); | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 58 | ▶ | if ( exists( $chars[0] ) and $chars[0] eq '.' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
exists $chars[0] and $chars[0] eq "."
MC/DC0%0/2
exists $chars[0] and $chars[0] eq "."
exists $chars[0]
$chars[0] eq "."
Truth table33%1/3
A and B
A= exists $chars[0]B= $chars[0] eq "."
| |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 58 | shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | elsif ( exists( $chars[0] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | shift(@chars) while ( $chars[0] ne '.' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 58 | ▶ | if ( exists( $chars[0] ) and exists( $chars[1] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $chars[0] and exists $chars[1]
MC/DC0%0/2
exists $chars[0] and exists $chars[1]
exists $chars[0]
exists $chars[1]
Truth table33%1/3
A and B
A= exists $chars[0]B= exists $chars[1]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 58 | $self->control()->mfi( join( '', splice( @chars, 0, 2 ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 58 | my $isValid = $self->is_valid(); | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | 58 | ▶ | if ( $strictMode && !$isValid ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$strictMode and not $isValid
MC/DC0%0/2
$strictMode and not $isValid
$strictMode
not $isValid
Truth table33%1/3
A and not(B)
A= $strictModeB= not $isValid
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | die 'parsing failed: invalid SICI'; | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 58 | ▶ | if ( $checkChar ne $self->checkchar() ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | push @{$parserProblems}, "wrong check char; was '$checkChar', should have been '$1'"; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 58 | ▶ | if ( $checkChar !~ /\A[0-9A-Z#]\Z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | push @{$parserProblems}, 'invalid original check char'; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 58 | ▶ | if ( $self->control()->csi() ne $csi ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | push @{$parserProblems}, 'wrong csi in string input'; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 58 | ▶ | my $roundTrip = ( $self->parsedString() eq $self->to_string() ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 58 | return ( $isValid, $roundTrip, $parserProblems ); | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | } ## end sub parse | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 121 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 121 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 121 | my $str = $self->_to_string(); | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | 121 | my $cs = calculate_check_char($str); | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 121 | return $str . $cs; | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 179 | ▶ | sub _to_string { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 179 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 179 | my $item = $self->item()->to_string(); | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | 179 | my $contrib = $self->contribution()->to_string(); | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | 179 | my $control = $self->control()->to_string(); | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 179 | return sprintf( '%s<%s>%s-', $item, $contrib, $control ); | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 58 | ▶ | sub checkchar { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkchar: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 58 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 58 | my $siciAsString = $self->_to_string(); | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 58 | return calculate_check_char($siciAsString); | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 58 | ▶ | sub reset { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 58 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | 58 | $self->item()->reset(); | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 58 | $self->contribution()->reset(); | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | 58 | $self->control()->reset(); | |||||||||||||||||||||||||||||||||||||||||||||
| 297 | 58 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 58 | ▶ | sub is_valid { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=4 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 58 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 58 | my $itemIsValid = $self->item()->is_valid(); | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | 58 | my $contribIsValid = $self->contribution()->is_valid(); | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | 58 | my $controlIsValid = $self->control()->is_valid(); | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 58 | ▶ | if ( $itemIsValid && $contribIsValid && $controlIsValid ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$itemIsValid and $contribIsValid and $controlIsValid
$itemIsValid and $contribIsValid
MC/DC0%0/3
$itemIsValid and $contribIsValid and $controlIsValid
$itemIsValid
$contribIsValid
$controlIsValid
Truth table25%1/4
A and B and C
A= $itemIsValidB= $contribIsValidC= $controlIsValid
| |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 58 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 63 | ▶ | sub list_problems { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_problems: called CC=5 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 63 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 63 | my $hasProblems = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | 63 | my %problems = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | 63 | ▶ | if ( not $self->item()->is_valid() ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $hasProblems++; | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $problems{'item'} = { $self->item()->list_problems() }; | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 63 | ▶ | if ( not $self->contribution()->is_valid() ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $hasProblems++; | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $problems{'contribution'} = { $self->contribution()->list_problems() }; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 63 | ▶ | if ( not $self->control()->is_valid() ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $hasProblems++; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $problems{'control'} = { $self->control()->list_problems() }; | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 63 | ▶ | if ($hasProblems) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | return %problems; | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 63 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||