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