Moose/Parser/Iso2709.pm

filter: Statementstmt 100% 55 / 55 Branchbran 68.7% 11 / 16 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 93.7% 75 / 80 CC 11 SCAR 20.7
CC
11
Cov
93%
__ANON__
11.1
BEGIN
1.0
BEGIN
1.0
CRAP 7.9
« Moose/Lint/Processor.pm ↑ Summary Moose/Parser/Yaml.pm »
1 package MARC::Moose::Parser::Iso2709;
2 # ABSTRACT: Parser for ISO2709 records
3 4 $MARC::Moose::Parser::Iso2709::VERSION = '1.0.46';
4 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 require bytes;
7  
8 4 extends 'MARC::Moose::Parser';
9  
10 4 ▶use MARC::Moose::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use MARC::Moose::Field::Control;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use MARC::Moose::Field::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 # FIXME Experimental. Not used yet.
16 #has converter => (
17 # is => 'rw',
18 # isa => 'Text::IconvPtr',
19 # default => sub { Text::Iconv->new( "cp857", "utf8" ) }
20 #);
21  
22  
23  
24 override 'parse' => sub {
25 4 ▶ my ($self, $raw) = @_;
Subroutine __ANON__: called CC=11 SCAR=24.1
26  
27 4 ▶ return unless $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $raw 0 4 4
28 4 ▶ my $utf8_flag = utf8::is_utf8($raw) || 1;
Condition100%2/2
utf8::is_utf8($raw) || 1
l!l
22
MC/DC100%1/1
utf8::is_utf8($raw) || 1
utf8::is_utf8($raw)
Truth table100%2/2
A
A= utf8::is_utf8($raw)
Aresult
11
00
29  
30 4 my $record = MARC::Moose::Record->new();
31  
32 4 my $leader = substr($raw, 0, 24);
33 4 $record->_leader( $leader );
34  
35 4 $raw = substr($raw, 24);
36 4 my $directory_len = substr($leader, 12, 5) - 25;
37 4 my $directory = substr $raw, 0, $directory_len;
38 4 my $content = substr($raw, $directory_len+1);
39 4 my $number_of_tag = $directory_len / 12;
40 4 my @fields;
41 4 ▶ for (my $i = 0; $i < $number_of_tag; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $number_of_tag) 76 4 80
42 76 my $off = $i * 12;
43 76 my $tag = substr($directory, $off, 3);
44 76 ▶ next if $tag !~ /^[a-zA-Z0-9]*$/; # FIXME: it happens!
Branch: 1 branch
BranchTrueFalseTotal
unless $tag =~ /^[a-zA-Z0-9]*$/u 0 76 76
45 76 my $len = substr($directory, $off+3, 4) - 1;
46 76 my $pos = substr($directory, $off+7, 5) + 0;
47 76 my $value = bytes::substr($content, $pos, $len);
48 76 ▶ utf8::decode($value) if $utf8_flag;
Branch: 1 branch
BranchTrueFalseTotal
if $utf8_flag 76 0 76
49 76 ▶ next unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 76 76
50 #$value = $self->converter->convert($value);
51 76 ▶ if ( $value =~ /\x1F/ ) { # There are some letters
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /\x1F/u) { } 59 17 76
52 59 my $i1 = substr($value, 0, 1);
53 59 my $i2 = substr($value, 1, 1);
54 59 $value = substr($value, 2);
55 59 my @sf;
56 59 for ( split /\x1F/, $value) {
57 160 ▶ next if length($_) < 2;
Branch: 1 branch
BranchTrueFalseTotal
if length $_ < 2 59 101 160
58 101 push @sf, [ substr($_, 0, 1), substr($_, 1) ];
59 }
60 59 push @fields, MARC::Moose::Field::Std->new(
61 tag => $tag, ind1 => $i1, ind2 => $i2, subf => \@sf );
62 }
63 else {
64 17 push @fields, MARC::Moose::Field::Control->new( tag => $tag, value => $value );
65 }
66 }
67 4 $record->fields( \@fields );
68 4 ▶ $record->lint($self->lint) if $self->lint;
Branch: 1 branch
BranchTrueFalseTotal
if $self->lint 0 4 4
69 4 return $record;
70 4 };
71  
72 4 __PACKAGE__->meta->make_immutable;
73  
74 4 1;
75  
76 __END__
77  
78 =pod
79  
80 =encoding UTF-8
81  
82 =head1 NAME
83  
84 MARC::Moose::Parser::Iso2709 - Parser for ISO2709 records
85  
86 =head1 VERSION
87  
88 version 1.0.46
89  
90 =head1 DESCRIPTION
91  
92 Override L<MARC::Moose::Parser> to parse ISO2709 MARC records.
93  
94 =head1 SEE ALSO
95  
96 =over 4
97  
98 =item *
99  
100 L<MARC::Moose>
101  
102 =item *
103  
104 L<MARC::Moose::Parser>
105  
106 =back
107  
108 =head1 AUTHOR
109  
110 Frédéric Demians <f.demians@tamil.fr>
111  
112 =head1 COPYRIGHT AND LICENSE
113  
114 This software is copyright (c) 2022 by Frédéric Demians.
115  
116 This is free software; you can redistribute it and/or modify it under
117 the same terms as the Perl 5 programming language system itself.
118  
119 =cut
« Moose/Lint/Processor.pm ↑ Summary Moose/Parser/Yaml.pm »