line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::View::XSLT::XML::LibXSLT; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
594
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
{ |
29
|
0
|
|
|
0
|
1
|
|
my ($proto, $c, $params) = @_; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
eval { |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
require XML::LibXML; |
34
|
0
|
|
|
|
|
|
require XML::LibXSLT; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
XML::LibXML->import; |
37
|
0
|
|
|
|
|
|
XML::LibXSLT->import; |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if ($@) { |
41
|
0
|
|
|
|
|
|
$c->error('Could not use XML::LibXSLT: ' . $@); |
42
|
0
|
|
|
|
|
|
return undef; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
0
|
|
|
|
if (exists $params->{register_function} |
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 }) { |
|
0
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
XML::LibXSLT->register_function( |
52
|
|
|
|
|
|
|
$hrefSubConf->{uri}, |
53
|
|
|
|
|
|
|
$hrefSubConf->{name}, |
54
|
|
|
|
|
|
|
$hrefSubConf->{subref}, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
0
|
|
|
|
my $class = ref $proto || $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
|
|
|
|
|
|
|
sub process { |
75
|
0
|
|
|
0
|
1
|
|
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
|
0
|
0
|
|
|
|
if (ref($xml) && $xml->isa('GLOB')) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$xmlDocument = $xmlParser->parse_fh($xml); |
89
|
|
|
|
|
|
|
} elsif (ref($xml) && $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
|
0
|
0
|
|
|
|
if ($template =~ m/\</) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$xsltStylesheet = $xmlParser->parse_string($template, $base); |
99
|
|
|
|
|
|
|
} elsif (ref($template) && $template->isa('GLOB')) { |
100
|
0
|
|
|
|
|
|
$xsltStylesheet = $xmlParser->parse_fh($template, $base); |
101
|
|
|
|
|
|
|
} elsif (ref($template) && $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} ); |
|
0
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
1; |