line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::XML::LX; |
2
|
1
|
|
|
1
|
|
14083
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
6938
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
756
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
5
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
13
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
194
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use XML::Hash::LX qw(hash2xml); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Encode qw(decode_utf8); |
14
|
|
|
|
|
|
|
use Mojo::Util qw(camelize xml_escape); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub register { |
17
|
|
|
|
|
|
|
my ($self, $app, $conf) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$conf ||= {}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Add XML type if not exists |
22
|
|
|
|
|
|
|
$app->types->type(xml => 'application/xml') |
23
|
|
|
|
|
|
|
unless $app->types->type('xml'); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# http://mojolicious.org/perldoc/Mojolicious/Guides/Rendering |
26
|
|
|
|
|
|
|
# #Adding-a-handler-to-generate-binary-data |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Add XML handler |
29
|
|
|
|
|
|
|
$app->renderer->add_handler(xml => sub { |
30
|
|
|
|
|
|
|
my ($renderer, $c, $output, $options) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my %opts = %$conf; |
33
|
|
|
|
|
|
|
$opts{encoding} = $options->{encoding} if $options->{encoding}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $data = delete $c->stash->{xml}; |
36
|
|
|
|
|
|
|
my $dom = hash2xml $data, doc => 1, %opts; |
37
|
|
|
|
|
|
|
$$output = $dom->toString( 2 ); |
38
|
|
|
|
|
|
|
}); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Automatic apply XML handler |
41
|
|
|
|
|
|
|
$app->hook(before_render => sub { |
42
|
|
|
|
|
|
|
my ($c, $args) = @_; |
43
|
|
|
|
|
|
|
$args->{handler} = 'xml' |
44
|
|
|
|
|
|
|
if exists $args->{xml} || exists $c->stash->{xml}; |
45
|
|
|
|
|
|
|
}); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Mojolicious::Plugin::XML::LX - is a plugin |
51
|
|
|
|
|
|
|
to support simple XML response from HASH. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 SYNOPSIS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$self->render(xml => { |
57
|
|
|
|
|
|
|
response => { |
58
|
|
|
|
|
|
|
-status => 'ok', |
59
|
|
|
|
|
|
|
message => 'hello world!', |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
}); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# You get: |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
hello world! |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DESCRIPTION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
L based on L |
74
|
|
|
|
|
|
|
companion for L. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
All configuration parameters apply to L. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AUTHOR |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Roman V. Nikolaev, C<< >> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 BUGS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
85
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
86
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SUPPORT |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
perldoc Mojolicious::Plugin::XML::LX |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
You can also look for information at: |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=over 4 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
L |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * CPAN Ratings |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * Search CPAN |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
L |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=back |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Copyright 2016 Roman V. Nikolaev. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
129
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
130
|
|
|
|
|
|
|
copy of the full license at: |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
135
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
136
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
137
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
140
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
141
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
144
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
147
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
148
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
149
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
150
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
151
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
152
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
153
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
156
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
157
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
158
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
159
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
160
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
161
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
162
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1; # End of Mojolicious::Plugin::XML::LX |