| 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
| |||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $params->{"register_function"} and ref $params->{"register_function"} eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $xml and $xml->isa("GLOB")
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")
| |||||||||||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||
| 98 | 0 | $xsltStylesheet = $xmlParser->parse_string($template, $base); | |||||||||||||||||||||||||||||||||||
| 99 | ▶ | } elsif (ref($template) && $template->isa('GLOB')) { | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $template and $template->isa("GLOB")
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")
| |||||||||||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||