blib/lib/QuadPres/WriteContents.pm

filter: Statementstmt 26.2% 21 / 80 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 5 / 10 Podpod 100% 1 / 1 totaltotal 23.6% 27 / 114 CC 13 SCAR 44.6
CC
13
Cov
21%
_stringify_contents
156.0
_get_key_order
6.0
_sort_keys
2.0
CRAP 86.1
« blib/lib/QuadPres/Url.pm ↑ Summary blib/lib/QuadPres.pm »
1 package QuadPres::WriteContents;
2 1 $QuadPres::WriteContents::VERSION = '0.28.4';
3 1 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use MooX qw/ late /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 has '_contents' =>
11 ( isa => "HashRef", is => "ro", init_arg => "contents", required => 1, );
12  
13  
14 1 my @output_contents_keys_order = (qw(url title subs images));
15  
16 my %output_contents_keys_values =
17 1 ( map { $output_contents_keys_order[$_] => $_ }
18 ( 0 .. $#output_contents_keys_order ) );
19  
20 sub _get_key_order
21 {
22 0 ▶ my ($key) = (@_);
Subroutine _get_key_order: not called CC=2 SCAR=17.9
23  
24 return
25 exists( $output_contents_keys_values{$key} )
26 0 ▶ ? $output_contents_keys_values{$key}
Branch: 1 branch
BranchTrueFalseTotal
exists $output_contents_keys_values{$key} ? : 0 0 0
27 : scalar(@output_contents_keys_order);
28 }
29  
30 sub _sort_keys
31 {
32 0 ▶ my ($hash) = @_;
Subroutine _sort_keys: not called CC=1 SCAR=6.9
33 return [
34 0 sort { _get_key_order($a) <=> _get_key_order($b) }
35 keys(%$hash)
36 ];
37 }
38 1 my %special_chars = (
39 "\n" => "\\n",
40 "\t" => "\\t",
41 "\r" => "\\r",
42 "\f" => "\\f",
43 "\b" => "\\b",
44 "\a" => "\\a",
45 "\e" => "\\e",
46 );
47  
48 sub _string_to_perl
49 {
50 0 ▶ my $s = shift;
Subroutine _string_to_perl: not called CC=1 SCAR=6.9
51 0 $s =~ s/([\\\"])/\\$1/g;
52  
53 0 $s =~ s/([\n\t\r\f\b\a\e])/$special_chars{$1}/ge;
54 0 $s =~ s/([\x00-\x1F\x80-\xFF])/sprintf("\\x%.2xd", ord($1))/ge;
55  
56 0 return $s;
57 }
58  
59  
60 sub update_contents
61 {
62 0 ▶ my ($self) = @_;
Subroutine update_contents: not called CC=1 SCAR=6.9
Pod documented
63  
64 0 open my $contents_fh, ">", "Contents.pm";
65 0 print {$contents_fh}
66 "package Contents;\n\nuse strict;\n\nmy \$contents = \n";
67  
68 0 print {$contents_fh} $self->_stringify_contents();
69  
70 0 print {$contents_fh} <<"EOF";
71  
72 sub get_contents
73 {
74 return \$contents;
75 }
76  
77 1;
78 EOF
79  
80 0 close($contents_fh);
81 }
82  
83 sub _stringify_contents
84 {
85 0 ▶ my $self = shift;
Subroutine _stringify_contents: not called CC=12 SCAR=50.5
86  
87 0 my $contents = $self->_contents();
88  
89 0 my $indent = " ";
90  
91 0 my @branches = ( { 'b' => $contents, 'i' => -1 } );
92  
93 0 my $ret = "";
94  
95 0 ▶MAIN_LOOP: while ( @branches > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (@branches > 0) 0 0 0
96 {
97 0 my $last_element = $branches[$#branches];
98 0 my $b = $last_element->{'b'};
99 0 my $i = $last_element->{'i'};
100 0 my $p1 = $indent x ( 2 * ( scalar(@branches) - 1 ) );
101 0 my $p2 = $p1 . $indent;
102 0 my $p3 = $p2 . $indent;
103 0 ▶ if ( $i < 0 )
Branch: 2 branches
BranchTrueFalseTotal
if ($i < 0) { } 0 0 0
elsif (not exists $b->{'subs'} or $i >= scalar @{$b->{'subs'};}) { } 0 0 0
104 {
105 0 $ret .= "${p1}\{\n";
106 0 foreach my $field (qw(url title))
107 {
108 0 ▶ if ( exists( $b->{$field} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $b->{$field}) 0 0 0
109 {
110 $ret .= "${p2}'$field' => \""
111 0 . _string_to_perl( $b->{$field} ) . "\",\n";
112 }
113 }
114  
115 0 ▶ if ( exists( $b->{'subs'} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $b->{"subs"}) 0 0 0
116 {
117 0 $ret .= "${p2}'subs' =>\n";
118 0 $ret .= "${p2}\[\n";
119  
120 # push @branches { 'b' => $b->{'subs'} }
121 }
122 0 $last_element->{'i'} = 0;
123 0 next MAIN_LOOP;
124 }
125 ▶ elsif (( !exists( $b->{'subs'} ) )
Condition0%0/3
not exists $b->{"subs"} or $i >= scalar @{$b->{"subs"};}
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $b->{"subs"} or $i >= scalar @{$b->{"subs"};}
not exists $b->{"subs"} $i >= scalar @{$b->{"subs"};}
Truth table0%0/3
not(A) or B
A= not exists $b->{"subs"}B= $i >= scalar @{$b->{"subs"};}
ABresult
1X1
011
000
126 0 || ( $i >= scalar( @{ $b->{'subs'} } ) ) )
127 {
128 0 ▶ $ret .= "${p2}],\n" if ( exists( $b->{'subs'} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $b->{"subs"} 0 0 0
129 0 ▶ if ( exists( $b->{'images'} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $b->{"images"}) 0 0 0
130 {
131 0 $ret .= "${p2}'images' =>\n";
132 0 $ret .= "${p2}\[\n";
133 0 foreach my $img ( @{ $b->{'images'} } )
134 {
135 0 $ret .= "${p3}\"" . _string_to_perl($img) . "\",\n";
136 }
137 0 $ret .= "${p2}],\n";
138 }
139 0 pop(@branches);
140 0 ▶ $ret .= "${p1}}" . ( ( @branches > 0 ) ? "," : ";" ) . "\n";
Branch: 1 branch
BranchTrueFalseTotal
@branches > 0 ? : 0 0 0
141 0 next MAIN_LOOP;
142 }
143 else
144 {
145 0 push @branches, { 'b' => $b->{'subs'}->[$i], 'i' => -1 };
146 0 ++( $last_element->{'i'} );
147 0 next MAIN_LOOP;
148 }
149 }
150  
151 0 return $ret;
152 }
153  
154 1 1;
155  
156 __END__
157  
158 =pod
159  
160 =encoding UTF-8
161  
162 =head1 NAME
163  
164 QuadPres::WriteContents - write the contents.
165  
166 =head1 VERSION
167  
168 version 0.28.4
169  
170 =head1 SYNOPSIS
171  
172 my $obj = QuadPres::WriteContents->new({contents => $contents, });
173 $obj->update_contents();
174  
175 =head1 DESCTIPTION
176  
177 QuadPres::WriteContents.
178  
179 =head1 METHODS
180  
181 =head2 $writer->update_contents()
182  
183 Overwrite Contents.pm with the updated contents perl code.
184  
185 =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
186  
187 =head1 SUPPORT
188  
189 =head2 Websites
190  
191 The following websites have more information about this module, and may be of help to you. As always,
192 in addition to those websites please use your favorite search engine to discover more resources.
193  
194 =over 4
195  
196 =item *
197  
198 MetaCPAN
199  
200 A modern, open-source CPAN search engine, useful to view POD in HTML format.
201  
202 L<https://metacpan.org/release/QuadPres>
203  
204 =item *
205  
206 RT: CPAN's Bug Tracker
207  
208 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
209  
210 L<https://rt.cpan.org/Public/Dist/Display.html?Name=QuadPres>
211  
212 =item *
213  
214 CPANTS
215  
216 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
217  
218 L<http://cpants.cpanauthors.org/dist/QuadPres>
219  
220 =item *
221  
222 CPAN Testers
223  
224 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
225  
226 L<http://www.cpantesters.org/distro/Q/QuadPres>
227  
228 =item *
229  
230 CPAN Testers Matrix
231  
232 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
233  
234 L<http://matrix.cpantesters.org/?dist=QuadPres>
235  
236 =item *
237  
238 CPAN Testers Dependencies
239  
240 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
241  
242 L<http://deps.cpantesters.org/?module=QuadPres>
243  
244 =back
245  
246 =head2 Bugs / Feature Requests
247  
248 Please report any bugs or feature requests by email to C<bug-quadpres at rt.cpan.org>, or through
249 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=QuadPres>. You will be automatically notified of any
250 progress on the request by the system.
251  
252 =head2 Source Code
253  
254 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
255 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
256 from your repository :)
257  
258 L<https://github.com/shlomif/quad-pres>
259  
260 git clone https://github.com/shlomif/quad-pres.git
261  
262 =head1 AUTHOR
263  
264 Shlomi Fish <shlomif@cpan.org>
265  
266 =head1 BUGS
267  
268 Please report any bugs or feature requests on the bugtracker website
269 L<https://github.com/shlomif/quad-pres/issues>
270  
271 When submitting a bug or request, please include a test-file or a
272 patch to an existing test-file that illustrates the bug or desired
273 feature.
274  
275 =head1 COPYRIGHT AND LICENSE
276  
277 This software is Copyright (c) 2019 by Shlomi Fish.
278  
279 This is free software, licensed under:
280  
281 The MIT (X11) License
282  
283 =cut
« blib/lib/QuadPres/Url.pm ↑ Summary blib/lib/QuadPres.pm »