| 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
| |||||||||||
| 17 | 2 | ▶ | print { $self->fh } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 27 | 1 | my $leader = $record->[0]; | |||||||||
| 28 | 1 | ▶ | my ( $status, $typ ) = ( $1, $2 ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 41 | 8 | ▶ | if ( $field->[2] eq '_' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | 3 | 1; | |||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||