blib/lib/NKC/Transform/MARC2BIBFRAME.pm

filter: Statementstmt 91.6% 22 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 93.7% 30 / 32 CC 1 SCAR 0.4
CC
1
Cov
92%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package NKC::Transform::MARC2BIBFRAME;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use File::Spec::Functions qw(catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use File::Share ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 0 ▶use XML::LibXSLT;
Subroutine BEGIN: called CC=1 SCAR=2.6
12  
13 our $VERSION = 0.05;
14  
15 sub new {
16 my ($class, @params) = @_;
17  
18 # Create object.
19 my $self = bless {}, $class;
20  
21 # Version of transformation.
22 $self->{'version'} = '3.0.0';
23  
24 # XSLT transformation file.
25 $self->{'xslt_transformation_file'} = undef;
26  
27 # Process parameters.
28 set_params($self, @params);
29  
30 if (! defined $self->{'xslt_transformation_file'}) {
31 if (! defined $self->{'version'}) {
32 err "Parameter 'version' is undefined.";
33 }
34 $self->{'xslt_transformation_file'} = dist_file('NKC-Transform-MARC2BIBFRAME',
35 catfile($self->{'version'}, 'marc2bibframe2.xsl'));
36 }
37  
38 if (! -r $self->{'xslt_transformation_file'}) {
39 err "Cannot read XSLT file.",
40 'XSLT file', $self->{'xslt_transformation_file'},
41 ;
42 }
43  
44 $self->{'_xml_parser'} = XML::LibXML->new;
45 $self->{'_xslt'} = XML::LibXSLT->new;
46  
47 return $self;
48 }
49  
50 sub version {
51 my $self = shift;
52  
53 my $dom = $self->{'_xml_parser'}->load_xml(
54 'location' => dist_file('NKC-Transform-MARC2BIBFRAME', catfile($self->{'version'}, 'variables.xsl')),
55 );
56  
57 my $version = $dom->findvalue('//xsl:variable[@name="vCurrentVersion"]');
58 $version =~ s/^v//ms;
59  
60 return $version;
61 }
62  
63 sub transform {
64 my ($self, $marc_xml, @params) = @_;
65  
66 my $marc_xml_input = $self->{'_xml_parser'}->load_xml('string' => $marc_xml);
67 my $style_doc = $self->{'_xml_parser'}->parse_file($self->{'xslt_transformation_file'});
68  
69 my $stylesheet = $self->{'_xslt'}->parse_stylesheet($style_doc);
70  
71 my $results = $stylesheet->transform($marc_xml_input, @params);
72  
73 return $stylesheet->output_string($results);
74 }
75  
76 1;
77  
78 =pod
79  
80 =encoding utf8
81  
82 =head1 NAME
83  
84 NKC::Transform::MARC2BIBFRAME - marc2bibframe transformation class.
85  
86 =head1 SYNOPSIS
87  
88 use NKC::Transform::MARC2BIBFRAME;
89  
90 my $obj = NKC::Transform::MARC2BIBFRAME->new(%params);
91 my $version = $obj->version;
92 my $bf_xml = $obj->transform($marc_xml, @params);
93  
94 =head1 METHODS
95  
96 =head2 C<new>
97  
98 my $obj = NKC::Transform::MARC2BIBFRAME->new(%params);
99  
100 Constructor.
101  
102 =over 8
103  
104 =item * C<version>
105  
106 Transformation version.
107  
108 Default value is '3.0.0'.
109  
110 Possible versions are: '2.5.0', '2.9.0', '2.10.0' and '3.0.0'.
111  
112 Default value is undef.
113  
114 =item * C<xslt_transformation_file>
115  
116 XSLT transformation file.
117  
118 Default value is XSLT transformation file for '3.0.0' version.
119  
120 =back
121  
122 Returns instance of object.
123  
124 =head2 C<version>
125  
126 my $version = $obj->version;
127  
128 Get marc2bibframe transformation version which is set to object.
129  
130 Returns qr{\d\.\d\.\d} version string.
131  
132 =head2 C<transform>
133  
134 my $bf_xml = $obj->transform($mar_xml, @params);
135  
136 Transform MARC to BIBFRAME.
137  
138 Returns BIBFRAME XML string.
139  
140 new():
141 Cannot read XSLT file.
142 XSLT file: %s
143 Parameter 'version' is undefined.
144 From Class::Utils::set_params():
145 Unknown parameter '%s'.
146  
147 =head1 DEPENDENCIES
148  
149 L<Class::Utils>,
150 L<Error::Pure>,
151 L<File::Spec::Functions>,
152 L<File::Share>,
153 L<XML::LibXML>,
154 L<XML::LibXSLT>.
155  
156 =head1 SEE ALSO
157  
158 =over
159  
160 =item L<NKC::Transform::BIBFRAME2MARC>
161  
162 bibframe2marc transformation class.
163  
164 =item L<NKC::Transform::MARC2RDA>
165  
166 marc2rda transformation class.
167  
168 =item L<NKC::Transform::BIBFRAME2MARC::Utils>
169  
170 Utilities for bibframe2marc transformations.
171  
172 =back
173  
174 =head1 REPOSITORY
175  
176 L<https://github.com/michal-josef-spacek/NKC-Transform-MARC2BIBFRAME>
177  
178 =head1 LICENSE AND COPYRIGHT
179  
180 © 2024-2026 Michal Josef Špaček
181  
182 BSD 2-Clause License
183  
184 =head1 ACKNOWLEDGEMENTS
185  
186 Development of this software has been made possible by institutional support
187 for the long-term strategic development of the National Library of the Czech
188 Republic as a research organization provided by the Ministry of Culture of
189 the Czech Republic (DKRVO 2024–2028), Area 11: Linked Open Data.
190  
191 =head1 VERSION
192  
193 0.05
194  
195 =cut
↑ Summary