line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Renderer::XSLT; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
38184
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1844
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
MojoX::Renderer::XSLT - The great new MojoX::Renderer::XSLT! |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.01 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This module enables a Mojo / Mojolicious app to render output using XSLT stylesheets. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use MojoX::Renderer::XSLT; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub startup { |
25
|
|
|
|
|
|
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$self->types->type(xsl => 'text/html'); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $renderer = MojoX::Renderer::XSLT->build(); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$self->renderer->add_handler(xsl => $renderer); |
32
|
|
|
|
|
|
|
$self->renderer->default_handler('xsl'); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Routes |
35
|
|
|
|
|
|
|
my $r = $self->routes; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
... |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 FUNCTIONS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 _create_xslt |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Used internally only to instantiate a wrapper class which handles the XSLT parsing and transform. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _create_xslt { |
49
|
0
|
|
|
0
|
|
|
my ($self, $class, $params) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
unless ($class =~ /\A[\w:]+\z/) { |
52
|
0
|
|
|
|
|
|
die "invalid xslt_class '$class'"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# class = MojoX::Renderer::XSLT:: + XML::LibXSLT |
56
|
0
|
0
|
|
|
|
|
$class = 'MojoX::Renderer::XSLT::' . $class unless $class =~ m/^MojoX::Renderer::XSLT/; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
eval "require $class"; |
59
|
0
|
0
|
|
|
|
|
die "can't load '$class': $@" if $@; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
return defined($params) ? $class->new($params) : $class->new(); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 build |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This method is used to build an anonymous closure function which can be added as a handler for rendering output. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub build { |
71
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
72
|
0
|
|
|
|
|
|
my %params = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# fallback to XML::LibXSLT as default encoder class if needed |
75
|
0
|
|
0
|
|
|
|
my $xslt_class = $params{xslt_class} || 'XML::LibXSLT'; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $xslt = $class->_create_xslt($xslt_class,\%params); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# return closure which will become render handler |
80
|
|
|
|
|
|
|
return sub { |
81
|
0
|
|
|
0
|
|
|
my ($mojo, $ctx, $output, $options) = @_; |
82
|
|
|
|
|
|
|
# TODO: Should templates be in controller specific dirs? |
83
|
0
|
|
|
|
|
|
my $template = $ctx->app->home->rel_file('templates/' . $options->{template}); |
84
|
0
|
|
|
|
|
|
$$output = $xslt->transform($template,$ctx->stash->{xml}); |
85
|
0
|
|
|
|
|
|
return 1; |
86
|
0
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 AUTHOR |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Bob Faist, C<< >> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 BUGS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
96
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
97
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SUPPORT |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
perldoc MojoX::Renderer::XSLT |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
You can also look for information at: |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=over 4 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
L |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
L |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item * CPAN Ratings |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
L |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item * Search CPAN |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=back |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Copyright 2010 Bob Faist, all rights reserved. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
140
|
|
|
|
|
|
|
under the same terms as Perl itself. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; # End of MojoX::Renderer::XSLT |