PNX.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 41 CC 1 SCAR 6.9
CC
1
Cov
0%
BUILD
2.0
parse
2.0
to_xml
2.0
CRAP 2.0
1 package Catmandu::PNX;
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Catmandu::PNX - Modules for handling PNX data within the Catmandu framework
8  
9 =head1 SYNOPSIS
10  
11 Command line client C<catmandu>:
12  
13 catmandu convert PNX to JSON --fix myfixes.txt < data/pnx.xml > data/pnx.json
14  
15 catmandu convert JSON to PNX --fix myfixes.txt < data/pnx.json > data/pnx.xml
16  
17 See documentation of modules for more examples.
18  
19 =head1 DESCRIPTION
20  
21 Catmandu::PNX contains modules to handle PNX an
22 XML Schema for Ex Libris' Primo search engine.
23  
24 =head1 AVAILABLE MODULES
25  
26 =over
27  
28 =item L<Catmandu::Exporter::PNX>
29  
30 Serialize PNX data
31  
32 =item L<Catmandu::Importer::PNX>
33  
34 Parse PNX data
35  
36 =back
37  
38 =head1 SEE ALSO
39  
40 This module is based on the L<Catmandu> framework and L<XML::Compile>.
41 For more information on Catmandu visit: http://librecat.org/Catmandu/
42 or follow the blog posts at: https://librecatproject.wordpress.com/
43  
44 =head1 DISCLAIMER
45  
46 * I'm not a PNX expert.
47 * This project was created as part of the L<Catmandu> project as an example PNX files can be generated from MARC, EAD and others.
48 * All the heavy work is done by the excellent L<XML::Compile> package.
49 * I invite other developers to contribute to this code.
50  
51 =head1 BUGS, QUESTIONS HELP
52  
53 Use the github issue tracker for any bug reports or questions on this module:
54 https://github.com/LibreCat/Catmandu-PNX/issues
55  
56 =head1 AUTHOR
57  
58 Patrick Hochstenbach, C<< patrick.hochstenbach at ugent.be >>
59  
60 =head1 CONTRIBUTOR
61  
62 Johann Rolschewski, C<< jorol at cpan.org >>
63  
64 =head1 COPYRIGHT AND LICENSE
65  
66 Patrick Hochstenbach, 2016 -
67  
68 This is free software; you can redistribute it and/or modify it under the same
69 terms as the Perl 5 programming language system itself.
70  
71 =cut
72  
73 use Moo;
74  
75 use XML::Compile;
76 use XML::Compile::Schema;
77 use XML::Compile::Util 'pack_type';
78  
79 our $VERSION = '0.04';
80  
81 has '_reader' => (is => 'ro');
82 has '_writer' => (is => 'ro');
83  
84 sub BUILD {
85 my ($self) = @_;
86  
87 XML::Compile->addSchemaDirs(__FILE__);
88  
89 my $schema = XML::Compile::Schema->new();
90  
91 $schema->importDefinitions('pnx.pm');
92  
93 $self->{_reader} = $schema->compile(READER => '{}record' );
94  
95 $self->{_writer} = $schema->compile(WRITER => '{}record' );
96  
97 $schema = undef;
98 }
99  
100 sub parse {
101 my ($self,$input) = @_;
102 $self->_reader->($input);
103 }
104  
105 sub to_xml {
106 my ($self,$data) = @_;
107 my $doc = XML::LibXML::Document->new('1.0', 'UTF-8');
108 my $xml = $self->_writer->($doc, $data);
109 $doc->setDocumentElement($xml);
110 $xml = $doc->toString(1);
111 utf8::decode($xml);
112 $xml;
113 }
114  
115 1;