| 1 | package MARC::Lint; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use integer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use MARC::Record; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use MARC::Field; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use MARC::Lint::CodeData qw(%GeogAreaCodes %ObsoleteGeogAreaCodes %LanguageCodes %ObsoleteLanguageCodes); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | our $VERSION = 1.53; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | MARC::Lint - Perl extension for checking validity of MARC records | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | use MARC::File::USMARC; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | use MARC::Lint; | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | my $lint = new MARC::Lint; | ||||||||||||||||||||||||||||||||||||||||||
| 23 | my $filename = shift; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | my $file = MARC::File::USMARC->in( $filename ); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | while ( my $marc = $file->next() ) { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | $lint->check_record( $marc ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | # Print the title tag | ||||||||||||||||||||||||||||||||||||||||||
| 30 | print $marc->title, "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # Print the errors that were found | ||||||||||||||||||||||||||||||||||||||||||
| 33 | print join( "\n", $lint->warnings ), "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | } # while | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | Given the following MARC record: | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | LDR 00000nam 22002538a 4500 | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 040 _aMdSSJTT | ||||||||||||||||||||||||||||||||||||||||||
| 40 | _cMdSSJTT | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 040 _aMdSSJTT | ||||||||||||||||||||||||||||||||||||||||||
| 42 | _beng | ||||||||||||||||||||||||||||||||||||||||||
| 43 | _cMdSSJTT | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 100 14 _aWall, Larry. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 110 1 _aO'Reilly & Associates. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 245 90 _aProgramming Perl / | ||||||||||||||||||||||||||||||||||||||||||
| 47 | _aBig Book of Perl / | ||||||||||||||||||||||||||||||||||||||||||
| 48 | _cLarry Wall, Tom Christiansen & Jon Orwant. | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 250 _a3rd ed. | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 250 _a3rd ed. | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 260 _aCambridge, Mass. : | ||||||||||||||||||||||||||||||||||||||||||
| 52 | _bO'Reilly, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | _r2000. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 590 4 _aPersonally signed by Larry. | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 856 43 _uhttp://www.perl.com/ | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | the following errors are generated: | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 1XX: Only one 1XX tag is allowed, but I found 2 of them. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 100: Indicator 2 must be blank but it's "4" | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 245: Indicator 1 must be 0 or 1 but it's "9" | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 245: Subfield _a is not repeatable. | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 040: Field is not repeatable. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 260: Subfield _r is not allowed. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 856: Indicator 2 must be blank, 0, 1, 2 or 8 but it's "3" | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | Module for checking validity of MARC records. 99% of the users will want to do | ||||||||||||||||||||||||||||||||||||||||||
| 70 | something like is shown in the synopsis. The other intrepid 1% will overload the | ||||||||||||||||||||||||||||||||||||||||||
| 71 | C<MARC::Lint> module's methods and provide their own special field-level checking. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | What this means is that if you have certain requirements, such as making sure that | ||||||||||||||||||||||||||||||||||||||||||
| 74 | all 952 tags have a certain call number in them, you can write a function that | ||||||||||||||||||||||||||||||||||||||||||
| 75 | checks for that, and still get all the benefits of the MARC::Lint framework. | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | =head1 EXPORT | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | None. Everything is done through objects. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | =head2 new() | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | No parms needed. The C<MARC::Lint> object is little more than a list of warnings | ||||||||||||||||||||||||||||||||||||||||||
| 86 | and a bunch of rules. | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 6 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 6 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 94 | _warnings => [], | ||||||||||||||||||||||||||||||||||||||||||
| 95 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 6 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 6 | $self->_read_rules(); | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | =head2 warnings() | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | Returns a list of warnings found by C<check_record()> and its brethren. | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 64 | ▶ | sub warnings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warnings: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 64 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | return wantarray ? @{$self->{_warnings}} : scalar @{$self->{_warnings}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | =head2 clear_warnings() | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | Clear the list of warnings for this linter object. It's automatically called | ||||||||||||||||||||||||||||||||||||||||||
| 118 | when you call C<check_record()>. | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 64 | ▶ | sub clear_warnings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_warnings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 64 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 64 | $self->{_warnings} = []; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | =head2 warn( $str [, $str...] ) | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | Create a warning message, built from strings passed, like a C<print> | ||||||||||||||||||||||||||||||||||||||||||
| 131 | statement. | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | Typically, you'll leave this to C<check_record()>, but industrious | ||||||||||||||||||||||||||||||||||||||||||
| 134 | programmers may want to do their own checking as well. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 59 | ▶ | sub warn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warn: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 59 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 59 | push( @{$self->{_warnings}}, join( "", @_ ) ); | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 59 | return; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | =head2 check_record( $marc ) | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | Does all sorts of lint-like checks on the MARC record I<$marc>, | ||||||||||||||||||||||||||||||||||||||||||
| 149 | both on the record as a whole, and on the individual fields & | ||||||||||||||||||||||||||||||||||||||||||
| 150 | subfields. | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 13 | ▶ | sub check_record { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_record: called CC=28 SCAR=34.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 13 | my $marc = shift; | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 13 | $self->clear_warnings(); | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 13 | ▶ | ( (ref $marc) && $marc->isa('MARC::Record') ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $marc and $marc->isa("MARC::Record")
MC/DC0%0/2
ref $marc and $marc->isa("MARC::Record")
ref $marc
$marc->isa("MARC::Record")
Truth table33%1/3
A and B
A= ref $marcB= $marc->isa("MARC::Record")
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | or return $self->warn( "Must pass a MARC::Record object to check_record" ); | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 13 | my @_1xx = $marc->field( "1.." ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 13 | my $n1xx = scalar @_1xx; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 13 | ▶ | if ( $n1xx > 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | $self->warn( "1XX: Only one 1XX tag is allowed, but I found $n1xx of them." ); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 13 | ▶ | if ( not $marc->field( 245 ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $self->warn( "245: No 245 tag." ); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 13 | my %field_seen; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 13 | my $rules = $self->{_rules}; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 13 | for my $field ( $marc->fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 177 | 208 | my $tagno = $field->tag; | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 208 | my $tagrules = ''; | |||||||||||||||||||||||||||||||||||||||||
| 180 | #if 880 field, inherit rules from tagno in subfield _6 | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 208 | my $is_880 = 0; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 208 | ▶ | if ($tagno eq '880') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 3 | $is_880 = 1; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | ▶ | if ($field->subfield('6')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | my $sub6 = $field->subfield('6'); | |||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | $tagno = substr($sub6, 0, 3); | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | ▶ | $tagrules = $rules->{$tagno} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | #880 is repeatable, but its linked field may not be | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | ▶ | if ( ($tagrules->{'repeatable'} && ( $tagrules->{'repeatable'} eq 'NR' )) && $field_seen{'880.'.$tagno} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$tagrules->{"repeatable"} and $tagrules->{"repeatable"} eq "NR" and $field_seen{'880.' . $tagno}
$tagrules->{"repeatable"} and $tagrules->{"repeatable"} eq "NR"
MC/DC0%0/3
$tagrules->{"repeatable"} and $tagrules->{"repeatable"} eq "NR" and $field_seen{'880.' . $tagno}
$tagrules->{"repeatable"}
$tagrules->{"repeatable"} eq "NR"
$field_seen{'880.' . $tagno}
Truth table50%2/4
A and B and C
A= $tagrules->{"repeatable"}B= $tagrules->{"repeatable"} eq "NR"C= $field_seen{'880.' . $tagno}
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $self->warn( "$tagno: Field is not repeatable." ); | |||||||||||||||||||||||||||||||||||||||||
| 192 | } #if repeatability | ||||||||||||||||||||||||||||||||||||||||||
| 193 | } #if subfield 6 present | ||||||||||||||||||||||||||||||||||||||||||
| 194 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | $self->warn( "880: No subfield 6." ); | |||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } #else no subfield 6 in 880 field | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } #if this is 880 field | ||||||||||||||||||||||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 205 | ▶ | $tagrules = $rules->{$tagno} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 204 | ▶ | if ( ($tagrules->{'repeatable'} && ( $tagrules->{'repeatable'} eq 'NR' )) && $field_seen{$tagno} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$tagrules->{"repeatable"} and $tagrules->{"repeatable"} eq "NR" and $field_seen{$tagno}
$tagrules->{"repeatable"} and $tagrules->{"repeatable"} eq "NR"
MC/DC0%0/3
$tagrules->{"repeatable"} and $tagrules->{"repeatable"} eq "NR" and $field_seen{$tagno}
$tagrules->{"repeatable"}
$tagrules->{"repeatable"} eq "NR"
$field_seen{$tagno}
Truth table50%2/4
A and B and C
A= $tagrules->{"repeatable"}B= $tagrules->{"repeatable"} eq "NR"C= $field_seen{$tagno}
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $self->warn( "$tagno: Field is not repeatable." ); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } #if repeatability | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } #else not 880 | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 206 | ▶ | if ( $tagno >= 10 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 159 | for my $ind ( 1..2 ) { | |||||||||||||||||||||||||||||||||||||||||
| 209 | 318 | my $indvalue = $field->indicator($ind); | |||||||||||||||||||||||||||||||||||||||||
| 210 | 318 | ▶ | if ( not ($indvalue =~ $tagrules->{"ind$ind" . "_regex"}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | $self->warn( | ||||||||||||||||||||||||||||||||||||||||||
| 212 | "$tagno: Indicator $ind must be ", | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 5 | $tagrules->{"ind$ind" . "_desc"}, | |||||||||||||||||||||||||||||||||||||||||
| 214 | " but it's \"$indvalue\"" | ||||||||||||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | } # for | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 159 | my %sub_seen; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 159 | for my $subfield ( $field->subfields ) { | |||||||||||||||||||||||||||||||||||||||||
| 221 | 264 | my ($code,$data) = @$subfield; | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 264 | my $rule = $tagrules->{$code}; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 264 | ▶ | if ( not defined $rule ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 3 | $self->warn( "$tagno: Subfield _$code is not allowed." ); | |||||||||||||||||||||||||||||||||||||||||
| 226 | ▶ | } elsif ( ($rule eq "NR") && $sub_seen{$code} ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$rule eq "NR" and $sub_seen{$code}
MC/DC100%2/2
$rule eq "NR" and $sub_seen{$code}
$rule eq "NR"
$sub_seen{$code}
Truth table100%3/3
A and B
A= $rule eq "NR"B= $sub_seen{$code}
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | $self->warn( "$tagno: Subfield _$code is not repeatable." ); | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 264 | ▶ | if ( $data =~ /[\t\r\n]/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $self->warn( "$tagno: Subfield _$code has an invalid control character" ); | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 264 | ++$sub_seen{$code}; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } # for $subfields | ||||||||||||||||||||||||||||||||||||||||||
| 236 | } # if $tagno >= 10 | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | elsif ($tagno < 10) { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | #check for subfield characters | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 47 | ▶ | if ($field->data() =~ /\x1F/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | $self->warn( "$tagno: Subfields are not allowed in fields lower than 010" ); | |||||||||||||||||||||||||||||||||||||||||
| 242 | } #if control field has subfield delimiter | ||||||||||||||||||||||||||||||||||||||||||
| 243 | } #elsif $tagno < 10 | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # Check to see if a check_xxx() function exists, and call it on the field if it does | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 206 | my $checker = "check_$tagno"; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 206 | ▶ | if ( $self->can( $checker ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 25 | $self->$checker( $field ); | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 206 | ▶ | if ($is_880) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | ++$field_seen{'880.'.$tagno}; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } #if 880 field | ||||||||||||||||||||||||||||||||||||||||||
| 254 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 204 | ++$field_seen{$tagno}; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | } # for my $fields | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | =head2 check_I<xxx>( $field ) | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | Various functions to check the different fields. If the function doesn't exist, | ||||||||||||||||||||||||||||||||||||||||||
| 265 | then it doesn't get checked. | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | =head2 check_020() | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | Looks at 020$a and reports errors if the check digit is wrong. | ||||||||||||||||||||||||||||||||||||||||||
| 270 | Looks at 020$z and validates number if hyphens are present. | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | Uses Business::ISBN to do validation. Thirteen digit checking is currently done | ||||||||||||||||||||||||||||||||||||||||||
| 273 | with the internal sub _isbn13_check_digit(), based on code from Business::ISBN. | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | TO DO (check_020): | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | Fix 13-digit ISBN checking. | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 22 | ▶ | sub check_020 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_020: called CC=20 SCAR=34.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 5 | ▶ | use Business::ISBN; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 22 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 22 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | ################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | # break subfields into code-data array and validate data | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 22 | my @subfields = $field->subfields(); | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 22 | ▶ | while (my $subfield = pop(@subfields)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 22 | my ($code, $data) = @$subfield; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 22 | my $isbnno = $data; | |||||||||||||||||||||||||||||||||||||||||
| 298 | #remove any hyphens | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 22 | $isbnno =~ s/\-//g; | |||||||||||||||||||||||||||||||||||||||||
| 300 | #remove nondigits | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 22 | $isbnno =~ s/^\D*(\d{9,12}[X\d])\b.*$/$1/; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | #report error if this is subfield 'a' | ||||||||||||||||||||||||||||||||||||||||||
| 304 | #and the first 10 or 13 characters are not a match for $isbnno | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 22 | ▶ | if ($code eq 'a') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 21 | ▶ | if ((substr($data,0,length($isbnno)) ne $isbnno)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 2 | $self->warn( "020: Subfield a may have invalid characters."); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } #if first characters don't match | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | #report error if no space precedes a qualifier in subfield a | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 21 | ▶ | if ($data =~ /\(/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 8 | ▶ | $self->warn( "020: Subfield a qualifier must be preceded by space, $data.") unless ($data =~ /[X0-9] \(/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | } #if data has parenthetical qualifier | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | #report error if unable to find 10-13 digit string of digits in subfield 'a' | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 21 | ▶ | if (($isbnno !~ /(?:^\d{10}$)|(?:^\d{13}$)|(?:^\d{9}X$)/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 3 | $self->warn( "020: Subfield a has the wrong number of digits, $data."); | |||||||||||||||||||||||||||||||||||||||||
| 318 | } # if subfield 'a' but not 10 or 13 digit isbn | ||||||||||||||||||||||||||||||||||||||||||
| 319 | #otherwise, check 10 and 13 digit checksums for validity | ||||||||||||||||||||||||||||||||||||||||||
| 320 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 18 | ▶ | if ((length ($isbnno) == 10)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 16 | ▶ | if (($Business::ISBN::VERSION gt '2.02_01') || ($Business::ISBN::VERSION gt '2.009')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$Business::ISBN::VERSION gt "2.02_01" or $Business::ISBN::VERSION gt "2.009"
MC/DC0%0/2
$Business::ISBN::VERSION gt "2.02_01" or $Business::ISBN::VERSION gt "2.009"
$Business::ISBN::VERSION gt "2.02_01"
$Business::ISBN::VERSION gt "2.009"
Truth table33%1/3
A or B
A= $Business::ISBN::VERSION gt "2.02_01"B= $Business::ISBN::VERSION gt "2.009"
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 16 | ▶ | $self->warn( "020: Subfield a has bad checksum, $data." ) if (Business::ISBN::valid_isbn_checksum($isbnno) != 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | } #if Business::ISBN version higher than 2.02_01 or 2.009 | ||||||||||||||||||||||||||||||||||||||||||
| 326 | elsif ($Business::ISBN::VERSION lt '2') { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | $self->warn( "020: Subfield a has bad checksum, $data." ) if (Business::ISBN::is_valid_checksum($isbnno) != 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | } #elsif Business::ISBN version lower than 2 | ||||||||||||||||||||||||||||||||||||||||||
| 329 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $self->warn( "Business::ISBN version must be below 2 or above 2.02_02 or 2.009." ); | |||||||||||||||||||||||||||||||||||||||||
| 331 | } #else Business::ISBN version between 2 and 2.02_02 | ||||||||||||||||||||||||||||||||||||||||||
| 332 | } #if 10 digit ISBN has invalid check digit | ||||||||||||||||||||||||||||||||||||||||||
| 333 | # do validation check for 13 digit isbn | ||||||||||||||||||||||||||||||||||||||||||
| 334 | ######################################### | ||||||||||||||||||||||||||||||||||||||||||
| 335 | ### Not yet fully implemented ########### | ||||||||||||||||||||||||||||||||||||||||||
| 336 | ######################################### | ||||||||||||||||||||||||||||||||||||||||||
| 337 | elsif (length($isbnno) == 13){ | ||||||||||||||||||||||||||||||||||||||||||
| 338 | #change line below once Business::ISBN handles 13-digit ISBNs | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 2 | my $is_valid_13 = _isbn13_check_digit($isbnno); | |||||||||||||||||||||||||||||||||||||||||
| 340 | 2 | ▶ | $self->warn( "020: Subfield a has bad checksum (13 digit), $data.") unless ($is_valid_13 == 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | } #elsif 13 digit ISBN has invalid check digit | ||||||||||||||||||||||||||||||||||||||||||
| 342 | ################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 343 | } #else subfield 'a' has 10 or 13 digits | ||||||||||||||||||||||||||||||||||||||||||
| 344 | } #if subfield 'a' | ||||||||||||||||||||||||||||||||||||||||||
| 345 | #look for valid isbn in 020$z | ||||||||||||||||||||||||||||||||||||||||||
| 346 | elsif ($code eq 'z') { | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | ▶ | if (($data =~ /^ISBN/) || ($data =~ /^\d*\-\d+/)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$data =~ /^ISBN/ or $data =~ /^\d*\-\d+/
MC/DC0%0/2
$data =~ /^ISBN/ or $data =~ /^\d*\-\d+/
$data =~ /^ISBN/
$data =~ /^\d*\-\d+/
Truth table33%1/3
A or B
A= $data =~ /^ISBN/B= $data =~ /^\d*\-\d+/
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 349 | ## Turned on for now--Comment to unimplement #### | ||||||||||||||||||||||||||||||||||||||||||
| 350 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | $self->warn( "020: Subfield z is numerically valid.") if ((length ($isbnno) == 10) && (Business::ISBN::is_valid_checksum($isbnno) == 1)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $isbnno == 10 and Business::ISBN::is_valid_checksum($isbnno) == 1
MC/DC0%0/2
length $isbnno == 10 and Business::ISBN::is_valid_checksum($isbnno) == 1
length $isbnno == 10
Business::ISBN::is_valid_checksum($isbnno) == 1
Truth table0%0/3
A and B
A= length $isbnno == 10B= Business::ISBN::is_valid_checksum($isbnno) == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | } #if 10 digit ISBN has invalid check digit | ||||||||||||||||||||||||||||||||||||||||||
| 353 | } #elsif subfield 'z' | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | } # while @subfields | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | } #check_020 | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | =head2 _isbn13_check_digit($ean) | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | Internal sub to determine if 13-digit ISBN has a valid checksum. The code is | ||||||||||||||||||||||||||||||||||||||||||
| 362 | taken from Business::ISBN::as_ean. It is expected to be temporary until | ||||||||||||||||||||||||||||||||||||||||||
| 363 | Business::ISBN is updated to check 13-digit ISBNs itself. | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | ▶ | sub _isbn13_check_digit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_isbn13_check_digit: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | my $ean = shift; | |||||||||||||||||||||||||||||||||||||||||
| 370 | #remove and store current check digit | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | my $check_digit = chop($ean); | |||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | #calculate valid checksum | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 2 | my $sum = 0; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 2 | foreach my $index ( 0, 2, 4, 6, 8, 10 ) | |||||||||||||||||||||||||||||||||||||||||
| 376 | { | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 12 | $sum += substr($ean, $index, 1); | |||||||||||||||||||||||||||||||||||||||||
| 378 | 12 | $sum += 3 * substr($ean, $index + 1, 1); | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | #take the next higher multiple of 10 and subtract the sum. | ||||||||||||||||||||||||||||||||||||||||||
| 382 | #if $sum is 37, the next highest multiple of ten is 40. the | ||||||||||||||||||||||||||||||||||||||||||
| 383 | #check digit would be 40 - 37 => 3. | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 2 | my $valid_check_digit = ( 10 * ( int( $sum / 10 ) + 1 ) - $sum ) % 10; | |||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 2 | ▶ | return $check_digit == $valid_check_digit ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | } # _isbn13_check_digit | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | ######################################### | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | =head2 check_041( $field ) | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | Warns if subfields are not evenly divisible by 3 unless second indicator is 7 | ||||||||||||||||||||||||||||||||||||||||||
| 395 | (future implementation would ensure that each subfield is exactly 3 characters | ||||||||||||||||||||||||||||||||||||||||||
| 396 | unless ind2 is 7--since subfields are now repeatable. This is not implemented | ||||||||||||||||||||||||||||||||||||||||||
| 397 | here due to the large number of records needing to be corrected.). Validates | ||||||||||||||||||||||||||||||||||||||||||
| 398 | against the MARC Code List for Languages (L<http://www.loc.gov/marc/>) using the | ||||||||||||||||||||||||||||||||||||||||||
| 399 | MARC::Lint::CodeData data pack to MARC::Lint (%LanguageCodes, | ||||||||||||||||||||||||||||||||||||||||||
| 400 | %ObsoleteLanguageCodes). | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 3 | ▶ | sub check_041 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_041: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 3 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | # break subfields into code-data array (so the entire field is in one array) | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 3 | my @subfields = $field->subfields(); | |||||||||||||||||||||||||||||||||||||||||
| 413 | 3 | my @newsubfields = (); | |||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 3 | ▶ | while (my $subfield = pop(@subfields)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 7 | my ($code, $data) = @$subfield; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 7 | unshift (@newsubfields, $code, $data); | |||||||||||||||||||||||||||||||||||||||||
| 418 | } # while | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | #warn if length of each subfield is not divisible by 3 unless ind2 is 7 | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 3 | ▶ | unless ($field->indicator(2) eq '7') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 3 | ▶ | for (my $index = 0; $index <=$#newsubfields; $index+=2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 7 | ▶ | if (length ($newsubfields[$index+1]) %3 != 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 3 | $self->warn( "041: Subfield _$newsubfields[$index] must be evenly divisible by 3 or exactly three characters if ind2 is not 7, ($newsubfields[$index+1])." ); | |||||||||||||||||||||||||||||||||||||||||
| 425 | } #if field length not divisible evenly by 3 | ||||||||||||||||||||||||||||||||||||||||||
| 426 | ############################################## | ||||||||||||||||||||||||||||||||||||||||||
| 427 | # validation against code list data | ||||||||||||||||||||||||||||||||||||||||||
| 428 | ## each subfield has a multiple of 3 chars | ||||||||||||||||||||||||||||||||||||||||||
| 429 | # need to look at each group of 3 characters | ||||||||||||||||||||||||||||||||||||||||||
| 430 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | #break each character of the subfield into an array position | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 4 | my @codechars = split '', $newsubfields[$index+1]; | |||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 4 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||
| 436 | #store each 3 char code in a slot of @codes041 | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 4 | my @codes041 = (); | |||||||||||||||||||||||||||||||||||||||||
| 438 | 4 | ▶ | while ($pos <= $#codechars) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 6 | push @codes041, (join '', @codechars[$pos..$pos+2]); | |||||||||||||||||||||||||||||||||||||||||
| 440 | 6 | $pos += 3; | |||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 4 | foreach my $code041 (@codes041) { | |||||||||||||||||||||||||||||||||||||||||
| 445 | #see if language code matches valid code | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 6 | ▶ | my $validlang = $LanguageCodes{$code041} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | #look for invalid code match if valid code was not matched | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 6 | ▶ | my $obsoletelang = $ObsoleteLanguageCodes{$code041} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | # skip valid subfields | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 6 | ▶ | unless ($validlang) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | #report invalid matches as possible obsolete codes | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 6 | ▶ | if ($obsoletelang) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | $self->warn( "041: Subfield _$newsubfields[$index], $newsubfields[$index+1], may be obsolete."); | |||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 5 | $self->warn( "041: Subfield _$newsubfields[$index], $newsubfields[$index+1] ($code041), is not valid."); | |||||||||||||||||||||||||||||||||||||||||
| 458 | } #else code not found | ||||||||||||||||||||||||||||||||||||||||||
| 459 | } # unless found valid code | ||||||||||||||||||||||||||||||||||||||||||
| 460 | } #foreach code in 041 | ||||||||||||||||||||||||||||||||||||||||||
| 461 | } # else subfield has multiple of 3 chars | ||||||||||||||||||||||||||||||||||||||||||
| 462 | ############################################## | ||||||||||||||||||||||||||||||||||||||||||
| 463 | } # foreach subfield | ||||||||||||||||||||||||||||||||||||||||||
| 464 | } #unless ind2 is 7 | ||||||||||||||||||||||||||||||||||||||||||
| 465 | } #check_041 | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | =head2 check_043( $field ) | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | Warns if each subfield a is not exactly 7 characters. Validates each code | ||||||||||||||||||||||||||||||||||||||||||
| 470 | against the MARC code list for Geographic Areas (L<http://www.loc.gov/marc/>) | ||||||||||||||||||||||||||||||||||||||||||
| 471 | using the MARC::Lint::CodeData data pack to MARC::Lint (%GeogAreaCodes, | ||||||||||||||||||||||||||||||||||||||||||
| 472 | %ObsoleteGeogAreaCodes). | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 2 | ▶ | sub check_043 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_043: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 479 | 2 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | # break subfields into code-data array (so the entire field is in one array) | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | 2 | my @subfields = $field->subfields(); | |||||||||||||||||||||||||||||||||||||||||
| 484 | 2 | my @newsubfields = (); | |||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 2 | ▶ | while (my $subfield = pop(@subfields)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 5 | my ($code, $data) = @$subfield; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 5 | unshift (@newsubfields, $code, $data); | |||||||||||||||||||||||||||||||||||||||||
| 489 | } # while | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | #warn if length of subfield a is not exactly 7 | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 2 | ▶ | for (my $index = 0; $index <=$#newsubfields; $index+=2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 5 | ▶ | if (($newsubfields[$index] eq 'a') && (length ($newsubfields[$index+1]) != 7)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$newsubfields[$index] eq "a" and length $newsubfields[$index + 1] != 7
MC/DC50%1/2
$newsubfields[$index] eq "a" and length $newsubfields[$index + 1] != 7
$newsubfields[$index] eq "a"
length $newsubfields[$index + 1] != 7
Truth table66%2/3
A and B
A= $newsubfields[$index] eq "a"B= length $newsubfields[$index + 1] != 7
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 2 | $self->warn( "043: Subfield _a must be exactly 7 characters, $newsubfields[$index+1]" ); | |||||||||||||||||||||||||||||||||||||||||
| 495 | } # if suba and length is not 7 | ||||||||||||||||||||||||||||||||||||||||||
| 496 | #check against code list for geographic areas. | ||||||||||||||||||||||||||||||||||||||||||
| 497 | elsif ($newsubfields[$index] eq 'a') { | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | #see if geog area code matches valid code | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 3 | ▶ | my $validgac = $GeogAreaCodes{$newsubfields[$index+1]} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | #look for obsolete code match if valid code was not matched | ||||||||||||||||||||||||||||||||||||||||||
| 502 | 3 | ▶ | my $obsoletegac = $ObsoleteGeogAreaCodes{$newsubfields[$index+1]} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | # skip valid subfields | ||||||||||||||||||||||||||||||||||||||||||
| 505 | 3 | ▶ | unless ($validgac) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | #report invalid matches as possible obsolete codes | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 3 | ▶ | if ($obsoletegac) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | $self->warn( "043: Subfield _a, $newsubfields[$index+1], may be obsolete."); | |||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 2 | $self->warn( "043: Subfield _a, $newsubfields[$index+1], is not valid."); | |||||||||||||||||||||||||||||||||||||||||
| 512 | } #else code not found | ||||||||||||||||||||||||||||||||||||||||||
| 513 | } # unless found valid code | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | } #elsif suba | ||||||||||||||||||||||||||||||||||||||||||
| 516 | } #foreach subfield | ||||||||||||||||||||||||||||||||||||||||||
| 517 | } #check_043 | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | =head2 check_245( $field ) | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | -Makes sure $a exists (and is first subfield). | ||||||||||||||||||||||||||||||||||||||||||
| 522 | -Warns if last character of field is not a period | ||||||||||||||||||||||||||||||||||||||||||
| 523 | --Follows LCRI 1.0C, Nov. 2003 rather than MARC21 rule | ||||||||||||||||||||||||||||||||||||||||||
| 524 | -Verifies that $c is preceded by / (space-/) | ||||||||||||||||||||||||||||||||||||||||||
| 525 | -Verifies that initials in $c are not spaced | ||||||||||||||||||||||||||||||||||||||||||
| 526 | -Verifies that $b is preceded by :;= (space-colon, space-semicolon, space-equals) | ||||||||||||||||||||||||||||||||||||||||||
| 527 | -Verifies that $h is not preceded by space unless it is dash-space | ||||||||||||||||||||||||||||||||||||||||||
| 528 | -Verifies that data of $h is enclosed in square brackets | ||||||||||||||||||||||||||||||||||||||||||
| 529 | -Verifies that $n is preceded by . (period) | ||||||||||||||||||||||||||||||||||||||||||
| 530 | --As part of that, looks for no-space period, or dash-space-period (for replaced elipses) | ||||||||||||||||||||||||||||||||||||||||||
| 531 | -Verifies that $p is preceded by , (no-space-comma) when following $n and . (period) when following other subfields. | ||||||||||||||||||||||||||||||||||||||||||
| 532 | -Performs rudimentary article check of 245 2nd indicator vs. 1st word of 245$a (for manual verification). | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | Article checking is done by internal _check_article method, which should work for 130, 240, 245, 440, 630, 730, and 830. | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | 49 | ▶ | sub check_245 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_245: called CC=38 SCAR=36.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 49 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 541 | 49 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | #set tagno for reporting | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 49 | my $tagno = '245'; | |||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | 49 | ▶ | if ( not $field->subfield( "a" ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 1 | $self->warn( "245: Must have a subfield _a." ); | |||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | # break subfields into code-data array (so the entire field is in one array) | ||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | 49 | my @subfields = $field->subfields(); | |||||||||||||||||||||||||||||||||||||||||
| 553 | 49 | my @newsubfields = (); | |||||||||||||||||||||||||||||||||||||||||
| 554 | 49 | my $has_sub_6 = 0; | |||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | 49 | ▶ | while (my $subfield = pop(@subfields)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | 90 | my ($code, $data) = @$subfield; | |||||||||||||||||||||||||||||||||||||||||
| 558 | #check for subfield 6 being present | ||||||||||||||||||||||||||||||||||||||||||
| 559 | 90 | ▶ | $has_sub_6 = 1 if ($code eq '6'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | 90 | unshift (@newsubfields, $code, $data); | |||||||||||||||||||||||||||||||||||||||||
| 561 | } # while | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | # 245 must end in period (may want to make this less restrictive by allowing trailing spaces) | ||||||||||||||||||||||||||||||||||||||||||
| 564 | #do 2 checks--for final punctuation (MARC21 rule), and for period (LCRI 1.0C, Nov. 2003; LCPS 1.7.1) | ||||||||||||||||||||||||||||||||||||||||||
| 565 | 49 | ▶ | if ($newsubfields[$#newsubfields] !~ /[.?!]$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 1 | $self->warn ( "245: Must end with . (period)."); | |||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | elsif($newsubfields[$#newsubfields] =~ /[?!]$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 2 | $self->warn ( "245: MARC21 allows ? or ! as final punctuation but LCRI 1.0C, Nov. 2003 (LCPS 1.7.1 for RDA records), requires period."); | |||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | ##Check for first subfield | ||||||||||||||||||||||||||||||||||||||||||
| 573 | #subfield a should be first subfield (or 2nd if subfield '6' is present) | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 49 | ▶ | if ($has_sub_6) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | #make sure there are at least 2 subfields | ||||||||||||||||||||||||||||||||||||||||||
| 576 | 2 | ▶ | if ($#newsubfields < 3) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | $self->warn ("$tagno: May have too few subfields."); | |||||||||||||||||||||||||||||||||||||||||
| 578 | } #if fewer than 2 subfields | ||||||||||||||||||||||||||||||||||||||||||
| 579 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 580 | 2 | ▶ | if ($newsubfields[0] ne '6') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $self->warn ( "$tagno: First subfield must be _6, but it is $newsubfields[0]"); | |||||||||||||||||||||||||||||||||||||||||
| 582 | } #if 1st subfield not '6' | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 2 | ▶ | if ($newsubfields[2] ne 'a') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | $self->warn ( "$tagno: First subfield after subfield _6 must be _a, but it is _$newsubfields[2]"); | |||||||||||||||||||||||||||||||||||||||||
| 585 | } #if 2nd subfield not 'a' | ||||||||||||||||||||||||||||||||||||||||||
| 586 | } #else at least 2 subfields | ||||||||||||||||||||||||||||||||||||||||||
| 587 | } #if has subfield 6 | ||||||||||||||||||||||||||||||||||||||||||
| 588 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 589 | #1st subfield must be 'a' | ||||||||||||||||||||||||||||||||||||||||||
| 590 | 47 | ▶ | if ($newsubfields[0] ne 'a') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 1 | $self->warn ( "$tagno: First subfield must be _a, but it is _$newsubfields[0]"); | |||||||||||||||||||||||||||||||||||||||||
| 592 | } #if 2nd subfield not 'a' | ||||||||||||||||||||||||||||||||||||||||||
| 593 | } #else no subfield _6 | ||||||||||||||||||||||||||||||||||||||||||
| 594 | ##End check for first subfield | ||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | #subfield c, if present, must be preceded by / | ||||||||||||||||||||||||||||||||||||||||||
| 597 | #also look for space between initials | ||||||||||||||||||||||||||||||||||||||||||
| 598 | 49 | ▶ | if ($field->subfield("c")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | 14 | ▶ | for (my $index = 2; $index <=$#newsubfields; $index+=2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | # 245 subfield c must be preceded by / (space-/) | ||||||||||||||||||||||||||||||||||||||||||
| 602 | 17 | ▶ | if ($newsubfields[$index] eq 'c') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | 14 | ▶ | $self->warn ( "245: Subfield _c must be preceded by /") if ($newsubfields[$index-1] !~ /\s\/$/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | # 245 subfield c initials should not have space | ||||||||||||||||||||||||||||||||||||||||||
| 605 | 14 | ▶ | $self->warn ( "245: Subfield _c initials should not have a space.") if (($newsubfields[$index+1] =~ /\b\w\. \b\w\./) && ($newsubfields[$index+1] !~ /\[\bi\.e\. \b\w\..*\]/)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$newsubfields[$index + 1] =~ /\b\w\. \b\w\./ and not $newsubfields[$index + 1] =~ /\[\bi\.e\. \b\w\..*\]/
MC/DC50%1/2
$newsubfields[$index + 1] =~ /\b\w\. \b\w\./ and not $newsubfields[$index + 1] =~ /\[\bi\.e\. \b\w\..*\]/
$newsubfields[$index + 1] =~ /\b\w\. \b\w\./
not $newsubfields[$index + 1] =~ /\[\bi\.e\. \b\w\..*\]/
Truth table66%2/3
A and not(B)
A= $newsubfields[$index + 1] =~ /\b\w\. \b\w\./B= not $newsubfields[$index + 1] =~ /\[\bi\.e\. \b\w\..*\]/
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 14 | last; | |||||||||||||||||||||||||||||||||||||||||
| 607 | } #if | ||||||||||||||||||||||||||||||||||||||||||
| 608 | } #for | ||||||||||||||||||||||||||||||||||||||||||
| 609 | } # subfield c exists | ||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | #each subfield b, if present, should be preceded by :;= (colon, semicolon, or equals sign) | ||||||||||||||||||||||||||||||||||||||||||
| 612 | ### Are there others? ### | ||||||||||||||||||||||||||||||||||||||||||
| 613 | 49 | ▶ | if ($field->subfield("b")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | # 245 subfield b should be preceded by space-:;= (colon, semicolon, or equals sign) | ||||||||||||||||||||||||||||||||||||||||||
| 616 | 13 | ▶ | for (my $index = 2; $index <=$#newsubfields; $index+=2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | #report error if subfield 'b' is not preceded by space-:;= (colon, semicolon, or equals sign) | ||||||||||||||||||||||||||||||||||||||||||
| 618 | 16 | ▶ | if (($newsubfields[$index] eq 'b') && ($newsubfields[$index-1] !~ / [:;=]$/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$newsubfields[$index] eq "b" and not $newsubfields[$index - 1] =~ / [:;=]$/
MC/DC100%2/2
$newsubfields[$index] eq "b" and not $newsubfields[$index - 1] =~ / [:;=]$/
$newsubfields[$index] eq "b"
not $newsubfields[$index - 1] =~ / [:;=]$/
Truth table100%3/3
A and not(B)
A= $newsubfields[$index] eq "b"B= not $newsubfields[$index - 1] =~ / [:;=]$/
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | 4 | $self->warn ( "245: Subfield _b should be preceded by space-colon, space-semicolon, or space-equals sign."); | |||||||||||||||||||||||||||||||||||||||||
| 620 | } #if | ||||||||||||||||||||||||||||||||||||||||||
| 621 | } #for | ||||||||||||||||||||||||||||||||||||||||||
| 622 | } # subfield b exists | ||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | #each subfield h, if present, should be preceded by non-space | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 49 | ▶ | if ($field->subfield("h")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | # 245 subfield h should not be preceded by space | ||||||||||||||||||||||||||||||||||||||||||
| 629 | 4 | ▶ | for (my $index = 2; $index <=$#newsubfields; $index+=2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | #report error if subfield 'h' is preceded by space (unless dash-space) | ||||||||||||||||||||||||||||||||||||||||||
| 631 | 6 | ▶ | if (($newsubfields[$index] eq 'h') && ($newsubfields[$index-1] !~ /(\S$)|(\-\- $)/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$newsubfields[$index] eq "h" and not $newsubfields[$index - 1] =~ /(\S$)|(\-\- $)/
MC/DC100%2/2
$newsubfields[$index] eq "h" and not $newsubfields[$index - 1] =~ /(\S$)|(\-\- $)/
$newsubfields[$index] eq "h"
not $newsubfields[$index - 1] =~ /(\S$)|(\-\- $)/
Truth table100%3/3
A and not(B)
A= $newsubfields[$index] eq "h"B= not $newsubfields[$index - 1] =~ /(\S$)|(\-\- $)/
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | 1 | $self->warn ( "245: Subfield _h should not be preceded by space."); | |||||||||||||||||||||||||||||||||||||||||
| 633 | } #if h and not preceded by no-space (unless dash) | ||||||||||||||||||||||||||||||||||||||||||
| 634 | #report error if subfield 'h' does not start with open square bracket with a matching close bracket | ||||||||||||||||||||||||||||||||||||||||||
| 635 | ##could have check against list of valid values here | ||||||||||||||||||||||||||||||||||||||||||
| 636 | 6 | ▶ | if (($newsubfields[$index] eq 'h') && ($newsubfields[$index+1] !~ /^\[\w*\s*\w*\]/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$newsubfields[$index] eq "h" and not $newsubfields[$index + 1] =~ /^\[\w*\s*\w*\]/
MC/DC100%2/2
$newsubfields[$index] eq "h" and not $newsubfields[$index + 1] =~ /^\[\w*\s*\w*\]/
$newsubfields[$index] eq "h"
not $newsubfields[$index + 1] =~ /^\[\w*\s*\w*\]/
Truth table100%3/3
A and not(B)
A= $newsubfields[$index] eq "h"B= not $newsubfields[$index + 1] =~ /^\[\w*\s*\w*\]/
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | 1 | $self->warn ( "245: Subfield _h must have matching square brackets, $newsubfields[$index]."); | |||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||
| 639 | } #for | ||||||||||||||||||||||||||||||||||||||||||
| 640 | } # subfield h exists | ||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||
| 642 | #each subfield n, if present, must be preceded by . (period) | ||||||||||||||||||||||||||||||||||||||||||
| 643 | 49 | ▶ | if ($field->subfield("n")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||
| 645 | # 245 subfield n must be preceded by . (period) | ||||||||||||||||||||||||||||||||||||||||||
| 646 | 4 | ▶ | for (my $index = 2; $index <=$#newsubfields; $index+=2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 647 | #report error if subfield 'n' is not preceded by non-space-period or dash-space-period | ||||||||||||||||||||||||||||||||||||||||||
| 648 | 6 | ▶ | if (($newsubfields[$index] eq 'n') && ($newsubfields[$index-1] !~ /(\S\.$)|(\-\- \.$)/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$newsubfields[$index] eq "n" and not $newsubfields[$index - 1] =~ /(\S\.$)|(\-\- \.$)/
MC/DC100%2/2
$newsubfields[$index] eq "n" and not $newsubfields[$index - 1] =~ /(\S\.$)|(\-\- \.$)/
$newsubfields[$index] eq "n"
not $newsubfields[$index - 1] =~ /(\S\.$)|(\-\- \.$)/
Truth table100%3/3
A and not(B)
A= $newsubfields[$index] eq "n"B= not $newsubfields[$index - 1] =~ /(\S\.$)|(\-\- \.$)/
| |||||||||||||||||||||||||||||||||||||||||||
| 649 | 1 | $self->warn ( "245: Subfield _n must be preceded by . (period)."); | |||||||||||||||||||||||||||||||||||||||||
| 650 | } #if | ||||||||||||||||||||||||||||||||||||||||||
| 651 | } #for | ||||||||||||||||||||||||||||||||||||||||||
| 652 | } # subfield n exists | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | #each subfield p, if present, must be preceded by a , (no-space-comma) if it follows subfield n, or by . (no-space-period or dash-space-period) following other subfields | ||||||||||||||||||||||||||||||||||||||||||
| 655 | 49 | ▶ | if ($field->subfield("p")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | # 245 subfield p must be preceded by . (period) or , (comma) | ||||||||||||||||||||||||||||||||||||||||||
| 658 | 4 | ▶ | for (my $index = 2; $index <=$#newsubfields; $index+=2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | #only looking for subfield p | ||||||||||||||||||||||||||||||||||||||||||
| 660 | 6 | ▶ | if ($newsubfields[$index] eq 'p') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 661 | # case for subfield 'n' being field before this one (allows dash-space-comma) | ||||||||||||||||||||||||||||||||||||||||||
| 662 | 4 | ▶ | if (($newsubfields[$index-2] eq 'n') && ($newsubfields[$index-1] !~ /(\S,$)|(\-\- ,$)/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$newsubfields[$index - 2] eq "n" and not $newsubfields[$index - 1] =~ /(\S,$)|(\-\- ,$)/
MC/DC100%2/2
$newsubfields[$index - 2] eq "n" and not $newsubfields[$index - 1] =~ /(\S,$)|(\-\- ,$)/
$newsubfields[$index - 2] eq "n"
not $newsubfields[$index - 1] =~ /(\S,$)|(\-\- ,$)/
Truth table100%3/3
A and not(B)
A= $newsubfields[$index - 2] eq "n"B= not $newsubfields[$index - 1] =~ /(\S,$)|(\-\- ,$)/
| |||||||||||||||||||||||||||||||||||||||||||
| 663 | 1 | $self->warn ( "245: Subfield _p must be preceded by , (comma) when it follows subfield _n."); | |||||||||||||||||||||||||||||||||||||||||
| 664 | } #if subfield n precedes this one | ||||||||||||||||||||||||||||||||||||||||||
| 665 | # elsif case for subfield before this one is not n | ||||||||||||||||||||||||||||||||||||||||||
| 666 | ▶ | elsif (($newsubfields[$index-2] ne 'n') && ($newsubfields[$index-1] !~ /(\S\.$)|(\-\- \.$)/)) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$newsubfields[$index - 2] ne "n" and not $newsubfields[$index - 1] =~ /(\S\.$)|(\-\- \.$)/
MC/DC100%2/2
$newsubfields[$index - 2] ne "n" and not $newsubfields[$index - 1] =~ /(\S\.$)|(\-\- \.$)/
$newsubfields[$index - 2] ne "n"
not $newsubfields[$index - 1] =~ /(\S\.$)|(\-\- \.$)/
Truth table100%3/3
A and not(B)
A= $newsubfields[$index - 2] ne "n"B= not $newsubfields[$index - 1] =~ /(\S\.$)|(\-\- \.$)/
| |||||||||||||||||||||||||||||||||||||||||||
| 667 | 1 | $self->warn ( "245: Subfield _p must be preceded by . (period) when it follows a subfield other than _n."); | |||||||||||||||||||||||||||||||||||||||||
| 668 | } #elsif subfield p preceded by non-period when following a non-subfield 'n' | ||||||||||||||||||||||||||||||||||||||||||
| 669 | } #if index is looking at subfield p | ||||||||||||||||||||||||||||||||||||||||||
| 670 | } #for | ||||||||||||||||||||||||||||||||||||||||||
| 671 | } # subfield p exists | ||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||
| 673 | ###################################### | ||||||||||||||||||||||||||||||||||||||||||
| 674 | #check for invalid 2nd indicator | ||||||||||||||||||||||||||||||||||||||||||
| 675 | 49 | $self->_check_article($field); | |||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | } # check_245 | ||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | ############ | ||||||||||||||||||||||||||||||||||||||||||
| 683 | # Internal # | ||||||||||||||||||||||||||||||||||||||||||
| 684 | ############ | ||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||
| 686 | =head2 _check_article | ||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | Check of articles is based on code from Ian Hamilton. This version is more | ||||||||||||||||||||||||||||||||||||||||||
| 689 | limited in that it focuses on English, Spanish, French, Italian and German | ||||||||||||||||||||||||||||||||||||||||||
| 690 | articles. Certain possible articles have been removed if they are valid English | ||||||||||||||||||||||||||||||||||||||||||
| 691 | non-articles. This version also disregards 008_language/041 codes and just uses | ||||||||||||||||||||||||||||||||||||||||||
| 692 | the list of articles to provide warnings/suggestions. | ||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | source for articles = L<http://www.loc.gov/marc/bibliographic/bdapp-e.html> | ||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | Should work with fields 130, 240, 245, 440, 630, 730, and 830. Reports error if | ||||||||||||||||||||||||||||||||||||||||||
| 697 | another field is passed in. | ||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | 49 | ▶ | sub _check_article { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_article: called CC=23 SCAR=32.7
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | 49 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 704 | 49 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | #add articles here as needed | ||||||||||||||||||||||||||||||||||||||||||
| 707 | ##Some omitted due to similarity with valid words (e.g. the German 'die'). | ||||||||||||||||||||||||||||||||||||||||||
| 708 | 49 | my %article = ( | |||||||||||||||||||||||||||||||||||||||||
| 709 | 'a' => 'eng glg hun por', | ||||||||||||||||||||||||||||||||||||||||||
| 710 | 'an' => 'eng', | ||||||||||||||||||||||||||||||||||||||||||
| 711 | 'das' => 'ger', | ||||||||||||||||||||||||||||||||||||||||||
| 712 | 'dem' => 'ger', | ||||||||||||||||||||||||||||||||||||||||||
| 713 | 'der' => 'ger', | ||||||||||||||||||||||||||||||||||||||||||
| 714 | 'ein' => 'ger', | ||||||||||||||||||||||||||||||||||||||||||
| 715 | 'eine' => 'ger', | ||||||||||||||||||||||||||||||||||||||||||
| 716 | 'einem' => 'ger', | ||||||||||||||||||||||||||||||||||||||||||
| 717 | 'einen' => 'ger', | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 'einer' => 'ger', | ||||||||||||||||||||||||||||||||||||||||||
| 719 | 'eines' => 'ger', | ||||||||||||||||||||||||||||||||||||||||||
| 720 | 'el' => 'spa', | ||||||||||||||||||||||||||||||||||||||||||
| 721 | 'en' => 'cat dan nor swe', | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 'gl' => 'ita', | ||||||||||||||||||||||||||||||||||||||||||
| 723 | 'gli' => 'ita', | ||||||||||||||||||||||||||||||||||||||||||
| 724 | 'il' => 'ita mlt', | ||||||||||||||||||||||||||||||||||||||||||
| 725 | 'l' => 'cat fre ita mlt', | ||||||||||||||||||||||||||||||||||||||||||
| 726 | 'la' => 'cat fre ita spa', | ||||||||||||||||||||||||||||||||||||||||||
| 727 | 'las' => 'spa', | ||||||||||||||||||||||||||||||||||||||||||
| 728 | 'le' => 'fre ita', | ||||||||||||||||||||||||||||||||||||||||||
| 729 | 'les' => 'cat fre', | ||||||||||||||||||||||||||||||||||||||||||
| 730 | 'lo' => 'ita spa', | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 'los' => 'spa', | ||||||||||||||||||||||||||||||||||||||||||
| 732 | 'os' => 'por', | ||||||||||||||||||||||||||||||||||||||||||
| 733 | 'the' => 'eng', | ||||||||||||||||||||||||||||||||||||||||||
| 734 | 'um' => 'por', | ||||||||||||||||||||||||||||||||||||||||||
| 735 | 'uma' => 'por', | ||||||||||||||||||||||||||||||||||||||||||
| 736 | 'un' => 'cat spa fre ita', | ||||||||||||||||||||||||||||||||||||||||||
| 737 | 'una' => 'cat spa ita', | ||||||||||||||||||||||||||||||||||||||||||
| 738 | 'une' => 'fre', | ||||||||||||||||||||||||||||||||||||||||||
| 739 | 'uno' => 'ita', | ||||||||||||||||||||||||||||||||||||||||||
| 740 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||
| 742 | #add exceptions here as needed | ||||||||||||||||||||||||||||||||||||||||||
| 743 | # may want to make keys lowercase | ||||||||||||||||||||||||||||||||||||||||||
| 744 | 49 | my %exceptions = ( | |||||||||||||||||||||||||||||||||||||||||
| 745 | 'A & E' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 746 | 'A & ' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 747 | 'A-' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 748 | 'A+' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 749 | 'A is ' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 750 | 'A isn\'t ' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 751 | 'A l\'' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 752 | 'A la ' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 'A posteriori' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 754 | 'A priori' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 'A to ' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 756 | 'El Nino' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 757 | 'El Salvador' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 758 | 'L is ' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 759 | 'L-' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 760 | 'La Salle' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 761 | 'Las Vegas' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 762 | 'Lo cual' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 763 | 'Lo mein' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 764 | 'Lo que' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 765 | 'Los Alamos' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 766 | 'Los Angeles' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 767 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||
| 769 | #get tagno to determine which indicator to check and for reporting | ||||||||||||||||||||||||||||||||||||||||||
| 770 | 49 | my $tagno = $field->tag(); | |||||||||||||||||||||||||||||||||||||||||
| 771 | #retrieve tagno from subfield 6 if 880 field | ||||||||||||||||||||||||||||||||||||||||||
| 772 | 49 | ▶ | if ($tagno eq '880') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 773 | 1 | ▶ | if ($field->subfield('6')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | 1 | my $sub6 = $field->subfield('6'); | |||||||||||||||||||||||||||||||||||||||||
| 775 | 1 | $tagno = substr($sub6, 0, 3); | |||||||||||||||||||||||||||||||||||||||||
| 776 | } #if subfield 6 | ||||||||||||||||||||||||||||||||||||||||||
| 777 | } #if 880 field | ||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | #$ind holds nonfiling character indicator value | ||||||||||||||||||||||||||||||||||||||||||
| 780 | 49 | my $ind = ''; | |||||||||||||||||||||||||||||||||||||||||
| 781 | #$first_or_second holds which indicator is for nonfiling char value | ||||||||||||||||||||||||||||||||||||||||||
| 782 | 49 | my $first_or_second = ''; | |||||||||||||||||||||||||||||||||||||||||
| 783 | 49 | ▶ | if ($tagno !~ /^(?:130|240|245|440|630|730|830)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | print $tagno, " is not a valid field for article checking\n"; | |||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 786 | } #if field is not one of those checked for articles | ||||||||||||||||||||||||||||||||||||||||||
| 787 | #130, 630, 730 => ind1 | ||||||||||||||||||||||||||||||||||||||||||
| 788 | elsif ($tagno =~ /^(?:130|630|730)$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | $ind = $field->indicator(1); | |||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | $first_or_second = '1st'; | |||||||||||||||||||||||||||||||||||||||||
| 791 | } #if field is 130, 630, or 730 | ||||||||||||||||||||||||||||||||||||||||||
| 792 | #240, 245, 440, 830 => ind2 | ||||||||||||||||||||||||||||||||||||||||||
| 793 | elsif ($tagno =~ /^(?:240|245|440|830)$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 794 | 49 | $ind = $field->indicator(2); | |||||||||||||||||||||||||||||||||||||||||
| 795 | 49 | $first_or_second = '2nd'; | |||||||||||||||||||||||||||||||||||||||||
| 796 | } #if field is 240, 245, 440, or 830 | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | #report non-numeric non-filing indicators as invalid | ||||||||||||||||||||||||||||||||||||||||||
| 800 | 49 | ▶ | $self->warn ( $tagno, ": Non-filing indicator is non-numeric" ) unless ($ind =~ /^[0-9]$/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 801 | #get subfield 'a' of the title field | ||||||||||||||||||||||||||||||||||||||||||
| 802 | 49 | ▶ | my $title = $field->subfield('a') || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$field->subfield('a') || ''
MC/DC100%1/1
$field->subfield('a') || ''
$field->subfield('a')
Truth table100%2/2
A
A= $field->subfield('a')
| |||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | 49 | my $char1_notalphanum = 0; | |||||||||||||||||||||||||||||||||||||||||
| 806 | #check for apostrophe, quote, bracket, or parenthesis, before first word | ||||||||||||||||||||||||||||||||||||||||||
| 807 | #remove if found and add to non-word counter | ||||||||||||||||||||||||||||||||||||||||||
| 808 | 49 | ▶ | while ($title =~ /^["'\[\(*]/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 809 | 4 | $char1_notalphanum++; | |||||||||||||||||||||||||||||||||||||||||
| 810 | 4 | $title =~ s/^["'\[\(*]//; | |||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||
| 812 | # split title into first word + rest on space, parens, bracket, apostrophe, quote, or hyphen | ||||||||||||||||||||||||||||||||||||||||||
| 813 | 49 | my ($firstword, $separator, $etc) = $title =~ /^([^ \(\)\[\]'"\-]+)([ \(\)\[\]'"\-])?(.*)/i; | |||||||||||||||||||||||||||||||||||||||||
| 814 | 49 | ▶ | $firstword = '' if ! defined( $firstword ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 815 | 49 | ▶ | $separator = '' if ! defined( $separator ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 816 | 49 | ▶ | $etc = '' if ! defined( $etc ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | #get length of first word plus the number of chars removed above plus one for the separator | ||||||||||||||||||||||||||||||||||||||||||
| 819 | 49 | my $nonfilingchars = length($firstword) + $char1_notalphanum + 1; | |||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | #check to see if first word is an exception | ||||||||||||||||||||||||||||||||||||||||||
| 822 | 49 | my $isan_exception = 0; | |||||||||||||||||||||||||||||||||||||||||
| 823 | 49 | $isan_exception = grep {$title =~ /^\Q$_\E/i} (keys %exceptions); | |||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||
| 825 | #lowercase chars of $firstword for comparison with article list | ||||||||||||||||||||||||||||||||||||||||||
| 826 | 49 | $firstword = lc($firstword); | |||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | 49 | my $isan_article = 0; | |||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | #see if first word is in the list of articles and not an exception | ||||||||||||||||||||||||||||||||||||||||||
| 831 | 49 | ▶ | $isan_article = 1 if (($article{$firstword}) && !($isan_exception)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$article{$firstword} and not $isan_exception
MC/DC100%2/2
$article{$firstword} and not $isan_exception
$article{$firstword}
not $isan_exception
Truth table100%3/3
A and not(B)
A= $article{$firstword}B= not $isan_exception
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||
| 833 | #if article then $nonfilingchars should match $ind | ||||||||||||||||||||||||||||||||||||||||||
| 834 | 49 | ▶ | if ($isan_article) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 835 | #account for quotes, apostrophes, parens, or brackets before 2nd word | ||||||||||||||||||||||||||||||||||||||||||
| 836 | # if (($separator eq ' ') && ($etc =~ /^['"]/)) { | ||||||||||||||||||||||||||||||||||||||||||
| 837 | 9 | ▶ | if (($separator) && ($etc =~ /^[ \(\)\[\]'"\-]+/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$separator and $etc =~ /^[ \(\)\[\]'"\-]+/
MC/DC50%1/2
$separator and $etc =~ /^[ \(\)\[\]'"\-]+/
$separator
$etc =~ /^[ \(\)\[\]'"\-]+/
Truth table66%2/3
A and B
A= $separatorB= $etc =~ /^[ \(\)\[\]'"\-]+/
| |||||||||||||||||||||||||||||||||||||||||||
| 838 | 4 | ▶ | while ($etc =~ /^[ "'\[\]\(\)*]/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 839 | 6 | $nonfilingchars++; | |||||||||||||||||||||||||||||||||||||||||
| 840 | 6 | $etc =~ s/^[ "'\[\]\(\)*]//; | |||||||||||||||||||||||||||||||||||||||||
| 841 | } #while etc starts with nonfiling chars | ||||||||||||||||||||||||||||||||||||||||||
| 842 | } #if separator defined and etc starts with nonfiling chars | ||||||||||||||||||||||||||||||||||||||||||
| 843 | #special case for 'en' (unsure why) | ||||||||||||||||||||||||||||||||||||||||||
| 844 | 9 | ▶ | if ($firstword eq 'en') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | ▶ | $self->warn ( $tagno, ": First word, , $firstword, may be an article, check $first_or_second indicator ($ind)." ) unless (($ind eq '3') || ($ind eq '0')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ind eq 3 or $ind eq 0
MC/DC0%0/2
$ind eq 3 or $ind eq 0
$ind eq 3
$ind eq 0
Truth table0%0/3
A or B
A= $ind eq 3B= $ind eq 0
| |||||||||||||||||||||||||||||||||||||||||||
| 846 | } | ||||||||||||||||||||||||||||||||||||||||||
| 847 | elsif ($nonfilingchars ne $ind) { | ||||||||||||||||||||||||||||||||||||||||||
| 848 | 3 | $self->warn ( $tagno, ": First word, $firstword, may be an article, check $first_or_second indicator ($ind)." ); | |||||||||||||||||||||||||||||||||||||||||
| 849 | } #unless ind is same as length of first word and nonfiling characters | ||||||||||||||||||||||||||||||||||||||||||
| 850 | } #if first word is in article list | ||||||||||||||||||||||||||||||||||||||||||
| 851 | #not an article so warn if $ind is not 0 | ||||||||||||||||||||||||||||||||||||||||||
| 852 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 853 | 40 | ▶ | unless ($ind eq '0') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 854 | 1 | $self->warn ( $tagno, ": First word, $firstword, does not appear to be an article, check $first_or_second indicator ($ind)." ); | |||||||||||||||||||||||||||||||||||||||||
| 855 | } #unless ind is 0 | ||||||||||||||||||||||||||||||||||||||||||
| 856 | } #else not in article list | ||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | ####################################### | ||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||
| 860 | } #_check_article | ||||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||
| 863 | ############ | ||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||
| 865 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||
| 867 | Check the docs for L<MARC::Record>. All software links are there. | ||||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||
| 869 | =head1 TODO | ||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||
| 871 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||
| 873 | =item * Subfield 6 | ||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||
| 875 | For subfield 6, it should always be the 1st subfield according to MARC 21 specifications. Perhaps a generic check should be added that warns if subfield 6 is not the 1st subfield. | ||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||
| 877 | =item * Subfield 8. | ||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||
| 879 | This subfield could be the 1st or 2nd subfield, so the code that checks for the 1st few subfields (check_245, check_250) should take that into account. | ||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||
| 881 | =item * Subfield 9 | ||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||
| 883 | This subfield is not officially allowed in MARC, since it is locally defined. Some way needs to be made to allow messages/warnings about this subfield to be turned off (or otherwise deal with records using/allowing locally defined subfield 9). | ||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||
| 885 | =item * 008 length and presence check | ||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||
| 887 | Currently, 008 validation is not implemented in MARC::Lint, but is left to MARC::Errorchecks. It might be useful if MARC::Lint's basic validation checks included a verification that the 008 exists and is exactly 40 characters long. Additional 008-related checking and byte validation would remain in MARC::Errorchecks. | ||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||
| 889 | =item * ISBN and ISSN checking | ||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||
| 891 | 020 and 022 fields are validated with the C<Business::ISBN> and | ||||||||||||||||||||||||||||||||||||||||||
| 892 | C<Business::ISSN> modules, respectively. Business::ISBN versions between 2 and | ||||||||||||||||||||||||||||||||||||||||||
| 893 | 2.02_01 are incompatible with MARC::Lint. | ||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||
| 895 | =item * check_041 cleanup | ||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||
| 897 | Splitting subfield code strings every 3 chars could probably be written more efficiently. | ||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||
| 899 | =item * check_245 cleanup | ||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||
| 901 | The article checking in particular. | ||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||
| 903 | =item * Method for turning off checks | ||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||
| 905 | Provide a way for users to skip checks more easily when using check_record, or a | ||||||||||||||||||||||||||||||||||||||||||
| 906 | specific check_xxx method (e.g. skip article checking). | ||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||||||||||||
| 910 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||
| 912 | This code may be distributed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||
| 914 | Please note that these modules are not products of or supported by the | ||||||||||||||||||||||||||||||||||||||||||
| 915 | employers of the various contributors to the code. | ||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||
| 919 | # Used only to read the stuff from __DATA__ | ||||||||||||||||||||||||||||||||||||||||||
| 920 | 6 | ▶ | sub _read_rules { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_rules: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 921 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||
| 923 | 6 | my $tell = tell(DATA); # Stash the position so we can reset it for next time | |||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||
| 925 | 6 | local $/ = ""; | |||||||||||||||||||||||||||||||||||||||||
| 926 | 6 | ▶ | while ( my $tagblock = <DATA> ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 927 | 1464 | my @lines = split( /\n/, $tagblock ); | |||||||||||||||||||||||||||||||||||||||||
| 928 | 1464 | s/\s+$// for @lines; | |||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||
| 930 | 1464 | ▶ | next unless @lines >= 4; # Some of our entries are tag-only | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||
| 932 | 1362 | my $tagline = shift @lines; | |||||||||||||||||||||||||||||||||||||||||
| 933 | 1362 | my @keyvals = split( /\s+/, $tagline, 3 ); | |||||||||||||||||||||||||||||||||||||||||
| 934 | 1362 | my $tagno = shift @keyvals; | |||||||||||||||||||||||||||||||||||||||||
| 935 | 1362 | my $repeatable = shift @keyvals; | |||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||
| 937 | 1362 | $self->_parse_tag_rules( $tagno, $repeatable, @lines ); | |||||||||||||||||||||||||||||||||||||||||
| 938 | } # while | ||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||
| 940 | # Set the pointer back to where it was, in case we do this again | ||||||||||||||||||||||||||||||||||||||||||
| 941 | 6 | seek( DATA, $tell, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 942 | } | ||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||
| 944 | 1362 | ▶ | sub _parse_tag_rules { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_tag_rules: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 945 | 1362 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 946 | 1362 | my $tagno = shift; | |||||||||||||||||||||||||||||||||||||||||
| 947 | 1362 | my $repeatable = shift; | |||||||||||||||||||||||||||||||||||||||||
| 948 | 1362 | my @lines = @_; | |||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||
| 950 | 1362 | ▶ | my $rules = ($self->{_rules}->{$tagno} ||= {}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_rules"}{$tagno} ||= {}
MC/DC0%0/1
$self->{"_rules"}{$tagno} ||= {}
$self->{"_rules"}{$tagno}
Truth table50%1/2
A
A= $self->{"_rules"}{$tagno}
| |||||||||||||||||||||||||||||||||||||||||||
| 951 | 1362 | $rules->{'repeatable'} = $repeatable; | |||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||
| 953 | 1362 | for my $line ( @lines ) { | |||||||||||||||||||||||||||||||||||||||||
| 954 | 17190 | my @keyvals = split( /\s+/, $line, 3 ); | |||||||||||||||||||||||||||||||||||||||||
| 955 | 17190 | my $key = shift @keyvals; | |||||||||||||||||||||||||||||||||||||||||
| 956 | 17190 | my $val = shift @keyvals; | |||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||
| 958 | # Do magic for indicators | ||||||||||||||||||||||||||||||||||||||||||
| 959 | 17190 | ▶ | if ( $key =~ /^ind/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 960 | 2724 | $rules->{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||
| 962 | 2724 | my $desc; | |||||||||||||||||||||||||||||||||||||||||
| 963 | my $regex; | ||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||
| 965 | 2724 | ▶ | if ( $val eq "blank" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 966 | 1674 | $desc = "blank"; | |||||||||||||||||||||||||||||||||||||||||
| 967 | 1674 | $regex = qr/^ $/; | |||||||||||||||||||||||||||||||||||||||||
| 968 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 969 | 1050 | $desc = _nice_list($val); | |||||||||||||||||||||||||||||||||||||||||
| 970 | 1050 | $val =~ s/^b/ /; | |||||||||||||||||||||||||||||||||||||||||
| 971 | 1050 | $regex = qr/^[$val]$/; | |||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||
| 974 | 2724 | $rules->{$key."_desc"} = $desc; | |||||||||||||||||||||||||||||||||||||||||
| 975 | 2724 | $rules->{$key."_regex"} = $regex; | |||||||||||||||||||||||||||||||||||||||||
| 976 | } # if indicator | ||||||||||||||||||||||||||||||||||||||||||
| 977 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 978 | 14466 | ▶ | if ( $key =~ /(.)-(.)/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | my ($min,$max) = ($1,$2); | |||||||||||||||||||||||||||||||||||||||||
| 980 | 0 | $rules->{$_} = $val for ($min..$max); | |||||||||||||||||||||||||||||||||||||||||
| 981 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 982 | 14466 | $rules->{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||||||||||||||
| 984 | } # not an indicator | ||||||||||||||||||||||||||||||||||||||||||
| 985 | } # for $line | ||||||||||||||||||||||||||||||||||||||||||
| 986 | } | ||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||
| 989 | 1050 | ▶ | sub _nice_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_nice_list: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 990 | 1050 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||
| 992 | 1050 | ▶ | if ( $str =~ s/(\d)-(\d)/$1 thru $2/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 993 | 60 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 994 | } | ||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||
| 996 | 990 | my @digits = split( //, $str ); | |||||||||||||||||||||||||||||||||||||||||
| 997 | 990 | ▶ | $digits[0] = "blank" if $digits[0] eq "b"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 998 | 990 | my $last = pop @digits; | |||||||||||||||||||||||||||||||||||||||||
| 999 | 990 | return join( ", ", @digits ) . " or $last"; | |||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||
| 1002 | 0 | ▶ | sub _ind_regex { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ind_regex: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1003 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||||||||||||||||
| 1005 | 0 | ▶ | return qr/^ $/ if $str eq "blank"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||
| 1007 | 0 | return qr/^[$str]$/; | |||||||||||||||||||||||||||||||||||||||||
| 1008 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||
| 1011 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||
| 1013 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||