blib/lib/XML/Grammar/Fiction/FromProto.pm

filter: Statementstmt 88.8% 96 / 108 Branchbran 72.2% 13 / 18 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.0% 23 / 25 Podpod n/a totaltotal 84.0% 132 / 157 CC 15 SCAR 12.9
CC
15
Cov
84%
_output_tag_with_childs_and_common_attributes
9.2
_write_Element_List
6.0
__ANON__
5.5
CRAP 3.6
« blib/lib/XML/Grammar/Screenplay/FromProto/Parser/QnD.pm ↑ Summary blib/lib/XML/Grammar/Fiction/FromProto/Parser/QnD.pm »
1 package XML::Grammar::Fiction::FromProto;
2 20 $XML::Grammar::Fiction::FromProto::VERSION = '0.22.0';
3 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 20 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 20 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 20 ▶use MooX 'late';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 20 extends("XML::Grammar::FictionBase::TagsTree2XML");
12  
13 20 my $fiction_ns =
14 q{http://web-cpan.berlios.de/modules/XML-Grammar-Fortune/fiction-xml-0.2/};
15  
16  
17  
18 20 my %lookup = ( map { $_ => $_ } qw( li ol ul ) );
19  
20 around '_calc_passthrough_cb' => sub {
21 176 ▶ my $orig = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
22 176 my $self = shift;
23 176 my ($name) = @_;
24  
25 176 ▶ if ( $lookup{$name} )
Branch: 1 branch
BranchTrueFalseTotal
if ($lookup{$name}) 50 126 176
26 {
27 50 return $name;
28 }
29  
30 126 return $orig->( $self, @_ );
31 20 };
32  
33 sub _output_tag_with_childs_and_common_attributes
34 {
35 63 ▶ my ( $self, $elem, $tag_name, $args ) = @_;
Subroutine _output_tag_with_childs_and_common_attributes: called CC=8 SCAR=22.2
36  
37 63 my $id = $elem->lookup_attr("id");
38 63 my $lang = $elem->lookup_attr("lang");
39 63 my $href = $elem->lookup_attr("href");
40  
41 63 my @attr;
42  
43 63 ▶ if ( !defined($id) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $id) { } 8 55 63
44 {
45 8 ▶ if ( !$args->{optional_id} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"optional_id"}) 0 8 8
46 {
47 0 ▶ Carp::confess( $args->{missing_id_msg} || "Unspecified id!" );
Condition0%0/2
$args->{'missing_id_msg'} || 'Unspecified id!'
l!l
00
MC/DC0%0/1
$args->{'missing_id_msg'} || 'Unspecified id!'
$args->{'missing_id_msg'}
Truth table0%0/2
A
A= $args->{'missing_id_msg'}
Aresult
11
00
48 }
49 }
50 else
51 {
52 55 push @attr, ( [ $self->_get_xml_xml_ns, "id" ] => $id );
53 }
54  
55 63 ▶ if ( defined($lang) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lang) 9 54 63
56 {
57 9 push @attr, ( [ $self->_get_xml_xml_ns, 'lang' ] => $lang );
58 }
59  
60 63 ▶ if ( !defined($href) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $href) { } 56 7 63
61 {
62 56 ▶ if ( $args->{required_href} )
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"required_href"}) 0 56 56
63 {
64 Carp::confess( $args->{missing_href_msg}
65 0 ▶ || 'Unspecified href in tag!' );
Condition0%0/2
$args->{'missing_href_msg'} || 'Unspecified href in tag!'
l!l
00
MC/DC0%0/1
$args->{'missing_href_msg'} || 'Unspecified href in tag!'
$args->{'missing_href_msg'}
Truth table0%0/2
A
A= $args->{'missing_href_msg'}
Aresult
11
00
66 }
67 }
68 else
69 {
70 7 push @attr, ( [ $self->_get_xlink_xml_ns(), 'href' ] => $href );
71 }
72  
73 63 return $self->_output_tag_with_childs(
74 {
75 'start' => [ $tag_name, @attr, ],
76 elem => $elem,
77 }
78 );
79 }
80  
81 sub _paragraph_tag
82 {
83 114 ▶ return "p";
Subroutine _paragraph_tag: called CC=1 SCAR=0.0
84 }
85  
86 sub _handle_elem_of_name_a
87 {
88 7 ▶ my ( $self, $elem ) = @_;
Subroutine _handle_elem_of_name_a: called CC=1 SCAR=0.0
89  
90 7 $self->_output_tag_with_childs_and_common_attributes(
91 $elem, 'span',
92 {
93 optional_id => 1,
94 required_href => 1,
95 missing_href_msg => 'Unspecified href in a tag.',
96 },
97 );
98  
99 7 return;
100 }
101  
102 sub _handle_elem_of_name_blockquote
103 {
104 4 ▶ my ( $self, $elem ) = @_;
Subroutine _handle_elem_of_name_blockquote: called CC=1 SCAR=0.0
105  
106 4 $self->_output_tag_with_childs_and_common_attributes(
107 $elem,
108 'blockquote',
109 {
110 optional_id => 1,
111 },
112 );
113  
114 4 return;
115 }
116  
117 sub _handle_elem_of_name_programlisting
118 {
119 1 ▶ my ( $self, $elem ) = @_;
Subroutine _handle_elem_of_name_programlisting: called CC=1 SCAR=0.3
120  
121 my $throw_found_tag_exception = sub {
122 0 ▶ XML::Grammar::Fiction::Err::Parse::ProgramListingContainsTags->throw(
Subroutine __ANON__: not called CC=1 SCAR=6.9
123 error => "<programlisting> tag cannot contain other tags.",
124 line => $elem->open_line(),
125 );
126 1 };
127  
128 return $self->_output_tag(
129 {
130 start => ['programlisting'],
131 elem => $elem,
132 'in' => sub {
133 1 ▶ foreach my $child ( @{ $elem->_get_childs() } )
Subroutine __ANON__: called CC=5 SCAR=17.0
134 {
135 1 ▶ if ( $child->_short_isa("Paragraph") )
Branch: 1 branch
BranchTrueFalseTotal
if ($child->_short_isa('Paragraph')) { } 1 0 1
136 {
137 1 foreach my $text_node (
138 1 @{ $child->children()->contents() } )
139 {
140 1 ▶ if ( $text_node->_short_isa("Text") )
Branch: 1 branch
BranchTrueFalseTotal
if ($text_node->_short_isa('Text')) { } 1 0 1
141 {
142 1 $self->_write_elem( { elem => $text_node } );
143 }
144 else
145 {
146 0 $throw_found_tag_exception->();
147 }
148 }
149 }
150 else
151 {
152 0 $throw_found_tag_exception->();
153 }
154  
155 # End of paragraph.
156 1 $self->_writer->characters("\n\n");
157 }
158  
159 1 return;
160 },
161 }
162 1 );
163  
164 0 return;
165 }
166  
167 sub _handle_elem_of_name_span
168 {
169 3 ▶ my ( $self, $elem ) = @_;
Subroutine _handle_elem_of_name_span: called CC=1 SCAR=0.0
170  
171 3 $self->_output_tag_with_childs_and_common_attributes(
172 $elem, 'span',
173 {
174 optional_id => 1,
175 missing_id_msg => "Unspecified id for span!",
176 },
177 );
178  
179 3 return;
180 }
181  
182 sub _handle_elem_of_name_title
183 {
184 49 ▶ my ( $self, $elem ) = @_;
Subroutine _handle_elem_of_name_title: called CC=1 SCAR=0.0
185  
186 # TODO :
187 # Eliminate the Law-of-Demeter-syndrome here.
188 49 my $list = $elem->_first();
189  
190 $self->_output_tag(
191 {
192 start => ["title"],
193 in => sub {
194 49 ▶ $self->_write_elem(
Subroutine __ANON__: called CC=1 SCAR=0.0
195 {
196 elem => $list,
197 }
198 ),
199 ;
200 },
201 },
202 49 );
203  
204 49 return;
205 }
206  
207 sub _bold_tag_name
208 {
209 15 ▶ return "b";
Subroutine _bold_tag_name: called CC=1 SCAR=0.0
210 }
211  
212 sub _italics_tag_name
213 {
214 14 ▶ return "i";
Subroutine _italics_tag_name: called CC=1 SCAR=0.0
215 }
216  
217 sub _write_Element_Text
218 {
219 241 ▶ return shift->_write_elem_childs(@_);
Subroutine _write_Element_Text: called CC=1 SCAR=0.0
220 }
221  
222 sub _write_Element_List
223 {
224 0 ▶ my ( $self, $elem ) = @_;
Subroutine _write_Element_List: not called CC=2 SCAR=17.9
225  
226 0 foreach my $child ( @{ $elem->contents() } )
227 {
228 0 $self->_write_elem( { elem => $child, } );
229 }
230  
231 0 return;
232 }
233  
234 around '_calc_write_elem_obj_classes' => sub {
235 549 ▶ my $orig = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
236 549 my $self = shift;
237  
238 549 return [ 'List', @{ $orig->($self) } ];
239 20 };
240  
241 sub _write_scene_main
242 {
243 33 ▶ my ( $self, $scene ) = @_;
Subroutine _write_scene_main: called CC=1 SCAR=0.0
244  
245 33 $self->_output_tag_with_childs_and_common_attributes( $scene, "section",
246 { missing_id_msg => "Unspecified id for scene!", },
247 );
248  
249 33 return;
250 }
251  
252 sub _write_body
253 {
254 16 ▶ my $self = shift;
Subroutine _write_body: called CC=2 SCAR=7.1
255 16 my $args = shift;
256  
257 16 my $body = $args->{'body'};
258  
259 16 my $tag = $body->name;
260  
261 16 ▶ if ( $tag ne "body" )
Branch: 1 branch
BranchTrueFalseTotal
if ($tag ne "body") 0 16 16
262 {
263 0 confess "Improper body tag - should be '<body>'!";
264 }
265  
266 16 $self->_output_tag_with_childs_and_common_attributes( $body, 'body',
267 { missing_id_msg => "Unspecified id for body tag!", },
268 );
269  
270 16 return;
271 }
272  
273 sub _get_default_xml_ns
274 {
275 323 ▶ return $fiction_ns;
Subroutine _get_default_xml_ns: called CC=1 SCAR=0.0
276 }
277  
278 sub _convert_write_content
279 {
280 16 ▶ my ( $self, $tree ) = @_;
Subroutine _convert_write_content: called CC=1 SCAR=0.0
281  
282 16 my $writer = $self->_writer;
283  
284 16 $writer->startTag( [ $fiction_ns, "document" ], "version" => "0.2" );
285 16 $writer->startTag( [ $fiction_ns, "head" ] );
286 16 $writer->endTag();
287  
288 16 $self->_write_body( { body => $tree } );
289  
290 16 $writer->endTag();
291  
292 16 return;
293 }
294  
295 20 1;
296  
297 __END__
298  
299 =pod
300  
301 =encoding UTF-8
302  
303 =head1 NAME
304  
305 XML::Grammar::Fiction::FromProto - module that converts well-formed
306 text representing prose to an XML format.
307  
308 =head2 new()
309  
310 Accepts no arguments so far. May take some time as the grammar is compiled
311 at that point.
312  
313 =head2 meta()
314  
315 Internal - (to settle pod-coverage.).
316  
317 =head2 $self->convert({ source => { file => $path_to_file } })
318  
319 Converts the file $path_to_file to XML and returns it. Throws an exception
320 on failure.
321  
322 =head1 VERSION
323  
324 version 0.22.0
325  
326 =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
327  
328 =head1 SUPPORT
329  
330 =head2 Websites
331  
332 The following websites have more information about this module, and may be of help to you. As always,
333 in addition to those websites please use your favorite search engine to discover more resources.
334  
335 =over 4
336  
337 =item *
338  
339 MetaCPAN
340  
341 A modern, open-source CPAN search engine, useful to view POD in HTML format.
342  
343 L<https://metacpan.org/release/XML-Grammar-Fiction>
344  
345 =item *
346  
347 RT: CPAN's Bug Tracker
348  
349 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
350  
351 L<https://rt.cpan.org/Public/Dist/Display.html?Name=XML-Grammar-Fiction>
352  
353 =item *
354  
355 CPANTS
356  
357 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
358  
359 L<http://cpants.cpanauthors.org/dist/XML-Grammar-Fiction>
360  
361 =item *
362  
363 CPAN Testers
364  
365 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
366  
367 L<http://www.cpantesters.org/distro/X/XML-Grammar-Fiction>
368  
369 =item *
370  
371 CPAN Testers Matrix
372  
373 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
374  
375 L<http://matrix.cpantesters.org/?dist=XML-Grammar-Fiction>
376  
377 =item *
378  
379 CPAN Testers Dependencies
380  
381 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
382  
383 L<http://deps.cpantesters.org/?module=XML::Grammar::Fiction>
384  
385 =back
386  
387 =head2 Bugs / Feature Requests
388  
389 Please report any bugs or feature requests by email to C<bug-xml-grammar-fiction at rt.cpan.org>, or through
390 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=XML-Grammar-Fiction>. You will be automatically notified of any
391 progress on the request by the system.
392  
393 =head2 Source Code
394  
395 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
396 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
397 from your repository :)
398  
399 L<https://github.com/shlomif/fiction-xml>
400  
401 git clone git://github.com/shlomif/fiction-xml.git
402  
403 =head1 AUTHOR
404  
405 Shlomi Fish <shlomif@cpan.org>
406  
407 =head1 BUGS
408  
409 Please report any bugs or feature requests on the bugtracker website
410 L<https://github.com/shlomif/fiction-xml/issues>
411  
412 When submitting a bug or request, please include a test-file or a
413 patch to an existing test-file that illustrates the bug or desired
414 feature.
415  
416 =head1 COPYRIGHT AND LICENSE
417  
418 This software is Copyright (c) 2007 by Shlomi Fish.
419  
420 This is free software, licensed under:
421  
422 The MIT (X11) License
423  
424 =cut
« blib/lib/XML/Grammar/Screenplay/FromProto/Parser/QnD.pm ↑ Summary blib/lib/XML/Grammar/Fiction/FromProto/Parser/QnD.pm »