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

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