| 1 | package MARC::Moose::Formater::Json; | ||||||||||
| 2 | # ABSTRACT: Record formater into a Json representation | ||||||||||
| 3 | 4 | $MARC::Moose::Formater::Json::VERSION = '1.0.46'; | |||||||||
| 4 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 4 | extends 'MARC::Moose::Formater'; | |||||||||
| 7 | |||||||||||
| 8 | 4 | ▶ | use MARC::Moose::Field::Control; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | ▶ | use MARC::Moose::Field::Std; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 4 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 4 | has pretty => ( is => 'rw', isa => 'Bool', default => 0 ); | |||||||||
| 13 | |||||||||||
| 14 | override 'format' => sub { | ||||||||||
| 15 | 0 | ▶ | my ($self, $record) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 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 | 0 | ▶ | subfields => [ map { ($_->[0], $_->[1]) } @{$_->subf} ], | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | } | ||||||||||
| 28 | ); | ||||||||||
| 29 | 0 | } @{ $record->fields } ], | |||||||||
| 30 | }; | ||||||||||
| 31 | 0 | return to_json($rec, { pretty => $self->pretty } ) . ",\n"; | |||||||||
| 32 | 4 | }; | |||||||||
| 33 | |||||||||||
| 34 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 35 | |||||||||||
| 36 | 4 | 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.46 | ||||||||||
| 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 | ||||||||||