blib/lib/XML/Grammar/Fortune.pm

filter: Statementstmt 90.4% 19 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 92.8% 26 / 28 CC 1 SCAR 0.4
CC
1
Cov
90%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Build ↑ Summary
1 package XML::Grammar::Fortune;
2 $XML::Grammar::Fortune::VERSION = '0.0701';
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Fatal (qw(open));
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use MooX qw/late/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use XML::GrammarBase::Role::RelaxNG v0.2.2;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use XML::GrammarBase::Role::XSLT v0.2.2;
Subroutine BEGIN: called CC=1 SCAR=2.6
14  
15 with('XML::GrammarBase::Role::RelaxNG');
16 with XSLT( output_format => 'html' );
17  
18 has '+module_base' => ( default => 'XML-Grammar-Fortune' );
19 has '+rng_schema_basename' => ( default => 'fortune-xml.rng' );
20  
21 has '+to_html_xslt_transform_basename' =>
22 ( default => 'fortune-xml-to-html.xslt' );
23  
24 has '_mode' => ( is => 'rw', init_arg => 'mode' );
25 has '_output_mode' => ( is => 'rw', init_arg => 'output_mode', );
26  
27  
28 sub run
29 {
30 my $self = shift;
31 my $args = shift;
32  
33 my $xslt_params = $args->{'xslt_params'} || {};
34  
35 my $output = $args->{'output'};
36 my $input = $args->{'input'};
37  
38 my $mode = $self->_mode();
39  
40 if ( $mode eq "validate" )
41 {
42 return $self->rng_validate_file($input);
43 }
44 elsif ( $mode eq "convert_to_html" )
45 {
46 my $translate = sub {
47 my ( $medium, $encoding ) = @_;
48  
49 return $self->perform_xslt_translation(
50 {
51 output_format => 'html',
52 source => { file => $input },
53 output => $medium,
54 encoding => $encoding,
55 xslt_params => $xslt_params,
56 }
57 );
58 };
59 if ( $self->_output_mode() eq "string" )
60 {
61 $$output .= $translate->( 'string', 'bytes' );
62 }
63 else
64 {
65 $translate->( { file => $output }, 'utf8' );
66 }
67 }
68  
69 return;
70 }
71  
72 1; # End of XML::Grammar::Fortune
73  
74 __END__
75  
76 =pod
77  
78 =encoding UTF-8
79  
80 =head1 NAME
81  
82 XML::Grammar::Fortune - convert the FortunesXML grammar to other formats and from plaintext.
83  
84 =head1 VERSION
85  
86 version 0.0701
87  
88 =head1 SYNOPSIS
89  
90 use XML::Grammar::Fortune;
91  
92 # Validate files.
93  
94 my $validator =
95 XML::Grammar::Fortune->new(
96 {
97 mode => "validate"
98 }
99 );
100  
101 # Returns 0 upon success - dies otherwise
102 exit($validator->run({input => "my-fortune-file.xml"}));
103  
104 # Convert files to XHTML.
105  
106 my $converter =
107 XML::Grammar::Fortune->new(
108 {
109 mode => "convert_to_html",
110 output_mode => "filename"
111 }
112 );
113  
114 $converter->run(
115 {
116 input => "my-fortune-file.xml",
117 output => "resultant-file.xhtml",
118 }
119 );
120  
121 =head1 VERSION
122  
123 version 0.0701
124  
125 =head1 FUNCTIONS
126  
127 =head2 my $processor = XML::Grammar::Fortune->new({mode => $mode, input => $in, output => $out, output_mode => "string",});
128  
129 Creates a new processor with mode $mode, output_mode "string", and input and output files.
130  
131 =head2 $self->run({ %args})
132  
133 Runs the processor. If $mode is "validate", validates the document.
134  
135 %args may contain:
136  
137 =over 4
138  
139 =item * xslt_params
140  
141 Parameters for the XSLT stylesheet.
142  
143 =item * input
144  
145 Input source - depends on input_mode.
146  
147 =item * output
148  
149 Output destination - depends on output mode.
150  
151 =back
152  
153 =head2 open
154  
155 This function is introduced by Fatal. It is mentioned here, in order to settle
156 L<Pod::Coverage> . Ignore.
157  
158 =head1 AUTHOR
159  
160 Shlomi Fish, L<http://www.shlomifish.org/> .
161  
162 =head1 BUGS
163  
164 Please report any bugs or feature requests to C<bug-xml-grammar-fortune at rt.cpan.org>, or through
165 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-Grammar-Fortune>. I will be notified, and then you'll
166 automatically be notified of progress on your bug as I make changes.
167  
168 =head1 SUPPORT
169  
170 You can find documentation for this module with the perldoc command.
171  
172 perldoc XML::Grammar::Fortune
173  
174 You can also look for information at:
175  
176 =over 4
177  
178 =item * RT: CPAN's request tracker
179  
180 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-Grammar-Fortune>
181  
182 =item * AnnoCPAN: Annotated CPAN documentation
183  
184 L<http://annocpan.org/dist/XML-Grammar-Fortune>
185  
186 =item * CPAN Ratings
187  
188 L<http://cpanratings.perl.org/d/XML-Grammar-Fortune>
189  
190 =item * Search CPAN
191  
192 L<http://search.cpan.org/dist/XML-Grammar-Fortune>
193  
194 =back
195  
196 =head1 ACKNOWLEDGEMENTS
197  
198 =head1 COPYRIGHT & LICENSE
199  
200 Copyright 2008 by Shlomi Fish
201  
202 This program is distributed under the MIT (X11) License:
203 L<http://www.opensource.org/licenses/mit-license.php>
204  
205 Permission is hereby granted, free of charge, to any person
206 obtaining a copy of this software and associated documentation
207 files (the "Software"), to deal in the Software without
208 restriction, including without limitation the rights to use,
209 copy, modify, merge, publish, distribute, sublicense, and/or sell
210 copies of the Software, and to permit persons to whom the
211 Software is furnished to do so, subject to the following
212 conditions:
213  
214 The above copyright notice and this permission notice shall be
215 included in all copies or substantial portions of the Software.
216  
217 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
218 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
219 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
220 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
221 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
222 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
223 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
224 OTHER DEALINGS IN THE SOFTWARE.
225  
226 =head1 AUTHOR
227  
228 Shlomi Fish <shlomif@cpan.org>
229  
230 =head1 COPYRIGHT AND LICENSE
231  
232 This software is Copyright (c) 2018 by Shlomi Fish.
233  
234 This is free software, licensed under:
235  
236 The MIT (X11) License
237  
238 =head1 BUGS
239  
240 Please report any bugs or feature requests on the bugtracker website
241 L<https://github.com/shlomif/xml-grammar-fortune/issues>
242  
243 When submitting a bug or request, please include a test-file or a
244 patch to an existing test-file that illustrates the bug or desired
245 feature.
246  
247 =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
248  
249 =head1 SUPPORT
250  
251 =head2 Perldoc
252  
253 You can find documentation for this module with the perldoc command.
254  
255 perldoc XML::Grammar::Fortune
256  
257 =head2 Websites
258  
259 The following websites have more information about this module, and may be of help to you. As always,
260 in addition to those websites please use your favorite search engine to discover more resources.
261  
262 =over 4
263  
264 =item *
265  
266 MetaCPAN
267  
268 A modern, open-source CPAN search engine, useful to view POD in HTML format.
269  
270 L<https://metacpan.org/release/XML-Grammar-Fortune>
271  
272 =item *
273  
274 Search CPAN
275  
276 The default CPAN search engine, useful to view POD in HTML format.
277  
278 L<http://search.cpan.org/dist/XML-Grammar-Fortune>
279  
280 =item *
281  
282 RT: CPAN's Bug Tracker
283  
284 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
285  
286 L<https://rt.cpan.org/Public/Dist/Display.html?Name=XML-Grammar-Fortune>
287  
288 =item *
289  
290 AnnoCPAN
291  
292 The AnnoCPAN is a website that allows community annotations of Perl module documentation.
293  
294 L<http://annocpan.org/dist/XML-Grammar-Fortune>
295  
296 =item *
297  
298 CPAN Ratings
299  
300 The CPAN Ratings is a website that allows community ratings and reviews of Perl modules.
301  
302 L<http://cpanratings.perl.org/d/XML-Grammar-Fortune>
303  
304 =item *
305  
306 CPANTS
307  
308 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
309  
310 L<http://cpants.cpanauthors.org/dist/XML-Grammar-Fortune>
311  
312 =item *
313  
314 CPAN Testers
315  
316 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
317  
318 L<http://www.cpantesters.org/distro/X/XML-Grammar-Fortune>
319  
320 =item *
321  
322 CPAN Testers Matrix
323  
324 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
325  
326 L<http://matrix.cpantesters.org/?dist=XML-Grammar-Fortune>
327  
328 =item *
329  
330 CPAN Testers Dependencies
331  
332 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
333  
334 L<http://deps.cpantesters.org/?module=XML::Grammar::Fortune>
335  
336 =back
337  
338 =head2 Bugs / Feature Requests
339  
340 Please report any bugs or feature requests by email to C<bug-xml-grammar-fortune at rt.cpan.org>, or through
341 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=XML-Grammar-Fortune>. You will be automatically notified of any
342 progress on the request by the system.
343  
344 =head2 Source Code
345  
346 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
347 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
348 from your repository :)
349  
350 L<https://github.com/shlomif/xml-grammar-fortune>
351  
352 git clone git://github.com/shlomif/xml-grammar-fortune.git
353  
354 =cut
« Build ↑ Summary