« 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 | 19 | $XML::Grammar::Fiction::FromProto::VERSION = '0.32.0'; | |||||||||||||||||||
| 3 | 21 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 21 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 21 | ▶ | use autodie; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 21 | ▶ | use Carp (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 21 | ▶ | use MooX 'late'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 19 | extends("XML::Grammar::FictionBase::TagsTree2XML"); | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 19 | my $fiction_ns = | |||||||||||||||||||
| 14 | q{http://web-cpan.berlios.de/modules/XML-Grammar-Fortune/fiction-xml-0.2/}; | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 19 | my %lookup = ( map { $_ => +{ tag => $_, wrap_para => 0, }, } qw( li ol ul ) ); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 176 | ▶ | around '_calc_passthrough_cb' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 21 | 176 | my $orig = shift; | |||||||||||||||||||
| 22 | 176 | my $self = shift; | |||||||||||||||||||
| 23 | 176 | my ($name) = @_; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 176 | ▶ | return ( $lookup{$name} // $orig->( $self, @_ ) ); | ||||||||||||||||||
|
Condition100%3/3
$lookup{$name} // &$orig($self, @_)
MC/DC100%2/2
$lookup{$name} // &$orig($self, @_)
$lookup{$name}
&$orig($self, @_)
Truth table100%3/3
A // B
A= $lookup{$name}B= &$orig($self, @_)
| |||||||||||||||||||||
| 26 | 19 | }; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | sub _output_tag_with_childs_and_common_attributes | ||||||||||||||||||||
| 29 | 63 | ▶ | { | ||||||||||||||||||
|
Subroutine
_output_tag_with_childs_and_common_attributes: called CC=8 SCAR=22.2
| |||||||||||||||||||||
| 30 | 63 | my ( $self, $elem, $tag_name, $args ) = @_; | |||||||||||||||||||
| 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
| |||||||||||||||||||||
| 39 | { | ||||||||||||||||||||
| 40 | 8 | ▶ | if ( !$args->{optional_id} ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | { | ||||||||||||||||||||
| 42 | 0 | ▶ | Carp::confess( $args->{missing_id_msg} || "Unspecified id!" ); | ||||||||||||||||||
|
Condition0%0/2
$args->{'missing_id_msg'} || 'Unspecified id!'
MC/DC0%0/1
$args->{'missing_id_msg'} || 'Unspecified id!'
$args->{'missing_id_msg'}
Truth table0%0/2
A
A= $args->{'missing_id_msg'}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 51 | { | ||||||||||||||||||||
| 52 | 9 | push @attr, ( [ $self->_get_xml_xml_ns, 'lang' ] => $lang ); | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 63 | ▶ | if ( !defined($href) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | { | ||||||||||||||||||||
| 57 | 56 | ▶ | if ( $args->{required_href} ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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!'
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'}
| |||||||||||||||||||||
| 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 | 257 | ▶ | { | ||||||||||||||||||
|
Subroutine
_paragraph_tag: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 78 | 257 | return "p"; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | sub _handle_elem_of_name_a | ||||||||||||||||||||
| 82 | 7 | ▶ | { | ||||||||||||||||||
|
Subroutine
_handle_elem_of_name_a: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 83 | 7 | my ( $self, $elem ) = @_; | |||||||||||||||||||
| 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 | 4 | ▶ | { | ||||||||||||||||||
|
Subroutine
_handle_elem_of_name_blockquote: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 99 | 4 | my ( $self, $elem ) = @_; | |||||||||||||||||||
| 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 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
_handle_elem_of_name_programlisting: called CC=1 SCAR=0.3
| |||||||||||||||||||||
| 114 | 1 | my ( $self, $elem ) = @_; | |||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 0 | ▶ | my $throw_found_tag_exception = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 117 | 0 | XML::Grammar::Fiction::Err::Parse::ProgramListingContainsTags->throw( | |||||||||||||||||||
| 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 | 1 | ▶ | 'in' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.0
| |||||||||||||||||||||
| 128 | 1 | foreach my $child ( @{ $elem->_get_childs() } ) | |||||||||||||||||||
| 129 | { | ||||||||||||||||||||
| 130 | 1 | ▶ | if ( $child->_short_isa("Paragraph") ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 131 | { | ||||||||||||||||||||
| 132 | 1 | foreach my $text_node ( | |||||||||||||||||||
| 133 | 1 | @{ $child->children()->contents() } ) | |||||||||||||||||||
| 134 | { | ||||||||||||||||||||
| 135 | 1 | ▶ | if ( $text_node->_short_isa("Text") ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
_handle_elem_of_name_span: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 164 | 3 | my ( $self, $elem ) = @_; | |||||||||||||||||||
| 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 | 49 | ▶ | { | ||||||||||||||||||
|
Subroutine
_handle_elem_of_name_title: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 179 | 49 | my ( $self, $elem ) = @_; | |||||||||||||||||||
| 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 | 49 | ▶ | in => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 189 | 49 | $self->_write_elem( | |||||||||||||||||||
| 190 | { | ||||||||||||||||||||
| 191 | elem => $list, | ||||||||||||||||||||
| 192 | } | ||||||||||||||||||||
| 193 | ), | ||||||||||||||||||||
| 194 | ; | ||||||||||||||||||||
| 195 | }, | ||||||||||||||||||||
| 196 | }, | ||||||||||||||||||||
| 197 | 49 | ); | |||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | 49 | return; | |||||||||||||||||||
| 200 | } | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | sub _bold_tag_name | ||||||||||||||||||||
| 203 | 15 | ▶ | { | ||||||||||||||||||
|
Subroutine
_bold_tag_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 204 | 15 | return "b"; | |||||||||||||||||||
| 205 | } | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | sub _italics_tag_name | ||||||||||||||||||||
| 208 | 14 | ▶ | { | ||||||||||||||||||
|
Subroutine
_italics_tag_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 209 | 14 | return "i"; | |||||||||||||||||||
| 210 | } | ||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | sub _write_Element_Text | ||||||||||||||||||||
| 213 | 241 | ▶ | { | ||||||||||||||||||
|
Subroutine
_write_Element_Text: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 214 | 241 | return shift->_write_elem_childs(@_); | |||||||||||||||||||
| 215 | } | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | sub _write_Element_List | ||||||||||||||||||||
| 218 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_write_Element_List: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 219 | 0 | my ( $self, $elem ) = @_; | |||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | 0 | foreach my $child ( @{ $elem->contents() } ) | |||||||||||||||||||
| 222 | { | ||||||||||||||||||||
| 223 | 0 | $self->_write_elem( { elem => $child, } ); | |||||||||||||||||||
| 224 | } | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | 0 | return; | |||||||||||||||||||
| 227 | } | ||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | 549 | ▶ | around '_calc_write_elem_obj_classes' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 230 | 549 | my $orig = shift; | |||||||||||||||||||
| 231 | 549 | my $self = shift; | |||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | 549 | return [ 'List', @{ $orig->($self) } ]; | |||||||||||||||||||
| 234 | 19 | }; | |||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | sub _write_scene_main | ||||||||||||||||||||
| 237 | 33 | ▶ | { | ||||||||||||||||||
|
Subroutine
_write_scene_main: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 238 | 33 | my ( $self, $scene ) = @_; | |||||||||||||||||||
| 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 | 16 | ▶ | { | ||||||||||||||||||
|
Subroutine
_write_body: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 249 | 16 | my $self = shift; | |||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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 | 323 | ▶ | { | ||||||||||||||||||
|
Subroutine
_get_default_xml_ns: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 270 | 323 | return $fiction_ns; | |||||||||||||||||||
| 271 | } | ||||||||||||||||||||
| 272 | |||||||||||||||||||||
| 273 | sub _convert_write_content | ||||||||||||||||||||
| 274 | 16 | ▶ | { | ||||||||||||||||||
|
Subroutine
_convert_write_content: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 275 | 16 | my ( $self, $tree ) = @_; | |||||||||||||||||||
| 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 | 19 | 1; | |||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | __END__ | ||||||||||||||||||||