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

filter: Statementstmt 96.1% 75 / 78 Branchbran 80.0% 16 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 95.0% 19 / 20 Podpod n/a totaltotal 93.2% 110 / 118 CC 12 SCAR 8.2
CC
12
Cov
93%
__ANON__
4.1
_write_scene_main
4.0
__ANON__
3.0
CRAP 2.3
« blib/lib/XML/Grammar/FictionBase/Event.pm ↑ Summary blib/lib/XML/Grammar/FictionBase/FromProto/Parser/XmlIterator.pm »
1 package XML::Grammar::Screenplay::FromProto;
2 8 $XML::Grammar::Screenplay::FromProto::VERSION = '0.22.0';
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 ▶use MooX 'late';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 extends("XML::Grammar::FictionBase::TagsTree2XML");
12  
13 8 my $screenplay_ns =
14 q{http://web-cpan.berlios.de/modules/XML-Grammar-Screenplay/screenplay-xml-0.2/};
15  
16  
17 sub _write_Element_Text
18 {
19 411 ▶ my ( $self, $elem ) = @_;
Subroutine _write_Element_Text: called CC=3 SCAR=11.0
20  
21 411 ▶ if ( $elem->_short_isa("Saying") )
Branch: 2 branches
BranchTrueFalseTotal
if ($elem->_short_isa('Saying')) { } 98 313 411
elsif ($elem->_short_isa('Description')) { } 45 268 313
22 {
23 98 $self->_output_tag_with_childs(
24 {
25 start => [ "saying", 'character' => $elem->character() ],
26 elem => $elem,
27 },
28 );
29  
30 98 return;
31 }
32 elsif ( $elem->_short_isa("Description") )
33 {
34 45 $self->_output_tag_with_childs(
35 {
36 start => ["description"],
37 elem => $elem,
38 },
39 );
40  
41 45 return;
42 }
43 else
44 {
45 268 $self->_write_elem_childs($elem);
46  
47 268 return;
48 }
49 }
50  
51 sub _paragraph_tag
52 {
53 185 ▶ return "para";
Subroutine _paragraph_tag: called CC=1 SCAR=0.0
54 }
55  
56 sub _handle_elem_of_name_code_blk
57 {
58 1 ▶ my ( $self, $elem ) = @_;
Subroutine _handle_elem_of_name_code_blk: called CC=1 SCAR=0.0
59  
60 my $good = sub {
61 4 ▶ my ( $k, $v ) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
62 4 my $input_v = $elem->lookup_attr($k);
63 4 ▶ die "wrong value \"$v\""
Branch: 2 branches
BranchTrueFalseTotal
if ref $v eq "" ? $v ne $input_v : !($input_v =~ /$v/) 0 4 4
ref $v eq '' ? : 2 2 4
64 if ( ref($v) eq "" ? ( $v ne $input_v ) : ( $input_v !~ /$v/ ) );
65 4 return ( $k, $input_v );
66 1 };
67  
68 $self->_output_tag(
69 {
70 start => [ $self->_paragraph_tag() ],
71 in => sub {
72 $self->_output_tag(
73 {
74 start => [
75 "code_blk",
76 $good->( "syntax", "text" ),
77 $good->( "tag_role", "asciiart" ),
78 $good->( "title", qr#.#ms ),
79 $good->( "alt", qr#.#ms ),
80 ],
81 in => sub {
82 1 ▶ my $inner_text =
Subroutine __ANON__: called CC=4 SCAR=14.0
83 $elem->_first()->_first()->_first();
84  
85 1 ▶ die if ( ref($inner_text) ne "" );
Branch: 1 branch
BranchTrueFalseTotal
if ref $inner_text ne "" 0 1 1
86 1 $inner_text =~ s/\A(?:\r?\n)*//ms;
87 1 $inner_text =~ s/(?:^\r?\n)*\z//ms;
88 1 my @lines = split /^/ms, $inner_text;
89 LINES:
90 1 foreach my $l (@lines)
91 {
92 # next LINES if $l =~ /\A\r?\n/
93 6 ▶ $l =~ s#^\|##ms
Branch: 1 branch
BranchTrueFalseTotal
$l =~ s/^\|//ms or die "code_blk line did not start with a '|'" 0 6 6
94 or die
95 qq#code_blk line did not start with a '|'#;
96 }
97 1 return $self->_write_elem(
98 {
99 elem => ( join "", @lines )
100 }
101 );
102 },
103 }
104 1 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
105 },
106 },
107 1 );
108  
109 1 return;
110 }
111  
112 sub _handle_elem_of_name_img
113 {
114 8 ▶ my ( $self, $elem ) = @_;
Subroutine _handle_elem_of_name_img: called CC=2 SCAR=6.9
115  
116 my $image_cb = sub {
117 8 ▶ return $self->_output_tag_with_childs(
Subroutine __ANON__: called CC=1 SCAR=0.0
118 {
119 start => [
120 "image",
121 "url" => $elem->lookup_attr("src"),
122 "alt" => $elem->lookup_attr("alt"),
123 "title" => $elem->lookup_attr("title"),
124 ],
125 elem => $elem,
126 }
127 );
128 8 };
129  
130 return (
131 8 ▶ ( $self->_writer->ancestor(0) eq $self->_paragraph_tag )
Branch: 1 branch
BranchTrueFalseTotal
$self->_writer->ancestor(0) eq $self->_paragraph_tag ? : 1 7 8
132 ? $image_cb->()
133 : $self->_output_tag(
134 {
135 start => [ "para", ],
136 in => $image_cb,
137 }
138 )
139 );
140  
141 }
142  
143 sub _handle_elem_of_name_a
144 {
145 30 ▶ my ( $self, $elem ) = @_;
Subroutine _handle_elem_of_name_a: called CC=1 SCAR=0.0
146  
147 30 $self->_output_tag_with_childs(
148 {
149 start => [ "ulink", "url" => $elem->lookup_attr("href") ],
150 elem => $elem,
151 }
152 );
153  
154 30 return;
155 }
156  
157 sub _handle_elem_of_name_section
158 {
159 0 ▶ my ( $self, $elem ) = @_;
Subroutine _handle_elem_of_name_section: not called CC=1 SCAR=6.9
160  
161 0 return $self->_handle_elem_of_name_s($elem);
162 }
163  
164 sub _bold_tag_name
165 {
166 4 ▶ return "bold";
Subroutine _bold_tag_name: called CC=1 SCAR=0.0
167 }
168  
169 sub _italics_tag_name
170 {
171 5 ▶ return "italics";
Subroutine _italics_tag_name: called CC=1 SCAR=0.0
172 }
173  
174 sub _write_scene_main
175 {
176 57 ▶ my ( $self, $scene ) = @_;
Subroutine _write_scene_main: called CC=4 SCAR=13.9
177  
178 57 my $id = $scene->lookup_attr("id");
179  
180 57 ▶ if ( !defined($id) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id) 0 57 57
181 {
182 0 Carp::confess("Unspecified id for scene!");
183 }
184  
185 57 my $title = $scene->lookup_attr("title");
186 57 my $lang = $scene->lookup_attr("lang");
187 57 ▶ my @t = ( defined($title) ? ( title => $title ) : () );
Branch: 1 branch
BranchTrueFalseTotal
defined $title ? : 7 50 57
188 57 ▶ if ( defined($lang) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lang) 2 55 57
189 {
190 2 push @t, ( [ $self->_get_xml_xml_ns, 'lang' ] => $lang );
191 }
192  
193 $self->_output_tag_with_childs(
194 {
195 57 'start' => [ "scene", id => $id, @t ],
196 elem => $scene,
197 }
198 );
199  
200 57 return;
201 }
202  
203 sub _get_default_xml_ns
204 {
205 464 ▶ return $screenplay_ns;
Subroutine _get_default_xml_ns: called CC=1 SCAR=0.0
206 }
207  
208 sub _convert_write_content
209 {
210 25 ▶ my ( $self, $tree ) = @_;
Subroutine _convert_write_content: called CC=1 SCAR=0.0
211  
212 25 my $writer = $self->_writer;
213  
214 25 $writer->startTag( [ $screenplay_ns, "document" ] );
215 25 $writer->startTag( [ $screenplay_ns, "head" ] );
216 25 $writer->endTag();
217 25 $writer->startTag( [ $screenplay_ns, "body" ], "id" => "index", );
218  
219 25 $self->_write_scene( { scene => $tree } );
220  
221 # Ending the body
222 25 $writer->endTag();
223  
224 25 $writer->endTag();
225  
226 25 return;
227 }
228  
229 8 1;
230  
231 __END__
232  
233 =pod
234  
235 =encoding UTF-8
236  
237 =head1 NAME
238  
239 XML::Grammar::Screenplay::FromProto - module that converts well-formed
240 text representing a screenplay to an XML format.
241  
242 =head2 new()
243  
244 Accepts no arguments so far. May take some time as the grammar is compiled
245 at that point.
246  
247 =head2 meta()
248  
249 Internal - (to settle pod-coverage.).
250  
251 =head2 $self->convert({ source => { file => $path_to_file } })
252  
253 Converts the file $path_to_file to XML and returns it.
254  
255 =head1 VERSION
256  
257 version 0.22.0
258  
259 =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
260  
261 =head1 SUPPORT
262  
263 =head2 Websites
264  
265 The following websites have more information about this module, and may be of help to you. As always,
266 in addition to those websites please use your favorite search engine to discover more resources.
267  
268 =over 4
269  
270 =item *
271  
272 MetaCPAN
273  
274 A modern, open-source CPAN search engine, useful to view POD in HTML format.
275  
276 L<https://metacpan.org/release/XML-Grammar-Fiction>
277  
278 =item *
279  
280 RT: CPAN's Bug Tracker
281  
282 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
283  
284 L<https://rt.cpan.org/Public/Dist/Display.html?Name=XML-Grammar-Fiction>
285  
286 =item *
287  
288 CPANTS
289  
290 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
291  
292 L<http://cpants.cpanauthors.org/dist/XML-Grammar-Fiction>
293  
294 =item *
295  
296 CPAN Testers
297  
298 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
299  
300 L<http://www.cpantesters.org/distro/X/XML-Grammar-Fiction>
301  
302 =item *
303  
304 CPAN Testers Matrix
305  
306 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
307  
308 L<http://matrix.cpantesters.org/?dist=XML-Grammar-Fiction>
309  
310 =item *
311  
312 CPAN Testers Dependencies
313  
314 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
315  
316 L<http://deps.cpantesters.org/?module=XML::Grammar::Fiction>
317  
318 =back
319  
320 =head2 Bugs / Feature Requests
321  
322 Please report any bugs or feature requests by email to C<bug-xml-grammar-fiction at rt.cpan.org>, or through
323 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=XML-Grammar-Fiction>. You will be automatically notified of any
324 progress on the request by the system.
325  
326 =head2 Source Code
327  
328 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
329 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
330 from your repository :)
331  
332 L<https://github.com/shlomif/fiction-xml>
333  
334 git clone git://github.com/shlomif/fiction-xml.git
335  
336 =head1 AUTHOR
337  
338 Shlomi Fish <shlomif@cpan.org>
339  
340 =head1 BUGS
341  
342 Please report any bugs or feature requests on the bugtracker website
343 L<https://github.com/shlomif/fiction-xml/issues>
344  
345 When submitting a bug or request, please include a test-file or a
346 patch to an existing test-file that illustrates the bug or desired
347 feature.
348  
349 =head1 COPYRIGHT AND LICENSE
350  
351 This software is Copyright (c) 2007 by Shlomi Fish.
352  
353 This is free software, licensed under:
354  
355 The MIT (X11) License
356  
357 =cut
« blib/lib/XML/Grammar/FictionBase/Event.pm ↑ Summary blib/lib/XML/Grammar/FictionBase/FromProto/Parser/XmlIterator.pm »