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