| 1 | package MARC::Spec::Structure; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use Const::Fast; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | our $VERSION = '0.1.4'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | const my $NO_LENGTH => -1; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | const my $LAST => '#'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | has base => ( | |||||||||||||||||||||||||||||||||||||||||
| 14 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | builder => '_base' | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | sub _base { | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 122 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_base: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 122 | ▶ | my $base = ($self->can('tag')) ? $self->tag : '$'.$self->code; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 122 | $base .= '['.$self->index_start; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 122 | ▶ | if($self->index_start ne $self->index_end) { $base .= '-'.$self->index_end } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 122 | $base .= ']'; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 122 | ▶ | if(defined $self->char_start) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 34 | my $char_start = $self->char_start; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 34 | my $char_end = $self->char_end; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 34 | ▶ | unless($char_start eq '0' && $char_end eq '#') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$char_start eq 0 and $char_end eq "#"
MC/DC100%2/2
$char_start eq 0 and $char_end eq "#"
$char_start eq 0
$char_end eq "#"
Truth table100%3/3
A and B
A= $char_start eq 0B= $char_end eq "#"
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 32 | $base .= '/'.$char_start; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 32 | ▶ | if($char_end ne $char_start) { $base .= '-'.$char_end } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 122 | ▶ | if($self->can('indicator1')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 81 | ▶ | my $indicators = (defined $self->indicator1) ? $self->indicator1 : '_'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 81 | ▶ | $indicators .= (defined $self->indicator2) ? $self->indicator2 : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 81 | ▶ | if($indicators ne '_') { $base .= '_'.$indicators } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 122 | return $base; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | has index_start => ( | ||||||||||||||||||||||||||||||||||||||||||
| 47 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 97 | ▶ | default => sub {0}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | trigger => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 17 | ▶ | my ($self, $index_start) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 17 | ▶ | if ($LAST ne $self->index_end && $LAST ne $index_start && $self->index_end < $index_start) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$LAST ne $self->index_end and $LAST ne $index_start and $self->index_end < $index_start
$LAST ne $self->index_end and $LAST ne $index_start
MC/DC33%1/3
$LAST ne $self->index_end and $LAST ne $index_start and $self->index_end < $index_start
$LAST ne $self->index_end
$LAST ne $index_start
$self->index_end < $index_start
Truth table50%2/4
A and B and C
A= $LAST ne $self->index_endB= $LAST ne $index_startC= $self->index_end < $index_start
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | $self->index_end($index_start); | |||||||||||||||||||||||||||||||||||||||||
| 53 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 16 | $self->_set_base( $self->_base() ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 17 | $self->_set_index_length( _calculate_length($index_start, $self->index_end) ) | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 13 | ); | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | has index_end => ( | ||||||||||||||||||||||||||||||||||||||||||
| 61 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 97 | ▶ | default => sub {$LAST}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | trigger => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 19 | ▶ | my ($self, $index_end) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 19 | ▶ | if ($LAST ne $self->index_start && $LAST ne $index_end && $self->index_start > $index_end) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$LAST ne $self->index_start and $LAST ne $index_end and $self->index_start > $index_end
$LAST ne $self->index_start and $LAST ne $index_end
MC/DC0%0/3
$LAST ne $self->index_start and $LAST ne $index_end and $self->index_start > $index_end
$LAST ne $self->index_start
$LAST ne $index_end
$self->index_start > $index_end
Truth table75%3/4
A and B and C
A= $LAST ne $self->index_startB= $LAST ne $index_endC= $self->index_start > $index_end
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->index_start($index_end); | |||||||||||||||||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 19 | $self->_set_base( $self->_base() ); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 19 | $self->_set_index_length( _calculate_length($self->index_start, $index_end) ) | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 13 | ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | has index_length => ( | ||||||||||||||||||||||||||||||||||||||||||
| 75 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 97 | ▶ | default => sub {$NO_LENGTH} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 13 | ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | has char_start => ( | ||||||||||||||||||||||||||||||||||||||||||
| 80 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | trigger => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 11 | ▶ | my ($self, $char_start) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 11 | ▶ | if(!defined $self->char_end) { $self->char_end($char_start) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 11 | $self->_set_char_pos($self->char_start.'-'.$self->char_end); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 11 | $self->_set_char_length( _calculate_length($char_start, $self->char_end) ); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 11 | $self->_set_base( $self->_base() ) | |||||||||||||||||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 13 | predicate => 1 | |||||||||||||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | has char_end => ( | ||||||||||||||||||||||||||||||||||||||||||
| 92 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 93 | trigger => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 22 | ▶ | my ($self, $char_end) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 22 | ▶ | if(!defined $self->char_start) { $self->char_start($char_end) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 22 | $self->_set_char_pos($self->char_start.'-'.$self->char_end); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 22 | $self->_set_char_length( _calculate_length($self->char_start, $char_end) ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 21 | $self->_set_base( $self->_base() ) | |||||||||||||||||||||||||||||||||||||||||
| 99 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 13 | predicate => 1 | |||||||||||||||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 13 | has char_pos => ( | |||||||||||||||||||||||||||||||||||||||||
| 104 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||
| 105 | predicate => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | has char_length => ( | ||||||||||||||||||||||||||||||||||||||||||
| 109 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||
| 110 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 111 | builder => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_char_length: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return _calculate_length($self->char_start, $self->char_end) | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 13 | ); | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | has subspecs => ( | ||||||||||||||||||||||||||||||||||||||||||
| 118 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||
| 119 | isa => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 67 | ▶ | foreach my $and (@{$_[0]}) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 104 | ▶ | if(ref $and eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 59 | foreach my $or (@{$and}) { | |||||||||||||||||||||||||||||||||||||||||
| 123 | 118 | ▶ | croak('Subspec is not an instance of MARC::Spec::Subspec.') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | if(ref $or ne 'MARC::Spec::Subspec') | ||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 45 | ▶ | croak('Subspec is not an instance of MARC::Spec::Subspec.') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | if(ref $and ne 'MARC::Spec::Subspec') | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 13 | predicate => 1 | |||||||||||||||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | sub set_index_start_end { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 13 | ▶ | my ($self, $indizes) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_index_start_end: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 13 | my @pos = _validate_pos($indizes); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 13 | $self->index_start($pos[0]); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 13 | ▶ | defined $pos[1] ? $self->index_end($pos[1]) : $self->index_end($pos[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | sub set_char_start_end { | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 9 | ▶ | my ($self, $charpos) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_char_start_end: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 9 | my @pos = _validate_pos($charpos); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 9 | $self->char_start($pos[0]); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 9 | ▶ | defined $pos[1] ? $self->char_end($pos[1]) : $self->char_end($pos[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | sub add_subspec { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 34 | ▶ | my ($self, $subspec) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_subspec: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 34 | ▶ | if(!$self->has_subspecs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | $self->_set_subspecs([$subspec]); | |||||||||||||||||||||||||||||||||||||||||
| 153 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 28 | my @subspecs = ( @{$self->subspecs}, $subspec ); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 28 | $self->_set_subspecs( \@subspecs ) | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | sub add_subspecs { | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 33 | ▶ | my ($self, $subspecs) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_subspecs: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 33 | ▶ | if (ref $subspecs ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | croak('Subspecs is not an ARRAYRef!') | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 33 | ▶ | if(!$self->has_subspecs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 29 | $self->_set_subspecs($subspecs) | |||||||||||||||||||||||||||||||||||||||||
| 166 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | my @merged = @{$self->subspecs}; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | push @merged, @{$subspecs}; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | $self->_set_subspecs( \@merged ) | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | sub to_string { | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 21 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 21 | my $string = $self->base; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 21 | ▶ | if($self->has_subspecs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | my @outer = (); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | foreach my $ss (@{$self->subspecs}) { | |||||||||||||||||||||||||||||||||||||||||
| 179 | 3 | ▶ | if(ref $ss eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | my $inner = join '|', map {$_->to_string()} @{$ss}; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | push @outer, $inner; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | push @outer, $ss->to_string(); | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | my $joined = join '}{', @outer; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | $string .= '{'. $joined .'}'; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 21 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | sub _calculate_length { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 69 | ▶ | my ($start, $end) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_calculate_length: called CC=7 SCAR=20.0
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | # start eq end | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 69 | ▶ | if ($start eq $end) { return 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | # start = #, end != # | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 38 | ▶ | if($LAST eq $start && $LAST ne $end) { return $end + 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$LAST eq $start and $LAST ne $end
MC/DC0%0/2
$LAST eq $start and $LAST ne $end
$LAST eq $start
$LAST ne $end
Truth table33%1/3
A and B
A= $LAST eq $startB= $LAST ne $end
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | # start != #, end = # | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 38 | ▶ | if($LAST ne $start && $LAST eq $end) { return $NO_LENGTH } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$LAST ne $start and $LAST eq $end
MC/DC50%1/2
$LAST ne $start and $LAST eq $end
$LAST ne $start
$LAST eq $end
Truth table66%2/3
A and B
A= $LAST ne $startB= $LAST eq $end
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 9 | my $length = $end - $start + 1; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 9 | ▶ | if(1 > $length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | _throw("Ending character or index position must be equal or higher than starting character or index position.", "$start-$end"); | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 8 | return $length; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | sub _validate_pos { | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 22 | ▶ | my ($charpos) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_pos: called CC=5 SCAR=17.6
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 22 | ▶ | if($charpos =~ /[^0-9\-#]/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | _throw("Assuming index or character position or range. Only digits, the character '#' and one '-' is allowed.", $charpos); | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | # something like 123- is not valid | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 22 | ▶ | if('-' eq substr $charpos, -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | _throw("Assuming index or character range. At least two digits or the character '#' must be present." ,$charpos); | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | # something like -123 is not valid | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 22 | ▶ | if('-' eq substr $charpos, 0, 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | _throw("Assuming index or character position or range. First character must not be '-'.", $charpos); | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 22 | my @pos = split /\-/, $charpos, 2; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | # set end pos to start pos if no end pos | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 22 | ▶ | if(!defined $pos[1]) { push (@pos, $pos[0]) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 22 | return @pos; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | sub _throw { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | ▶ | my ($message, $hint) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_throw: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | croak 'MARCspec Parser exception. '.$message.' Tried to parse: '.$hint; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 243 | __END__ | ||||||||||||||||||||||||||||||||||||||||||