View/XSLT/XML/LibXSLT.pm

filter: Statementstmt 30.0% 15 / 50 Branchbran 6.2% 1 / 16 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 75.0% 3 / 4 Podpod 100% 2 / 2 totaltotal 20.5% 21 / 102 CC 16 SCAR 44.1
CC
16
Cov
19%
process
132.0
new
19.1
BEGIN
1.0
CRAP 82.6
↑ Summary View/XSLT.pm »
1 package Catalyst::View::XSLT::XML::LibXSLT;
2  
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 13 our $VERSION = '0.09';
7  
8 =head1 NAME
9  
10 Catalyst::View::XSLT::XML::LibXSLT - An implementation for Catalyst::View::XSLT
11 with XML::LibXSLT
12  
13 =head1 SYNOPSIS
14  
15 This module is meant to be used internally by L<Catalyst::View::XSLT>.
16  
17 =head1 METHODS
18  
19 =over 4
20  
21 =item new
22  
23 Returns a new instance of XML::LibXSLT view implementation
24  
25 =cut
26  
27 sub new
28 25 ▶{
Subroutine new: called CC=6 SCAR=29.5
Pod documented
29 25 my ($proto, $c, $params) = @_;
30  
31 25 eval {
32  
33 25 require XML::LibXML;
34 25 require XML::LibXSLT;
35  
36 0 XML::LibXML->import;
37 0 XML::LibXSLT->import;
38 };
39  
40 25 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 25 0 25
41 25 $c->error('Could not use XML::LibXSLT: ' . $@);
42 25 return undef;
43 }
44  
45 0 ▶ if (exists $params->{register_function}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{"register_function"} and ref $params->{"register_function"} eq "ARRAY") 0 0 0
Condition0%0/3
exists $params->{"register_function"} and ref $params->{"register_function"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $params->{"register_function"} and ref $params->{"register_function"} eq "ARRAY"
exists $params->{"register_function"} ref $params->{"register_function"} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $params->{"register_function"}B= ref $params->{"register_function"} eq "ARRAY"
ABresult
0X0
100
111
46 and ref($params->{register_function}) eq 'ARRAY') {
47  
48 0 my $register_subs = $params->{register_function};
49  
50 0 foreach my $hrefSubConf (@{ $register_subs }) {
51 XML::LibXSLT->register_function(
52 $hrefSubConf->{uri},
53 $hrefSubConf->{name},
54 $hrefSubConf->{subref},
55 0 );
56 }
57  
58 }
59  
60 0 ▶ my $class = ref $proto || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
61  
62 0 my $self = {};
63  
64 0 bless($self, $class);
65  
66 0 return $self;
67  
68 }
69  
70 =item process
71  
72 =cut
73  
74 0 ▶sub process {
Subroutine process: not called CC=11 SCAR=48.8
Pod documented
75 0 my ($self, $template, $args, $base) = @_;
76  
77 0 my ($result, $error) = ('', undef);
78  
79 0 eval {
80 0 my $xmlParser = XML::LibXML->new();
81 0 my $xsltProcessor = XML::LibXSLT->new();
82  
83 0 my ($xmlDocument, $xsltStylesheet);
84  
85 0 my $xml = delete $args->{xml};
86  
87 0 ▶ if (ref($xml) && $xml->isa('GLOB')) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $xml and $xml->isa('GLOB')) { } 0 0 0
elsif (ref $xml and $xml->isa('XML::LibXML::Document')) { } 0 0 0
elsif ($xml =~ /\</) { } 0 0 0
Condition0%0/3
ref $xml and $xml->isa("GLOB")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $xml and $xml->isa("GLOB")
ref $xml $xml->isa("GLOB")
Truth table0%0/3
A and B
A= ref $xmlB= $xml->isa("GLOB")
ABresult
0X0
100
111
88 0 $xmlDocument = $xmlParser->parse_fh($xml);
89 ▶ } elsif (ref($xml) && $xml->isa('XML::LibXML::Document')) {
Condition0%0/3
ref $xml and $xml->isa("XML::LibXML::Document")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $xml and $xml->isa("XML::LibXML::Document")
ref $xml $xml->isa("XML::LibXML::Document")
Truth table0%0/3
A and B
A= ref $xmlB= $xml->isa("XML::LibXML::Document")
ABresult
0X0
100
111
90 0 $xmlDocument = $xml;
91 } elsif ($xml =~ m/\</) {
92 0 $xmlDocument = $xmlParser->parse_string($xml);
93 } else {
94 0 $xmlDocument = $xmlParser->parse_file($xml);
95 }
96  
97 0 ▶ if ($template =~ m/\</) {
Branch: 3 branches
BranchTrueFalseTotal
if ($template =~ /\</) { } 0 0 0
elsif (ref $template and $template->isa('GLOB')) { } 0 0 0
elsif (ref $template and $template->isa('XML::LibXML::Document')) { } 0 0 0
98 0 $xsltStylesheet = $xmlParser->parse_string($template, $base);
99 ▶ } elsif (ref($template) && $template->isa('GLOB')) {
Condition0%0/3
ref $template and $template->isa("GLOB")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $template and $template->isa("GLOB")
ref $template $template->isa("GLOB")
Truth table0%0/3
A and B
A= ref $templateB= $template->isa("GLOB")
ABresult
0X0
100
111
100 0 $xsltStylesheet = $xmlParser->parse_fh($template, $base);
101 ▶ } elsif (ref($template) && $template->isa('XML::LibXML::Document')) {
Condition0%0/3
ref $template and $template->isa("XML::LibXML::Document")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $template and $template->isa("XML::LibXML::Document")
ref $template $template->isa("XML::LibXML::Document")
Truth table0%0/3
A and B
A= ref $templateB= $template->isa("XML::LibXML::Document")
ABresult
0X0
100
111
102 0 $xsltStylesheet = $template;
103 } else {
104 0 $xsltStylesheet = $xmlParser->parse_file($template);
105 }
106  
107 0 my $xsltTransformer = $xsltProcessor->parse_stylesheet($xsltStylesheet);
108  
109 0 my %params = XML::LibXSLT::xpath_to_string( %{$args} );
110  
111 0 my $results = $xsltTransformer->transform($xmlDocument, %params);
112  
113 0 $result = $xsltTransformer->output_string($results);
114  
115 };
116  
117 0 $error = $@;
118  
119 0 return ($result, $error);
120 }
121  
122 =back
123  
124 =head1 SEE ALSO
125  
126 L<Catalyst>, L<Catalyst::Base>, L<XML::LibXSLT>
127  
128 =head1 AUTHORS
129  
130 Martin Grigorov, E<lt>mcgregory {at} e-card {dot} bgE<gt>
131  
132 Simon Bertrang, E<lt>simon.bertrang@puzzworks.comE<gt>
133  
134 =head1 COPYRIGHT
135  
136 This program is free software, you can redistribute it and/or modify it
137 under the same terms as Perl itself.
138  
139 =cut
140  
141 13 1;
↑ Summary View/XSLT.pm »