BIBFRAME2MARC.pm

filter: Statementstmt 90.4% 19 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 92.8% 26 / 28 CC 1 SCAR 0.4
CC
1
Cov
90%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« BIBFRAME2MARC/Utils.pm ↑ Summary
1 package NKC::Transform::BIBFRAME2MARC;
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::Share ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 0 ▶use XML::LibXSLT;
Subroutine BEGIN: called CC=1 SCAR=2.6
11  
12 our $VERSION = 0.07;
13  
14 sub new {
15 my ($class, @params) = @_;
16  
17 # Create object.
18 my $self = bless {}, $class;
19  
20 # Version of transformation.
21 $self->{'version'} = '3.0.0';
22  
23 # XSLT transformation file.
24 $self->{'xslt_transformation_file'} = undef;
25  
26 # Process parameters.
27 set_params($self, @params);
28  
29 if (! defined $self->{'xslt_transformation_file'}) {
30 if (! defined $self->{'version'}) {
31 err "Parameter 'version' is undefined.";
32 }
33 $self->{'xslt_transformation_file'} = dist_file('NKC-Transform-BIBFRAME2MARC',
34 'bibframe2marc-'.$self->{'version'}.'.xsl');
35 }
36  
37 if (! -r $self->{'xslt_transformation_file'}) {
38 err "Cannot read XSLT file.",
39 'XSLT file', $self->{'xslt_transformation_file'},
40 ;
41 }
42  
43 $self->{'_xml_parser'} = XML::LibXML->new;
44 $self->{'_xslt'} = XML::LibXSLT->new;
45  
46 return $self;
47 }
48  
49 sub version {
50 my $self = shift;
51  
52 my $dom = $self->{'_xml_parser'}->load_xml('location' => $self->{'xslt_transformation_file'});
53  
54 my $version = $dom->findvalue('//xsl:variable[@name="vCurrentVersion"]');
55 $version =~ s/\s*DLC\s+bibframe2marc\s*//ms;
56 $version =~ s/^v//ms;
57  
58 return $version;
59 }
60  
61 sub transform {
62 my ($self, $bf_xml, @params) = @_;
63  
64 my $bf_xml_input = $self->{'_xml_parser'}->load_xml('string' => $bf_xml);
65 my $style_doc = $self->{'_xml_parser'}->parse_file($self->{'xslt_transformation_file'});
66  
67 my $stylesheet = $self->{'_xslt'}->parse_stylesheet($style_doc);
68  
69 my $results = $stylesheet->transform($bf_xml_input, @params);
70  
71 return $stylesheet->output_string($results);
72 }
73  
74 1;
75  
76 __END__
« BIBFRAME2MARC/Utils.pm ↑ Summary