line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MARC::Moose::Parser::Json; |
2
|
|
|
|
|
|
|
# ABSTRACT: Parser for JSON records |
3
|
|
|
|
|
|
|
$MARC::Moose::Parser::Json::VERSION = '1.0.44'; |
4
|
4
|
|
|
4
|
|
30
|
use Moose; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
29
|
|
5
|
|
|
|
|
|
|
extends 'MARC::Moose::Parser'; |
6
|
4
|
|
|
4
|
|
25409
|
use JSON; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
36
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
override 'parse' => sub { |
10
|
|
|
|
|
|
|
my ($self, $raw) = @_; |
11
|
|
|
|
|
|
|
return unless $raw; |
12
|
|
|
|
|
|
|
my $json = from_json($raw); |
13
|
|
|
|
|
|
|
my @jfields = @{$json->{fields}}; |
14
|
|
|
|
|
|
|
my @fields; |
15
|
|
|
|
|
|
|
while ( @jfields ) { |
16
|
|
|
|
|
|
|
my $tag = shift @jfields; |
17
|
|
|
|
|
|
|
my $value = shift @jfields; |
18
|
|
|
|
|
|
|
if ( ref($value) eq 'HASH' ) { |
19
|
|
|
|
|
|
|
my @subf; |
20
|
|
|
|
|
|
|
my @jsubf = @{$value->{subfields}}; |
21
|
|
|
|
|
|
|
while (@jsubf) { |
22
|
|
|
|
|
|
|
my ($letter, $value) = (shift @jsubf, shift @jsubf); |
23
|
|
|
|
|
|
|
push @subf, [ $letter => $value ]; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
push @fields, MARC::Moose::Field::Std->new( |
26
|
|
|
|
|
|
|
tag => $tag, |
27
|
|
|
|
|
|
|
ind1 => $value->{ind1}, |
28
|
|
|
|
|
|
|
ind2 => $value->{ind2}, |
29
|
|
|
|
|
|
|
subf => \@subf ); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
|
|
|
|
|
|
push @fields, MARC::Moose::Field::Control->new( |
33
|
|
|
|
|
|
|
tag => $tag, value => $value ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
my $record = MARC::Moose::Record->new( |
37
|
|
|
|
|
|
|
leader => $json->{leader}, |
38
|
|
|
|
|
|
|
fields => \@fields ); |
39
|
|
|
|
|
|
|
$record->lint($self->lint) if $record->lint; |
40
|
|
|
|
|
|
|
return $record; |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=pod |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=encoding UTF-8 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
MARC::Moose::Parser::Json - Parser for JSON records |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 VERSION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
version 1.0.44 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SEE ALSO |
61
|
|
|
|
|
|
|
=for :list |
62
|
|
|
|
|
|
|
* L<MARC::Moose> |
63
|
|
|
|
|
|
|
* L<MARC::Moose::Parser> |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 AUTHOR |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Frédéric Demians <f.demians@tamil.fr> |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Frédéric Demians. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
74
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |