blib/lib/XML/Grammar/Screenplay/API/Concat.pm

filter: Statementstmt 35.9% 23 / 64 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 100% 1 / 1 totaltotal 37.8% 31 / 82 CC 9 SCAR 38.7
CC
9
Cov
32%
concat
90.0
_calc_xpc
2.0
BEGIN
1.0
CRAP 48.2
↑ Summary blib/lib/XML/Grammar/FictionBase/TagsTree2XML.pm »
1 package XML::Grammar::Screenplay::API::Concat;
2 2 $XML::Grammar::Screenplay::API::Concat::VERSION = '0.32.0';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use MooX 'late';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use XML::LibXML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 my $SCREENPLAY_XML_NS =
14 "http://web-cpan.berlios.de/modules/XML-Grammar-Screenplay/screenplay-xml-0.2/";
15  
16 sub _calc_xpc
17 0 ▶{
Subroutine _calc_xpc: not called CC=1 SCAR=6.9
18 0 my $xpc = XML::LibXML::XPathContext->new();
19 0 $xpc->registerNs( "sp", $SCREENPLAY_XML_NS );
20  
21 0 return $xpc;
22 }
23  
24 sub concat
25 0 ▶{
Subroutine concat: not called CC=9 SCAR=45.0
Pod documented
26 0 my ( $self, $args ) = @_;
27 0 my $inputs = $args->{inputs};
28  
29 0 my $parser = XML::LibXML->new();
30 0 my $new_xml = $parser->parse_string(
31 qq#<document xmlns="$SCREENPLAY_XML_NS"><head></head><body id="index"></body></document>#
32 );
33 0 my $root = $new_xml->documentElement();
34 0 my $xpc = _calc_xpc();
35 0 my ($root_body) = $xpc->findnodes( './sp:body', $root );
36  
37 0 my $id_differentiator_counters = +{};
38 0 my $chapter_idx = 0;
39 0 foreach my $src (@$inputs)
40 {
41 0 my $this_chapter_idx = ( ++$chapter_idx );
42 0 my $src_type = $src->{type};
43 0 ▶ if ( $src_type ne 'file' )
Branch: 1 branch
BranchTrueFalseTotal
if ($src_type ne "file") 0 0 0
44 {
45 0 Carp::confess(qq#Unknown input type "$src_type"#);
46 }
47 0 my $src_fn = $src->{filename};
48 0 my $input = $parser->parse_file($src_fn);
49 0 my $doc = $input->documentElement();
50 0 my @el = $xpc->findnodes( "//sp:document/sp:body/sp:scene", $doc, );
51 0 my $dest_xml;
52  
53 0 ▶ if ( not @el )
Branch: 2 branches
BranchTrueFalseTotal
if (not @el) { } 0 0 0
elsif (1 == @el) { } 0 0 0
54 {
55 0 Carp::confess(q#no scenes found in "$src_fn"#);
56 }
57 elsif ( 1 == @el )
58 {
59 0 $dest_xml = $el[0];
60  
61 # @el = $xpc->findnodes("//sp:document/sp:body/sp:scene/sp:scene");
62 }
63 else
64 {
65 0 $dest_xml = $parser->parse_string(
66 qq#<scene xmlns="$SCREENPLAY_XML_NS" id="chapter_$this_chapter_idx" title="Chapter $this_chapter_idx"></scene>#
67 );
68 0 foreach my $el (@el)
69 {
70 0 $dest_xml->documentElement()
71 ->appendWellBalancedChunk( $el->toString() );
72 }
73 }
74  
75 0 foreach my $el ($dest_xml)
76 {
77 0 my @idels = $xpc->findnodes( "//sp:scene[\@id]", $el, );
78 0 foreach my $id_el (@idels)
79 {
80 0 my $old_id = $id_el->getAttribute('id');
81 0 ▶ if ( exists $id_differentiator_counters->{$old_id} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $id_differentiator_counters->{$old_id}) { } 0 0 0
82 {
83 0 my $new_idx = $id_differentiator_counters->{$old_id}++;
84 0 my $new_id = sprintf( "%s_%d", $old_id, $new_idx );
85 0 $id_el->setAttribute( 'id', $new_id );
86 }
87 else
88 {
89 0 $id_differentiator_counters->{$old_id} = 1;
90 }
91 }
92 }
93  
94 $root_body->appendWellBalancedChunk(
95  
96 # $dest_xml->documentElement()->toString() );
97 0 $dest_xml->toString()
98 );
99 }
100  
101 0 my $output_str = $new_xml->toString();
102 0 my $output_dom = $parser->parse_string( $output_str, );
103 0 return +{ 'dom' => $output_dom, 'string' => $output_str, };
104 }
105  
106 2 1;
107  
108 =pod
109  
110 =encoding UTF-8
111  
112 =head1 NAME
113  
114 XML::Grammar::Screenplay::API::Concat - concatenate several screenplay-xml files.
115  
116 =head1 VERSION
117  
118 version 0.32.0
119  
120 =head1 SYNOPSIS
121  
122 =head1 DESCRIPTION
123  
124 =head1 METHODS
125  
126 =head2 my $rec = $obj->concat({ inputs => [@inputs] })
127  
128 =head1 THANKS
129  
130 L<https://stackoverflow.com/questions/1074233/how-can-i-combine-two-xml-files-with-perl> and L<https://github.com/robinsmidsrod/xml-merge> .
131  
132 =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
133  
134 =head1 SUPPORT
135  
136 =head2 Websites
137  
138 The following websites have more information about this module, and may be of help to you. As always,
139 in addition to those websites please use your favorite search engine to discover more resources.
140  
141 =over 4
142  
143 =item *
144  
145 MetaCPAN
146  
147 A modern, open-source CPAN search engine, useful to view POD in HTML format.
148  
149 L<https://metacpan.org/release/XML-Grammar-Fiction>
150  
151 =item *
152  
153 RT: CPAN's Bug Tracker
154  
155 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
156  
157 L<https://rt.cpan.org/Public/Dist/Display.html?Name=XML-Grammar-Fiction>
158  
159 =item *
160  
161 CPANTS
162  
163 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
164  
165 L<http://cpants.cpanauthors.org/dist/XML-Grammar-Fiction>
166  
167 =item *
168  
169 CPAN Testers
170  
171 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
172  
173 L<http://www.cpantesters.org/distro/X/XML-Grammar-Fiction>
174  
175 =item *
176  
177 CPAN Testers Matrix
178  
179 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
180  
181 L<http://matrix.cpantesters.org/?dist=XML-Grammar-Fiction>
182  
183 =item *
184  
185 CPAN Testers Dependencies
186  
187 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
188  
189 L<http://deps.cpantesters.org/?module=XML::Grammar::Fiction>
190  
191 =back
192  
193 =head2 Bugs / Feature Requests
194  
195 Please report any bugs or feature requests by email to C<bug-xml-grammar-fiction at rt.cpan.org>, or through
196 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=XML-Grammar-Fiction>. You will be automatically notified of any
197 progress on the request by the system.
198  
199 =head2 Source Code
200  
201 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
202 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
203 from your repository :)
204  
205 L<https://github.com/shlomif/fiction-xml>
206  
207 git clone git://github.com/shlomif/fiction-xml.git
208  
209 =head1 AUTHOR
210  
211 Shlomi Fish <shlomif@cpan.org>
212  
213 =head1 BUGS
214  
215 Please report any bugs or feature requests on the bugtracker website
216 L<https://github.com/shlomif/fiction-xml/issues>
217  
218 When submitting a bug or request, please include a test-file or a
219 patch to an existing test-file that illustrates the bug or desired
220 feature.
221  
222 =head1 COPYRIGHT AND LICENSE
223  
224 This software is Copyright (c) 2007 by Shlomi Fish.
225  
226 This is free software, licensed under:
227  
228 The MIT (X11) License
229  
230 =cut
231  
232 __END__
↑ Summary blib/lib/XML/Grammar/FictionBase/TagsTree2XML.pm »