| 1 | package XML::GrammarBase::Role::XSLT; | ||
| 2 | $XML::GrammarBase::Role::XSLT::VERSION = '0.2.8'; | ||
| 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.8 | ||
| 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 PARAMATERS | ||
| 92 | |||
| 93 | =head2 output_format | ||
| 94 | |||
| 95 | A Perl identifier string identifying the format. | ||
| 96 | |||
| 97 | =head1 SLOTS | ||
| 98 | |||
| 99 | =head2 module_base | ||
| 100 | |||
| 101 | The basename of the module - used for dist dir. | ||
| 102 | |||
| 103 | =head2 data_dir | ||
| 104 | |||
| 105 | The data directory where the XML assets can be found (the RELAX NG schema, etc.) | ||
| 106 | |||
| 107 | =head2 rng_schema_basename | ||
| 108 | |||
| 109 | The Relax NG Schema basename. | ||
| 110 | |||
| 111 | =head2 to_${output_format}_xslt_transform_basename | ||
| 112 | |||
| 113 | The basename of the primary XSLT transform file. Should be overrided in | ||
| 114 | the constructor or using C<has '+to_html'>. For example: | ||
| 115 | |||
| 116 | has '+to_html_xslt_transform_basename' => (default => 'fiction-xml-to-html.xslt'); | ||
| 117 | |||
| 118 | =head1 METHODS | ||
| 119 | |||
| 120 | =head2 $self->rng_validate_dom($source_dom) | ||
| 121 | |||
| 122 | Validates the DOM ( $source_dom ) using the RELAX-NG schema. | ||
| 123 | |||
| 124 | =head2 $self->rng_validate_file($file_path) | ||
| 125 | |||
| 126 | Validates the file in $file_path using the RELAX-NG schema. | ||
| 127 | |||
| 128 | =head2 $self->rng_validate_string($xml_string) | ||
| 129 | |||
| 130 | Validates the XML in the $xml_string using the RELAX-NG schema. | ||
| 131 | |||
| 132 | =head2 $converter->perform_xslt_translation | ||
| 133 | |||
| 134 | =over 4 | ||
| 135 | |||
| 136 | =item * my $final_source = $converter->perform_xslt_translation({output_format => $format, source => {file => $filename}, output => "string" }) | ||
| 137 | |||
| 138 | =item * my $final_source = $converter->perform_xslt_translation({output_format => $format, source => {string_ref => \$buffer}, output => "string" }) | ||
| 139 | |||
| 140 | =item * my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {file => $filename}, output => "dom" }) | ||
| 141 | |||
| 142 | =item * my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {dom => $libxml_dom}, output => "dom" }) | ||
| 143 | |||
| 144 | =item * my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {dom => $libxml_dom}, output => {file => $path_to_file,}, }) | ||
| 145 | |||
| 146 | =item * my $final_dom = $converter->perform_xslt_translation({output_format => $format, source => {dom => $libxml_dom}, output => {fh => $filehandle,}, }) | ||
| 147 | |||
| 148 | =back | ||
| 149 | |||
| 150 | This method does the actual conversion with the output format of | ||
| 151 | $format. The C<'source'> argument points to a hash-ref with | ||
| 152 | keys and values for the source. If C<'file'> is specified there it points to the | ||
| 153 | filename to translate (currently the only available source). If | ||
| 154 | C<'string_ref'> is specified it points to a reference to a string, with the | ||
| 155 | contents of the source XML. If C<'dom'> is specified then it points to an XML | ||
| 156 | DOM as parsed or constructed by XML::LibXML. | ||
| 157 | |||
| 158 | The C<'output'> key specifies the return value. A value of C<'string'> returns | ||
| 159 | the XML as a string, and a value of C<'dom'> returns the XML as an | ||
| 160 | L<XML::LibXML> DOM object. If it is a hash ref then it specifies a | ||
| 161 | C<'file'> or a C<'fh'> with a filepath or filehandle respectively. | ||
| 162 | |||
| 163 | An optional C<'encoding'> parameter determines if one should output the string | ||
| 164 | as C<'utf8'> (the deafult - using L<XML::LibXSLT>'s | ||
| 165 | output_as_chars()) or as C<'bytes'> - using its output_as_bytes() . | ||
| 166 | |||
| 167 | An optional 'xslt_params' parmater allows one to specify a hash of XSLT | ||
| 168 | parameters. | ||
| 169 | |||
| 170 | =head2 BUILD | ||
| 171 | |||
| 172 | L<Moo> constructor. For internal use. | ||
| 173 | |||
| 174 | =head2 make_variant | ||
| 175 | |||
| 176 | L<Package::Variant> constructor. For internal use. | ||
| 177 | |||
| 178 | =head1 AUTHOR | ||
| 179 | |||
| 180 | Shlomi Fish, C<< <shlomif at cpan.org> >> | ||
| 181 | |||
| 182 | =head1 ACKNOWLEDGEMENTS | ||
| 183 | |||
| 184 | =head1 COPYRIGHT & LICENSE | ||
| 185 | |||
| 186 | Copyright 2009 Shlomi Fish. | ||
| 187 | |||
| 188 | This program is distributed under the MIT (X11) License: | ||
| 189 | L<http://www.opensource.org/licenses/mit-license.php> | ||
| 190 | |||
| 191 | Permission is hereby granted, free of charge, to any person | ||
| 192 | obtaining a copy of this software and associated documentation | ||
| 193 | files (the "Software"), to deal in the Software without | ||
| 194 | restriction, including without limitation the rights to use, | ||
| 195 | copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 196 | copies of the Software, and to permit persons to whom the | ||
| 197 | Software is furnished to do so, subject to the following | ||
| 198 | conditions: | ||
| 199 | |||
| 200 | The above copyright notice and this permission notice shall be | ||
| 201 | included in all copies or substantial portions of the Software. | ||
| 202 | |||
| 203 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 204 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
| 205 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| 206 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
| 207 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| 208 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| 209 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| 210 | OTHER DEALINGS IN THE SOFTWARE. | ||
| 211 | |||
| 212 | =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan | ||
| 213 | |||
| 214 | =head1 SUPPORT | ||
| 215 | |||
| 216 | =head2 Websites | ||
| 217 | |||
| 218 | The following websites have more information about this module, and may be of help to you. As always, | ||
| 219 | in addition to those websites please use your favorite search engine to discover more resources. | ||
| 220 | |||
| 221 | =over 4 | ||
| 222 | |||
| 223 | =item * | ||
| 224 | |||
| 225 | MetaCPAN | ||
| 226 | |||
| 227 | A modern, open-source CPAN search engine, useful to view POD in HTML format. | ||
| 228 | |||
| 229 | L<https://metacpan.org/release/XML-GrammarBase> | ||
| 230 | |||
| 231 | =item * | ||
| 232 | |||
| 233 | RT: CPAN's Bug Tracker | ||
| 234 | |||
| 235 | The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN. | ||
| 236 | |||
| 237 | L<https://rt.cpan.org/Public/Dist/Display.html?Name=XML-GrammarBase> | ||
| 238 | |||
| 239 | =item * | ||
| 240 | |||
| 241 | CPANTS | ||
| 242 | |||
| 243 | The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution. | ||
| 244 | |||
| 245 | L<http://cpants.cpanauthors.org/dist/XML-GrammarBase> | ||
| 246 | |||
| 247 | =item * | ||
| 248 | |||
| 249 | CPAN Testers | ||
| 250 | |||
| 251 | The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions. | ||
| 252 | |||
| 253 | L<http://www.cpantesters.org/distro/X/XML-GrammarBase> | ||
| 254 | |||
| 255 | =item * | ||
| 256 | |||
| 257 | CPAN Testers Matrix | ||
| 258 | |||
| 259 | The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms. | ||
| 260 | |||
| 261 | L<http://matrix.cpantesters.org/?dist=XML-GrammarBase> | ||
| 262 | |||
| 263 | =item * | ||
| 264 | |||
| 265 | CPAN Testers Dependencies | ||
| 266 | |||
| 267 | The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution. | ||
| 268 | |||
| 269 | L<http://deps.cpantesters.org/?module=XML::GrammarBase> | ||
| 270 | |||
| 271 | =back | ||
| 272 | |||
| 273 | =head2 Bugs / Feature Requests | ||
| 274 | |||
| 275 | Please report any bugs or feature requests by email to C<bug-xml-grammarbase at rt.cpan.org>, or through | ||
| 276 | the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=XML-GrammarBase>. You will be automatically notified of any | ||
| 277 | progress on the request by the system. | ||
| 278 | |||
| 279 | =head2 Source Code | ||
| 280 | |||
| 281 | The code is open to the world, and available for you to hack on. Please feel free to browse it and play | ||
| 282 | with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull | ||
| 283 | from your repository :) | ||
| 284 | |||
| 285 | L<https://github.com/shlomif/perl-XML-GrammarBase> | ||
| 286 | |||
| 287 | git clone git://github.com/shlomif/perl-XML-GrammarBase.git | ||
| 288 | |||
| 289 | =head1 AUTHOR | ||
| 290 | |||
| 291 | Shlomi Fish <shlomif@cpan.org> | ||
| 292 | |||
| 293 | =head1 BUGS | ||
| 294 | |||
| 295 | Please report any bugs or feature requests on the bugtracker website | ||
| 296 | L<https://github.com/shlomif/perl-XML-GrammarBase/issues> | ||
| 297 | |||
| 298 | When submitting a bug or request, please include a test-file or a | ||
| 299 | patch to an existing test-file that illustrates the bug or desired | ||
| 300 | feature. | ||
| 301 | |||
| 302 | =head1 COPYRIGHT AND LICENSE | ||
| 303 | |||
| 304 | This software is Copyright (c) 2018 by Shlomi Fish. | ||
| 305 | |||
| 306 | This is free software, licensed under: | ||
| 307 | |||
| 308 | The MIT (X11) License | ||
| 309 | |||
| 310 | =cut | ||