lib/MAB2/Writer/XML.pm

filter: Statementstmt 94.7% 36 / 38 Branchbran 75.0% 12 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 87.3% 55 / 63 CC 10 SCAR 14.3
CC
10
Cov
89%
_write_record
7.0
start
3.1
end
2.0
CRAP 4.2
« lib/MAB2/Parser/RAW.pm ↑ Summary lib/MAB2/Writer/RAW.pm »
1 package MAB2::Writer::XML;
2  
3 3 our $VERSION = '0.24';
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 with 'MAB2::Writer::Handle';
8  
9 0 ▶has xml_declaration => ( is => 'ro' , default => sub {0} );
Subroutine __ANON__: not called CC=1 SCAR=1.2
10 0 ▶has collection => ( is => 'ro' , default => sub {0} );
Subroutine __ANON__: not called CC=1 SCAR=1.2
11  
12  
13 2 ▶sub start {
Subroutine start: called CC=3 SCAR=11.3
Pod documented
14 2 my ($self) = @_;
15  
16 2 ▶ print { $self->fh } "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" if $self->xml_declaration;
Branch: 1 branch
BranchTrueFalseTotal
if $self->xml_declaration 2 0 2
17 2 ▶ print { $self->fh }
Branch: 1 branch
BranchTrueFalseTotal
if $self->collection 2 0 2
18 "<datei xmlns=\"http://www.ddb.de/professionell/mabxml/mabxml-1.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.ddb.de/professionell/mabxml/mabxml-1.xsd http://www.d-nb.de/standardisierung/formate/mabxml-1.xsd\">\n" if $self->collection;
19 }
20  
21  
22 4 ▶sub _write_record {
Subroutine _write_record: called CC=7 SCAR=19.5
23 4 my ( $self, $record ) = @_;
24 4 my $fh = $self->fh;
25  
26 4 ▶ if ( $record->[0][0] eq 'LDR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record->[0][0] eq 'LDR') { } 1 3 4
27 1 my $leader = $record->[0];
28 1 ▶ my ( $status, $typ ) = ( $1, $2 )
Branch: 1 branch
BranchTrueFalseTotal
if $leader->[3] =~ /^\d{5}(\w)M2\.0\d*\s*(\w)$/ 1 0 1
29 if $leader->[3] =~ /^\d{5}(\w)M2\.0\d*\s*(\w)$/;
30 1 print $fh
31 "<datensatz typ=\"$typ\" status=\"$status\" mabVersion=\"M2.0\">\n";
32 }
33 else {
34 # default to typ and status
35 3 print $fh "<datensatz typ=\"h\" status=\"n\" mabVersion=\"M2.0\">\n";
36 }
37  
38 4 foreach my $field (@$record) {
39  
40 9 ▶ next if $field->[0] eq 'LDR';
Branch: 1 branch
BranchTrueFalseTotal
if $field->[0] eq "LDR" 1 8 9
41 8 ▶ if ( $field->[2] eq '_' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->[2] eq '_') { } 4 4 8
42 4 print $fh
43 "<feld nr=\"$field->[0]\" ind=\"$field->[1]\">$field->[3]</feld>\n";
44 }
45 else {
46 4 print $fh "<feld nr=\"$field->[0]\" ind=\"$field->[1]\">\n";
47 4 ▶ for ( my $i = 2; $i < scalar @$field; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$field) 6 4 10
48 6 my $value = $field->[ $i + 1 ];
49 6 print $fh " <uf code=\"$field->[$i]\">$value</uf>\n";
50 }
51 4 print $fh "</feld>\n";
52 }
53 }
54 4 print $fh "</datensatz>\n";
55 }
56  
57  
58 2 ▶sub end {
Subroutine end: called CC=2 SCAR=7.1
Pod documented
59 2 my ($self) = @_;
60  
61 2 ▶ print { $self->fh } "</datei>\n" if $self->collection;
Branch: 1 branch
BranchTrueFalseTotal
if $self->collection 2 0 2
62 }
63  
64  
65 3 1;
66  
67 __END__
« lib/MAB2/Parser/RAW.pm ↑ Summary lib/MAB2/Writer/RAW.pm »