line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MARC::Moose::Formater::Json; |
2
|
|
|
|
|
|
|
# ABSTRACT: Record formater into a Json representation |
3
|
|
|
|
|
|
|
$MARC::Moose::Formater::Json::VERSION = '1.0.45'; |
4
|
4
|
|
|
4
|
|
32
|
use Moose; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'MARC::Moose::Formater'; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
25982
|
use MARC::Moose::Field::Control; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
137
|
|
9
|
4
|
|
|
4
|
|
26
|
use MARC::Moose::Field::Std; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
103
|
|
10
|
4
|
|
|
4
|
|
4113
|
use JSON; |
|
4
|
|
|
|
|
48551
|
|
|
4
|
|
|
|
|
23
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has pretty => ( is => 'rw', isa => 'Bool', default => 0 ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
override 'format' => sub { |
15
|
|
|
|
|
|
|
my ($self, $record) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $rec = { |
18
|
|
|
|
|
|
|
leader => $record->leader, |
19
|
|
|
|
|
|
|
fields => [ map { |
20
|
|
|
|
|
|
|
$_->tag, |
21
|
|
|
|
|
|
|
( ref($_) eq 'MARC::Moose::Field::Control' |
22
|
|
|
|
|
|
|
? $_->value |
23
|
|
|
|
|
|
|
: { |
24
|
|
|
|
|
|
|
ind1 => $_->ind1, |
25
|
|
|
|
|
|
|
ind2 => $_->ind2, |
26
|
|
|
|
|
|
|
subfields => [ map { ($_->[0], $_->[1]) } @{$_->subf} ], |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
} @{ $record->fields } ], |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
return to_json($rec, { pretty => $self->pretty } ) . ",\n"; |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__END__ |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=pod |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=encoding UTF-8 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
MARC::Moose::Formater::Json - Record formater into a Json representation |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 VERSION |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
version 1.0.45 |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
The resulting JSON string representing a MARC::Moose::Record conforms to the |
55
|
|
|
|
|
|
|
following schema: |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
L<http://dilettantes.code4lib.org/files/marc-schema.json> |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Further details can be found at: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
L<http://dilettantes.code4lib.org/blog/2010/09/a-proposal-to-serialize-marc-in-json/> |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 pretty |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
A boolean value. If true, the resulting JSON string is prettier. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSYS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
use MARC::Moose::Reader::File::Iso2709; |
72
|
|
|
|
|
|
|
use MARC::Moose::Formater::Json; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $reader = MARC::Moose::Reader::File::Iso2709->new( file => 'marc.iso' ); |
75
|
|
|
|
|
|
|
my $formater = MARC::Moose::Formater::Json->new( pretty => 1); |
76
|
|
|
|
|
|
|
while ( my $record = $reader->read() ) { |
77
|
|
|
|
|
|
|
print $formater->format($record); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SEE ALSO |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=over 4 |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item * |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
L<MARC::Moose> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item * |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L<MARC::Moose::Formater> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item * |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
L<MARC::Moose::Parser> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=back |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHOR |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Frédéric Demians <f.demians@tamil.fr> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This software is copyright (c) 2022 by Frédéric Demians. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
107
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |