| 1 | package PICA::Writer::XML; | ||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use v5.14.1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 8 | our $VERSION = '1.18'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use XML::Writer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use parent 'PICA::Writer::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub namespace { | ||||||||||||||||||||||||||||
| 12 | 1 | ▶ | 'info:srw/schema/5/picaXML-v1.0'; | ||||||||||||||||||||||||||
|
Subroutine
namespace: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub new { | ||||||||||||||||||||||||||||
| 16 | 1 | ▶ | my $self = PICA::Writer::Base::new(@_); | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | $self->{writer} = XML::Writer->new( | ||||||||||||||||||||||||||||
| 18 | OUTPUT => $self->{fh}, | ||||||||||||||||||||||||||||
| 19 | 1 | DATA_MODE => 1, | |||||||||||||||||||||||||||
| 20 | DATA_INDENT => 2 | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | 1 | $self->{writer}->xmlDecl('UTF-8'); | |||||||||||||||||||||||||||
| 23 | 1 | $self->{writer}->startTag('collection', xmlns => $self->namespace); | |||||||||||||||||||||||||||
| 24 | 1 | $self; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub write_record { | ||||||||||||||||||||||||||||
| 28 | 1 | ▶ | my ($self, $record) = @_; | ||||||||||||||||||||||||||
|
Subroutine
write_record: called CC=14 SCAR=33.6
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | $record = $record->{record} if reftype $record eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | my $writer = $self->{writer}; | |||||||||||||||||||||||||||
| 32 | 1 | ▶ | my $schema = $self->{schema} // {field => {}}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"schema"} // {"field", {}}
MC/DC0%0/1
$self->{"schema"} // {"field", {}}
$self->{"schema"}
Truth table50%1/2
A
A= $self->{"schema"}
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | $writer->startTag('record'); | |||||||||||||||||||||||||||
| 35 | 1 | foreach my $field (@$record) { | |||||||||||||||||||||||||||
| 36 | 1 | my $id = $field->[0]; | |||||||||||||||||||||||||||
| 37 | 1 | my @attr = (tag => $field->[0]); | |||||||||||||||||||||||||||
| 38 | 1 | ▶ | if (defined $field->[1] && $field->[1] ne '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $field->[1] and $field->[1] ne ""
MC/DC0%0/2
defined $field->[1] and $field->[1] ne ""
defined $field->[1]
$field->[1] ne ""
Truth table33%1/3
A and B
A= defined $field->[1]B= $field->[1] ne ""
| |||||||||||||||||||||||||||||
| 39 | 0 | push @attr, occurrence => $field->[1]; | |||||||||||||||||||||||||||
| 40 | 0 | $id = "$id/" . $field->[1]; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 1 | my $fielddef = $schema->{fields}{$id}; | |||||||||||||||||||||||||||
| 43 | 1 | my $sfdef; | |||||||||||||||||||||||||||
| 44 | 1 | ▶ | if ($fielddef) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | foreach (qw(label url pica3)) { | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | if (defined $fielddef->{$_}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | push @attr, $_ => $fielddef->{$_}; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 0 | $sfdef = $fielddef->{subfields}; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 1 | $writer->startTag('datafield', @attr); | |||||||||||||||||||||||||||
| 53 | 1 | ▶ | for (my $i = 3; $i < scalar @$field; $i += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 1 | my $code = $field->[$i - 1]; | |||||||||||||||||||||||||||
| 55 | 1 | my $value = $field->[$i]; | |||||||||||||||||||||||||||
| 56 | 1 | my @attr = (code => $code); | |||||||||||||||||||||||||||
| 57 | 1 | ▶ | if ($sfdef && $sfdef->{$code}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$sfdef and $sfdef->{$code}
MC/DC0%0/2
$sfdef and $sfdef->{$code}
$sfdef
$sfdef->{$code}
Truth table33%1/3
A and B
A= $sfdefB= $sfdef->{$code}
| |||||||||||||||||||||||||||||
| 58 | 0 | foreach (qw(label url pica3)) { | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | if (defined $sfdef->{$code}{$_}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | push @attr, $_ => $sfdef->{$code}{$_}; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 1 | $writer->dataElement('subfield', $value, @attr); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 1 | $writer->endTag('datafield'); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 1 | $writer->endTag('record'); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub end { | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
end: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | $self->{writer}->endTag('collection'); | |||||||||||||||||||||||||||
| 74 | 0 | $self->{writer}->end(); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 8 | 1; | |||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||