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

filter: Statementstmt 88.3% 83 / 94 Branchbran 65.3% 17 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 86.9% 20 / 23 Podpod n/a totaltotal 83.9% 120 / 143 CC 16 SCAR 10.6
CC
16
Cov
83%
__ANON__
6.3
_handle_elem_of_name_q
6.0
_write_scene_main
4.0
CRAP 2.9
« blib/lib/XML/Grammar/Fiction/FromProto/Parser/QnD.pm ↑ Summary blib/lib/XML/Grammar/Fiction/App/FromProto.pm »
1 package XML::Grammar::Screenplay::FromProto;
2 10 $XML::Grammar::Screenplay::FromProto::VERSION = '0.32.0';
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 ▶use MooX 'late';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 extends("XML::Grammar::FictionBase::TagsTree2XML");
12  
13 10 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 562 ▶{
Subroutine _write_Element_Text: called CC=3 SCAR=11.0
19 562 my ( $self, $elem ) = @_;
20  
21 562 ▶ if ( $elem->_short_isa("Saying") )
Branch: 2 branches
BranchTrueFalseTotal
if ($elem->_short_isa('Saying')) { } 124 438 562
elsif ($elem->_short_isa('Description')) { } 64 374 438
22 {
23 124 $self->_output_tag_with_childs(
24 {
25 start => [ "saying", 'character' => $elem->character() ],
26 elem => $elem,
27 },
28 );
29  
30 124 return;
31 }
32 elsif ( $elem->_short_isa("Description") )
33 {
34 64 $self->_output_tag_with_childs(
35 {
36 start => ["description"],
37 elem => $elem,
38 },
39 );
40  
41 64 return;
42 }
43 else
44 {
45 374 $self->_write_elem_childs($elem);
46  
47 374 return;
48 }
49 }
50  
51 sub _paragraph_tag
52 529 ▶{
Subroutine _paragraph_tag: called CC=1 SCAR=0.0
53 529 return "para";
54 }
55  
56 sub _handle_elem_of_name_code_blk
57 6 ▶{
Subroutine _handle_elem_of_name_code_blk: called CC=2 SCAR=7.1
58 6 my ( $self, $elem ) = @_;
59  
60 24 ▶ my $good = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
61 24 my ( $k, $v ) = @_;
62 24 my $input_v = $elem->lookup_attr($k);
63 24 ▶ die
Branch: 2 branches
BranchTrueFalseTotal
if ref $v eq "" ? $v ne $input_v : !($input_v =~ /$v/) 0 24 24
ref $v eq '' ? : 6 18 24
64 "wrong value \"$input_v\" for attribute \"$k\" for element \"<code_blk>\""
65 if ( ref($v) eq "" ? ( $v ne $input_v ) : ( $input_v !~ /$v/ ) );
66 24 return ( $k, $input_v );
67 6 };
68  
69 6 ▶ my $out_cb = sub {
Subroutine __ANON__: called CC=1 SCAR=0.1
70 $self->_output_tag(
71 {
72 start => [
73 "code_blk",
74 $good->( "syntax", "text" ),
75 $good->( "tag_role", qr#\A(?:asciiart|code_block)\z#, ),
76 $good->( "title", qr#.#ms ),
77 $good->( "alt", qr#.#ms ),
78 ],
79 6 ▶ in => sub {
Subroutine __ANON__: called CC=6 SCAR=18.4
80 6 my $inner_text = $elem->_first()->_first();
81  
82 6 foreach my $cnt ( 1 .. 2 )
83 {
84 12 my $x;
85  
86 12 eval { $x = $inner_text->_first(); };
87  
88 12 ▶ if ($x)
Branch: 1 branch
BranchTrueFalseTotal
if ($x) 0 12 12
89 {
90 0 $inner_text = $x;
91 }
92  
93 }
94 6 ▶ die if ( ref($inner_text) ne "" );
Branch: 1 branch
BranchTrueFalseTotal
if ref $inner_text ne "" 0 6 6
95 6 $inner_text =~ s/\A(?:\r?\n)*//ms;
96 6 $inner_text =~ s/(?:^\r?\n)*\z//ms;
97 6 my @lines = split /^/ms, $inner_text;
98 LINES:
99 6 foreach my $l (@lines)
100 {
101 # next LINES if $l =~ /\A\r?\n/
102 36 ▶ $l =~ s#^\|##ms
Branch: 1 branch
BranchTrueFalseTotal
$l =~ s/^\|//ms or die "code_blk line did not start with a '|'" 36 0 36
103 or die qq#code_blk line did not start with a '|'#;
104 }
105 6 return $self->_write_elem(
106 {
107 elem => ( join "", @lines )
108 }
109 );
110 },
111 }
112 6 );
113 6 };
114 return (
115 6 ▶ ( $self->_writer->within_element( $self->_paragraph_tag ) )
Branch: 1 branch
BranchTrueFalseTotal
$self->_writer->within_element($self->_paragraph_tag) ? : 6 0 6
116 ? $out_cb->()
117 : $self->_output_tag(
118 {
119 start => [ $self->_paragraph_tag, ],
120 in => $out_cb,
121 }
122 )
123 );
124  
125 0 return;
126 }
127  
128 sub _handle_elem_of_name_img
129 8 ▶{
Subroutine _handle_elem_of_name_img: called CC=2 SCAR=7.0
130 8 my ( $self, $elem ) = @_;
131  
132 8 ▶ my $image_cb = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
133 8 return $self->_output_tag_with_childs(
134 {
135 start => [
136 "image",
137 "url" => $elem->lookup_attr("src"),
138 "alt" => $elem->lookup_attr("alt"),
139 "title" => $elem->lookup_attr("title"),
140 ],
141 elem => $elem,
142 }
143 );
144 8 };
145  
146 return (
147 8 ▶ ( $self->_writer->within_element( $self->_paragraph_tag ) )
Branch: 1 branch
BranchTrueFalseTotal
$self->_writer->within_element($self->_paragraph_tag) ? : 8 0 8
148 ? $image_cb->()
149 : $self->_output_tag(
150 {
151 start => [ "para", ],
152 in => $image_cb,
153 }
154 )
155 );
156  
157 }
158  
159 sub _handle_elem_of_name_q
160 0 ▶{
Subroutine _handle_elem_of_name_q: not called CC=2 SCAR=17.9
161 0 my ( $self, $elem ) = @_;
162  
163 0 ▶ my $q_cb = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
164 0 return $self->_output_tag_with_childs(
165 {
166 start => [ "q", ],
167 elem => $elem,
168 }
169 );
170 0 };
171  
172 return (
173 ( $self->_writer->within_element( $self->_paragraph_tag ) )
174 ? $q_cb->()
175 : do
176 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
$self->_writer->within_element($self->_paragraph_tag) ? : 0 0 0
177 0 Carp::confess("<q> element not at toplevel!");
178 0 $self->_output_tag(
179 {
180 start => [ "para", ],
181 in => $q_cb,
182 }
183 );
184 }
185 );
186  
187 }
188  
189 sub _handle_elem_of_name_a
190 45 ▶{
Subroutine _handle_elem_of_name_a: called CC=1 SCAR=0.0
191 45 my ( $self, $elem ) = @_;
192  
193 45 $self->_output_tag_with_childs(
194 {
195 start => [
196 "a",
197 [ "http://www.w3.org/1999/xlink", "href" ],
198 $elem->lookup_attr("href"),
199 ],
200 elem => $elem,
201 }
202 );
203  
204 45 return;
205 }
206  
207 sub _handle_elem_of_name_section
208 0 ▶{
Subroutine _handle_elem_of_name_section: not called CC=1 SCAR=6.9
209 0 my ( $self, $elem ) = @_;
210  
211 0 return $self->_handle_elem_of_name_s($elem);
212 }
213  
214 sub _handle_elem_of_name_strong
215 2 ▶{
Subroutine _handle_elem_of_name_strong: called CC=1 SCAR=0.0
216 2 my ( $self, $elem ) = @_;
217  
218 2 $self->_output_tag_with_childs(
219 {
220 start => [ "strong", ],
221 elem => $elem,
222 }
223 );
224  
225 2 return;
226 }
227  
228 sub _bold_tag_name
229 13 ▶{
Subroutine _bold_tag_name: called CC=1 SCAR=0.0
230 13 return "bold";
231 }
232  
233 sub _italics_tag_name
234 6 ▶{
Subroutine _italics_tag_name: called CC=1 SCAR=0.0
235 6 return "italics";
236 }
237  
238 sub _write_scene_main
239 67 ▶{
Subroutine _write_scene_main: called CC=4 SCAR=13.9
240 67 my ( $self, $scene ) = @_;
241  
242 67 my $id = $scene->lookup_attr("id");
243  
244 67 ▶ if ( !defined($id) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id) 0 67 67
245 {
246 0 Carp::confess("Unspecified id for scene!");
247 }
248  
249 67 my $title = $scene->lookup_attr("title");
250 67 my $lang = $scene->lookup_attr("lang");
251 67 ▶ my @t = ( defined($title) ? ( title => $title ) : () );
Branch: 1 branch
BranchTrueFalseTotal
defined $title ? : 7 60 67
252 67 ▶ if ( defined($lang) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lang) 2 65 67
253 {
254 2 push @t, ( [ $self->_get_xml_xml_ns, 'lang' ] => $lang );
255 }
256  
257 $self->_output_tag_with_childs(
258 {
259 67 'start' => [ "scene", id => $id, @t ],
260 elem => $scene,
261 }
262 );
263  
264 67 return;
265 }
266  
267 sub _get_default_xml_ns
268 620 ▶{
Subroutine _get_default_xml_ns: called CC=1 SCAR=0.0
269 620 return $screenplay_ns;
270 }
271  
272 sub _convert_write_content
273 30 ▶{
Subroutine _convert_write_content: called CC=1 SCAR=0.0
274 30 my ( $self, $tree ) = @_;
275  
276 30 my $writer = $self->_writer;
277  
278 30 $writer->startTag( [ $screenplay_ns, "document" ] );
279 30 $writer->startTag( [ $screenplay_ns, "head" ] );
280 30 $writer->endTag();
281 30 $writer->startTag( [ $screenplay_ns, "body" ], "id" => "index", );
282  
283 30 $self->_write_scene( { scene => $tree } );
284  
285 # Ending the body
286 30 $writer->endTag();
287  
288 30 $writer->endTag();
289  
290 30 return;
291 }
292  
293 10 1;
294  
295 __END__
« blib/lib/XML/Grammar/Fiction/FromProto/Parser/QnD.pm ↑ Summary blib/lib/XML/Grammar/Fiction/App/FromProto.pm »