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.0702';
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.0702
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 FUNCTIONS
122  
123 =head2 my $processor = XML::Grammar::Fortune->new({mode => $mode, input => $in, output => $out, output_mode => "string",});
124  
125 Creates a new processor with mode $mode, output_mode "string", and input and output files.
126  
127 =head2 $self->run({ %args})
128  
129 Runs the processor. If $mode is "validate", validates the document.
130  
131 %args may contain:
132  
133 =over 4
134  
135 =item * xslt_params
136  
137 Parameters for the XSLT stylesheet.
138  
139 =item * input
140  
141 Input source - depends on input_mode.
142  
143 =item * output
144  
145 Output destination - depends on output mode.
146  
147 =back
148  
149 =head2 open
150  
151 This function is introduced by Fatal. It is mentioned here, in order to settle
152 L<Pod::Coverage> . Ignore.
153  
154 =head1 AUTHOR
155  
156 Shlomi Fish, L<http://www.shlomifish.org/> .
157  
158 =head1 BUGS
159  
160 Please report any bugs or feature requests to C<bug-xml-grammar-fortune at rt.cpan.org>, or through
161 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-Grammar-Fortune>. I will be notified, and then you'll
162 automatically be notified of progress on your bug as I make changes.
163  
164 =head1 SUPPORT
165  
166 You can find documentation for this module with the perldoc command.
167  
168 perldoc XML::Grammar::Fortune
169  
170 You can also look for information at:
171  
172 =over 4
173  
174 =item * RT: CPAN's request tracker
175  
176 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=XML-Grammar-Fortune>
177  
178 =item * AnnoCPAN: Annotated CPAN documentation
179  
180 L<http://annocpan.org/dist/XML-Grammar-Fortune>
181  
182 =item * CPAN Ratings
183  
184 L<http://cpanratings.perl.org/d/XML-Grammar-Fortune>
185  
186 =item * Search CPAN
187  
188 L<http://search.cpan.org/dist/XML-Grammar-Fortune>
189  
190 =back
191  
192 =head1 ACKNOWLEDGEMENTS
193  
194 =head1 COPYRIGHT & LICENSE
195  
196 Copyright 2008 by Shlomi Fish
197  
198 This program is distributed under the MIT (X11) License:
199 L<http://www.opensource.org/licenses/mit-license.php>
200  
201 Permission is hereby granted, free of charge, to any person
202 obtaining a copy of this software and associated documentation
203 files (the "Software"), to deal in the Software without
204 restriction, including without limitation the rights to use,
205 copy, modify, merge, publish, distribute, sublicense, and/or sell
206 copies of the Software, and to permit persons to whom the
207 Software is furnished to do so, subject to the following
208 conditions:
209  
210 The above copyright notice and this permission notice shall be
211 included in all copies or substantial portions of the Software.
212  
213 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
214 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
215 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
216 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
217 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
218 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
219 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
220 OTHER DEALINGS IN THE SOFTWARE.
221  
222 =head1 AUTHOR
223  
224 Shlomi Fish <shlomif@cpan.org>
225  
226 =head1 COPYRIGHT AND LICENSE
227  
228 This software is Copyright (c) 2018 by Shlomi Fish.
229  
230 This is free software, licensed under:
231  
232 The MIT (X11) License
233  
234 =head1 BUGS
235  
236 Please report any bugs or feature requests on the bugtracker website
237 L<https://github.com/shlomif/fortune-xml/issues>
238  
239 When submitting a bug or request, please include a test-file or a
240 patch to an existing test-file that illustrates the bug or desired
241 feature.
242  
243 =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
244  
245 =head1 SUPPORT
246  
247 =head2 Perldoc
248  
249 You can find documentation for this module with the perldoc command.
250  
251 perldoc XML::Grammar::Fortune
252  
253 =head2 Websites
254  
255 The following websites have more information about this module, and may be of help to you. As always,
256 in addition to those websites please use your favorite search engine to discover more resources.
257  
258 =over 4
259  
260 =item *
261  
262 MetaCPAN
263  
264 A modern, open-source CPAN search engine, useful to view POD in HTML format.
265  
266 L<https://metacpan.org/release/XML-Grammar-Fortune>
267  
268 =item *
269  
270 Search CPAN
271  
272 The default CPAN search engine, useful to view POD in HTML format.
273  
274 L<http://search.cpan.org/dist/XML-Grammar-Fortune>
275  
276 =item *
277  
278 RT: CPAN's Bug Tracker
279  
280 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
281  
282 L<https://rt.cpan.org/Public/Dist/Display.html?Name=XML-Grammar-Fortune>
283  
284 =item *
285  
286 AnnoCPAN
287  
288 The AnnoCPAN is a website that allows community annotations of Perl module documentation.
289  
290 L<http://annocpan.org/dist/XML-Grammar-Fortune>
291  
292 =item *
293  
294 CPAN Ratings
295  
296 The CPAN Ratings is a website that allows community ratings and reviews of Perl modules.
297  
298 L<http://cpanratings.perl.org/d/XML-Grammar-Fortune>
299  
300 =item *
301  
302 CPANTS
303  
304 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
305  
306 L<http://cpants.cpanauthors.org/dist/XML-Grammar-Fortune>
307  
308 =item *
309  
310 CPAN Testers
311  
312 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
313  
314 L<http://www.cpantesters.org/distro/X/XML-Grammar-Fortune>
315  
316 =item *
317  
318 CPAN Testers Matrix
319  
320 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
321  
322 L<http://matrix.cpantesters.org/?dist=XML-Grammar-Fortune>
323  
324 =item *
325  
326 CPAN Testers Dependencies
327  
328 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
329  
330 L<http://deps.cpantesters.org/?module=XML::Grammar::Fortune>
331  
332 =back
333  
334 =head2 Bugs / Feature Requests
335  
336 Please report any bugs or feature requests by email to C<bug-xml-grammar-fortune at rt.cpan.org>, or through
337 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=XML-Grammar-Fortune>. You will be automatically notified of any
338 progress on the request by the system.
339  
340 =head2 Source Code
341  
342 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
343 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
344 from your repository :)
345  
346 L<https://github.com/shlomif/fortune-xml>
347  
348 git clone git://github.com/shlomif/fortune-xml.git
349  
350 =cut
« Build ↑ Summary