blib/lib/XML/GrammarBase/Role/XSLT.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/XML/GrammarBase/Role/RelaxNG.pm ↑ Summary blib/lib/XML/GrammarBase/Role/XSLT/Global.pm »
1 package XML::GrammarBase::Role::XSLT;
2 $XML::GrammarBase::Role::XSLT::VERSION = '0.2.6';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 use Package::Variant
8 3 importing => [ 'MooX::Role' => ['late'], ],
9 3 ▶ subs => [qw(has with)];
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # use MooX 'late';
12  
13 3 ▶use XML::LibXML '2.0017';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use XML::LibXSLT '1.80';
Subroutine BEGIN: called CC=1 SCAR=2.6
15  
16 use autodie;
17  
18 sub make_variant
19 {
20 my ( $class, $target_package, %args ) = @_;
21  
22 my $output_format = $args{output_format};
23  
24 with('XML::GrammarBase::Role::XSLT::Global');
25  
26 has "to_${output_format}_xslt_transform_basename" =>
27 ( isa => 'Str', is => 'rw' );
28  
29 has "_to_${output_format}_stylesheet" => (
30 isa => "XML::LibXSLT::StylesheetWrapper",
31 is => 'rw',
32 default => sub { return shift->_calc_stylesheet($output_format), },
33 lazy => 1,
34 );
35  
36 return;
37 }
38  
39  
40  
41 1; # End of XML::GrammarBase::RelaxNG::Validate
42  
43 __END__
44  
45 =pod
46  
47 =encoding UTF-8
48  
49 =head1 NAME
50  
51 XML::GrammarBase::Role::XSLT - a parameterized role for XSLT conversions.
52  
53 =head1 VERSION
54  
55 version 0.2.6
56  
57 =head1 SYNOPSIS
58  
59 package XML::Grammar::MyGrammar::ToOtherStuff;
60  
61 use MooX 'late';
62  
63 use XML::GrammarBase::Role::RelaxNG;
64 use XML::GrammarBase::Role::XSLT;
65  
66 with ('XML::GrammarBase::Role::RelaxNG');
67 with XSLT(output_format => 'html');
68 with XSLT(output_format => 'docbook');
69  
70 has '+module_base' => (default => 'XML-Grammar-MyGrammar');
71 has '+rng_schema_basename' => (default => 'my-grammar.rng');
72  
73 has '+to_html_xslt_transform_basename' => (default => 'mygrammar-xml-to-html.xslt');
74 has '+to_docbook_xslt_transform_basename' => (default => 'mygrammar-xml-to-docbook.xslt');
75  
76 package main;
77  
78 my $xslt = XML::Grammar::MyGrammar::ToOtherStuff->new(
79 data_dir => "/path/to/data-dir",
80 );
81  
82 # Throws an exception on failure.
83 my $as_html = $xslt->perform_xslt_translation(
84 {
85 output_format => 'html'
86 source => {file => $input_filename, },
87 output => "string",
88 }
89 );
90  
91 =head1 VERSION
92  
93 version 0.2.6
94  
95 =head1 PARAMATERS
96  
97 =head2 output_format
98  
99 A Perl identifier string identifying the format.
100  
101 =head1 SLOTS
102  
103 =head2 module_base
104  
105 The basename of the module - used for dist dir.
106  
107 =head2 data_dir
108  
109 The data directory where the XML assets can be found (the RELAX NG schema, etc.)
110  
111 =head2 rng_schema_basename
112  
113 The Relax NG Schema basename.
114  
115 =head2 to_${output_format}_xslt_transform_basename
116  
117 The basename of the primary XSLT transform file. Should be overrided in
118 the constructor or using C<has '+to_html'>. For example:
119  
120 has '+to_html_xslt_transform_basename' => (default => 'fiction-xml-to-html.xslt');
121  
122 =head1 METHODS
123  
124 =head2 $self->rng_validate_dom($source_dom)
125  
126 Validates the DOM ( $source_dom ) using the RELAX-NG schema.
127  
128 =head2 $self->rng_validate_file($file_path)
129  
130 Validates the file in $file_path using the RELAX-NG schema.
131  
132 =head2 $self->rng_validate_string($xml_string)
133  
134 Validates the XML in the $xml_string using the RELAX-NG schema.
135  
136 =head2 $converter->perform_xslt_translation
137  
138 =over 4
139  
140 =item * my $final_source = $converter->perform_xslt_translation({output_format => $format, source => {file => $filename}, output => "string" })
141  
142 =item * my $final_source = $converter->perform_xslt_translation({output_format => $format, source => {string_ref => \$buffer}, output => "string" })
143  
144 =item * my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {file => $filename}, output => "dom" })
145  
146 =item * my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {dom => $libxml_dom}, output => "dom" })
147  
148 =item * my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {dom => $libxml_dom}, output => {file => $path_to_file,}, })
149  
150 =item * my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {dom => $libxml_dom}, output => {fh => $filehandle,}, })
151  
152 =back
153  
154 This method does the actual conversion with the output format of
155 $format. The C<'source'> argument points to a hash-ref with
156 keys and values for the source. If C<'file'> is specified there it points to the
157 filename to translate (currently the only available source). If
158 C<'string_ref'> is specified it points to a reference to a string, with the
159 contents of the source XML. If C<'dom'> is specified then it points to an XML
160 DOM as parsed or constructed by XML::LibXML.
161  
162 The C<'output'> key specifies the return value. A value of C<'string'> returns
163 the XML as a string, and a value of C<'dom'> returns the XML as an
164 L<XML::LibXML> DOM object. If it is a hash ref then it specifies a
165 C<'file'> or a C<'fh'> with a filepath or filehandle respectively.
166  
167 An optional C<'encoding'> parameter determines if one should output the string
168 as C<'utf8'> (the deafult - using L<XML::LibXSLT>'s
169 output_as_chars()) or as C<'bytes'> - using its output_as_bytes() .
170  
171 An optional 'xslt_params' parmater allows one to specify a hash of XSLT
172 parameters.
173  
174 =head2 BUILD
175  
176 L<Moo> constructor. For internal use.
177  
178 =head2 make_variant
179  
180 L<Package::Variant> constructor. For internal use.
181  
182 =head1 AUTHOR
183  
184 Shlomi Fish, C<< <shlomif at cpan.org> >>
185  
186 =head1 BUGS
187  
188 Please report any bugs or feature requests to C<bug-xml-grammarbase at rt.cpan.org>, or through
189 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-GrammarBase>. I will be notified, and then you'll
190 automatically be notified of progress on your bug as I make changes.
191  
192 =head1 THANKS
193  
194 Thanks to Matt S. Trout L<http://metacpan.org/author/MSTROUT> and other
195 people from #moose on irc.perl.org for helping me figure out
196 L<Moo> / L<MooX> and steer me away from L<Any::Moose> , and for writing
197 the L<Moo> ecosystem.
198  
199 =head1 SUPPORT
200  
201 You can find documentation for this module with the perldoc command.
202  
203 perldoc XML::GrammarBase
204  
205 You can also look for information at:
206  
207 =over 4
208  
209 =item * RT: CPAN's request tracker
210  
211 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-GrammarBase>
212  
213 =item * AnnoCPAN: Annotated CPAN documentation
214  
215 L<http://annocpan.org/dist/XML-GrammarBase>
216  
217 =item * CPAN Ratings
218  
219 L<http://cpanratings.perl.org/d/XML-GrammarBase>
220  
221 =item * Search CPAN
222  
223 L<http://search.cpan.org/dist/XML-GrammarBase/>
224  
225 =back
226  
227 =head1 ACKNOWLEDGEMENTS
228  
229 =head1 COPYRIGHT & LICENSE
230  
231 Copyright 2009 Shlomi Fish.
232  
233 This program is distributed under the MIT (X11) License:
234 L<http://www.opensource.org/licenses/mit-license.php>
235  
236 Permission is hereby granted, free of charge, to any person
237 obtaining a copy of this software and associated documentation
238 files (the "Software"), to deal in the Software without
239 restriction, including without limitation the rights to use,
240 copy, modify, merge, publish, distribute, sublicense, and/or sell
241 copies of the Software, and to permit persons to whom the
242 Software is furnished to do so, subject to the following
243 conditions:
244  
245 The above copyright notice and this permission notice shall be
246 included in all copies or substantial portions of the Software.
247  
248 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
249 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
250 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
251 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
252 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
253 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
254 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
255 OTHER DEALINGS IN THE SOFTWARE.
256  
257 =head1 AUTHOR
258  
259 Shlomi Fish <shlomif@cpan.org>
260  
261 =head1 COPYRIGHT AND LICENSE
262  
263 This software is Copyright (c) 2018 by Shlomi Fish.
264  
265 This is free software, licensed under:
266  
267 The MIT (X11) License
268  
269 =head1 BUGS
270  
271 Please report any bugs or feature requests on the bugtracker website
272 L<https://github.com/shlomif/perl-XML-GrammarBase/issues>
273  
274 When submitting a bug or request, please include a test-file or a
275 patch to an existing test-file that illustrates the bug or desired
276 feature.
277  
278 =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
279  
280 =head1 SUPPORT
281  
282 =head2 Perldoc
283  
284 You can find documentation for this module with the perldoc command.
285  
286 perldoc XML::GrammarBase::Role::XSLT
287  
288 =head2 Websites
289  
290 The following websites have more information about this module, and may be of help to you. As always,
291 in addition to those websites please use your favorite search engine to discover more resources.
292  
293 =over 4
294  
295 =item *
296  
297 MetaCPAN
298  
299 A modern, open-source CPAN search engine, useful to view POD in HTML format.
300  
301 L<https://metacpan.org/release/XML-GrammarBase>
302  
303 =item *
304  
305 Search CPAN
306  
307 The default CPAN search engine, useful to view POD in HTML format.
308  
309 L<http://search.cpan.org/dist/XML-GrammarBase>
310  
311 =item *
312  
313 RT: CPAN's Bug Tracker
314  
315 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
316  
317 L<https://rt.cpan.org/Public/Dist/Display.html?Name=XML-GrammarBase>
318  
319 =item *
320  
321 AnnoCPAN
322  
323 The AnnoCPAN is a website that allows community annotations of Perl module documentation.
324  
325 L<http://annocpan.org/dist/XML-GrammarBase>
326  
327 =item *
328  
329 CPAN Ratings
330  
331 The CPAN Ratings is a website that allows community ratings and reviews of Perl modules.
332  
333 L<http://cpanratings.perl.org/d/XML-GrammarBase>
334  
335 =item *
336  
337 CPANTS
338  
339 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
340  
341 L<http://cpants.cpanauthors.org/dist/XML-GrammarBase>
342  
343 =item *
344  
345 CPAN Testers
346  
347 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
348  
349 L<http://www.cpantesters.org/distro/X/XML-GrammarBase>
350  
351 =item *
352  
353 CPAN Testers Matrix
354  
355 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
356  
357 L<http://matrix.cpantesters.org/?dist=XML-GrammarBase>
358  
359 =item *
360  
361 CPAN Testers Dependencies
362  
363 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
364  
365 L<http://deps.cpantesters.org/?module=XML::GrammarBase>
366  
367 =back
368  
369 =head2 Bugs / Feature Requests
370  
371 Please report any bugs or feature requests by email to C<bug-xml-grammarbase at rt.cpan.org>, or through
372 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=XML-GrammarBase>. You will be automatically notified of any
373 progress on the request by the system.
374  
375 =head2 Source Code
376  
377 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
378 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
379 from your repository :)
380  
381 L<https://github.com/shlomif/perl-XML-GrammarBase>
382  
383 git clone git://github.com/shlomif/perl-XML-GrammarBase.git
384  
385 =cut
« blib/lib/XML/GrammarBase/Role/RelaxNG.pm ↑ Summary blib/lib/XML/GrammarBase/Role/XSLT/Global.pm »