blib/lib/QuadPres.pm

filter: Statementstmt 9.3% 34 / 365 Branchbran 0.0% 0 / 76 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 23.8% 10 / 42 Podpod 0.0% 0 / 26 totaltotal 8.1% 44 / 537 CC 52 SCAR 28.2
CC
52
Cov
7%
get_next_url
56.0
get_relative_url__depcracated
42.0
get_last_url
30.0
CRAP 16.8
« blib/lib/QuadPres/WriteContents.pm ↑ Summary blib/lib/QuadPres/FS.pm »
1 package QuadPres;
2 1 $QuadPres::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  
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use parent 'QuadPres::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use IO::All qw/ io /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use QuadPres::Url ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use HTML::Widgets::NavMenu::EscapeHtml qw(escape_html);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 my $navigation_style_class = "nav";
18 1 my $contents_style_class = "contents";
19  
20 1 __PACKAGE__->mk_acc_ref(
21 [
22 qw(
23 contents
24 coords
25 doc_id
26 doc_id_slash_terminated
27 mode
28 navigation_bar
29 stage_idx
30 )
31 ]
32 );
33  
34 sub _init
35 {
36 0 ▶ my $self = shift;
Subroutine _init: not called CC=4 SCAR=30.0
37  
38 0 $self->contents(shift);
39  
40 0 my %args = (@_);
41  
42 0 my $doc_id = $args{'doc_id'};
43  
44 0 ▶ $self->mode( $args{'mode'} || "server" );
Condition0%0/2
$args{'mode'} || 'server'
l!l
00
MC/DC0%0/1
$args{'mode'} || 'server'
$args{'mode'}
Truth table0%0/2
A
A= $args{'mode'}
Aresult
11
00
45  
46 0 ▶ $self->stage_idx( $args{'stage_idx'} || 0 );
Condition0%0/2
$args{'stage_idx'} || 0
l!l
00
MC/DC0%0/1
$args{'stage_idx'} || 0
$args{'stage_idx'}
Truth table0%0/2
A
A= $args{'stage_idx'}
Aresult
11
00
47  
48 0 $self->_populate_doc_id($doc_id);
49  
50 0 ▶ $self->doc_id_slash_terminated( ( $doc_id =~ /\/$/ ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$doc_id =~ m[/$]u ? : 0 0 0
51  
52 0 return 0;
53 }
54  
55 sub _populate_doc_id
56 {
57 0 ▶ my $self = shift;
Subroutine _populate_doc_id: not called CC=2 SCAR=17.9
58  
59 0 my $doc_id = shift;
60  
61 0 my $doc_id_parsed = [ split( /\//, $doc_id ) ];
62  
63 0 $self->_populate_coords($doc_id_parsed);
64  
65 0 my @coords = @{ $self->coords() };
66 0 my $b = $self->contents;
67  
68 0 foreach my $c (@coords)
69 {
70 0 $b = $b->{'subs'}->[$c];
71 }
72  
73 $self->doc_id(
74 QuadPres::Url->new(
75 0 $doc_id_parsed, exists( $b->{'subs'} ),
76 $self->mode,
77 )
78 );
79  
80 0 return;
81 }
82  
83 sub _populate_coords
84 {
85 0 ▶ my $self = shift;
Subroutine _populate_coords: not called CC=3 SCAR=24.8
86  
87 0 my $doc_id_parsed = shift;
88 0 ▶ if ( !defined( $self->coords ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->coords) 0 0 0
89 {
90 0 my %locs;
91 my $traverse;
92  
93 $traverse = sub {
94 0 ▶ my $coords = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
95 0 my $branch = shift;
96 0 my $path = shift;
97  
98 0 push @$path, $branch->{'url'};
99  
100 0 $locs{ join( "/", @$path[ 1 .. $#$path ] ) } = [ @{$coords} ];
101 0 ▶ if ( exists( $branch->{'subs'} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $branch->{"subs"}) 0 0 0
102 {
103 0 my $i;
104  
105 0 ▶ for ( $i = 0 ; $i < scalar( @{ $branch->{'subs'} } ) ; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$branch->{"subs"};}) 0 0 0
106 {
107 $traverse->(
108 [ @$coords, $i ],
109 0 $branch->{'subs'}->[$i], [@$path],
110 );
111 }
112 }
113 0 };
114  
115 0 $traverse->( [], $self->contents, [], );
116  
117 0 if (0)
118 {
119 print "Content-Type: text/plain\n\n";
120 my $d = Data::Dumper->new( [ \%locs ], ["locs"] );
121 print $d->Dump();
122 }
123  
124 0 my $document_id = join( "/", @{$doc_id_parsed} );
125 0 ▶ if ( !exists( $locs{$document_id} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $locs{$document_id}) 0 0 0
126 {
127 0 die "Pres::get_coords(): Could not find the document \""
128 . $document_id . "\".";
129 }
130 0 $self->coords( [ @{ $locs{$document_id} } ] );
131 }
132  
133 0 return;
134 }
135  
136 sub get_document_base_text
137 {
138 0 ▶ my $self = shift;
Subroutine get_document_base_text: not called CC=4 SCAR=30.0
Pod undocumented
139  
140 0 my $document_id = join( "/", @{ $self->doc_id->get_url() } );
141  
142 0 my $filename = "./src/" . $document_id;
143  
144 0 my $index_fn = $filename . "/index.html";
145  
146 0 ▶ if ( -f $filename )
Branch: 2 branches
BranchTrueFalseTotal
if (-f $filename) { } 0 0 0
elsif (-d $filename and -f $index_fn) { } 0 0 0
147 {
148 0 return scalar( io->file($filename)->slurp );
149 }
150 ▶ elsif ( ( -d $filename ) && ( -f $index_fn ) )
Condition0%0/3
-d $filename and -f $index_fn
!ll&&!rl&&r
000
MC/DC0%0/2
-d $filename and -f $index_fn
-d $filename -f $index_fn
Truth table0%0/3
A and B
A= -d $filenameB= -f $index_fn
ABresult
0X0
100
111
151 {
152 0 return scalar( io->file($index_fn)->slurp );
153 }
154 else
155 {
156 0 die "Could not find the file \"" . $document_id . "\"";
157 }
158 }
159  
160 sub get_url_by_coords
161 {
162 0 ▶ my $self = shift;
Subroutine get_url_by_coords: not called CC=3 SCAR=24.8
Pod undocumented
163  
164 0 my @coords = @{ shift(@_) };
165  
166 0 my @url;
167  
168 0 my $b = $self->contents;
169  
170 0 foreach my $c (@coords)
171 {
172 0 $b = $b->{'subs'}->[$c];
173 0 my $comp = $b->{url};
174  
175 0 ▶ if ( !defined($comp) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $comp) 0 0 0
176 {
177 0 Carp::confess("undef component.");
178 }
179 0 push @url, $comp;
180 }
181  
182 0 return QuadPres::Url->new( \@url, exists( $b->{'subs'} ), $self->mode );
183 }
184  
185 sub get_contents_url
186 {
187 0 ▶ my $self = shift;
Subroutine get_contents_url: not called CC=1 SCAR=6.9
Pod undocumented
188  
189 0 return QuadPres::Url->new( [], 1, $self->mode );
190 }
191  
192 sub get_last_url
193 {
194 0 ▶ my $self = shift;
Subroutine get_last_url: not called CC=5 SCAR=34.0
Pod undocumented
195  
196 0 my $b = $self->contents;
197  
198 0 my @path;
199  
200 my $b_subs;
201  
202 my $fetch = sub {
203 0 ▶ $b_subs = $b->{subs};
Subroutine __ANON__: not called CC=1 SCAR=6.9
204 0 };
205  
206 0 $fetch->();
207  
208 0 ▶ while ( defined($b_subs) && @$b_subs )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $b_subs and @$b_subs) 0 0 0
Condition0%0/3
defined $b_subs and @$b_subs
!ll&&!rl&&r
000
MC/DC0%0/2
defined $b_subs and @$b_subs
defined $b_subs @$b_subs
Truth table0%0/3
A and B
A= defined $b_subsB= @$b_subs
ABresult
0X0
100
111
209 {
210 0 my $last_branch = $b_subs->[-1];
211 0 my $url = $last_branch->{url};
212 0 ▶ if ( !defined($url) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $url) 0 0 0
213 {
214 0 Carp::confess("undef URL.");
215 }
216 0 push @path, $url;
217 0 $b = $last_branch;
218 0 $fetch->();
219 }
220  
221 0 ▶ return QuadPres::Url->new( [@path], ( exists( $b->{subs} ) ? 1 : 0 ),
Branch: 1 branch
BranchTrueFalseTotal
exists $b->{'subs'} ? : 0 0 0
222 $self->mode );
223 }
224  
225 sub get_next_url
226 {
227 0 ▶ my $self = shift;
Subroutine get_next_url: not called CC=7 SCAR=40.3
Pod undocumented
228  
229 0 my @coords = @{ $self->coords };
230  
231 0 my @branches = ( $self->contents );
232  
233 0 my @dest_coords;
234  
235 my $i;
236  
237 0 ▶ for ( $i = 0 ; $i < scalar(@coords) ; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @coords) 0 0 0
238 {
239 0 $branches[ $i + 1 ] = $branches[$i]->{'subs'}->[ $coords[$i] ];
240 }
241  
242 0 my $subs = $branches[$i]->{'subs'};
243 0 ▶ if ( defined $subs && @$subs )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subs and @$subs) { } 0 0 0
Condition0%0/3
defined $subs and @$subs
!ll&&!rl&&r
000
MC/DC0%0/2
defined $subs and @$subs
defined $subs @$subs
Truth table0%0/3
A and B
A= defined $subsB= @$subs
ABresult
0X0
100
111
244 {
245 0 @dest_coords = ( @coords, 0 );
246 }
247 else
248 {
249 0 ▶ for ( $i-- ; $i >= 0 ; $i-- )
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 0 0 0
250 {
251 0 ▶ if ( @{ $branches[$i]->{'subs'} } > ( $coords[$i] + 1 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (@{$branches[$i]{"subs"};} > $coords[$i] + 1) 0 0 0
252 {
253 0 @dest_coords = ( @coords[ 0 .. ( $i - 1 ) ], $coords[$i] + 1 );
254 0 last;
255 }
256 }
257 0 ▶ if ( $i == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i == -1) 0 0 0
258 {
259 0 return;
260 }
261 }
262  
263 0 return $self->get_url_by_coords( \@dest_coords );
264 }
265  
266 sub get_most_advanced_leaf
267 {
268 0 ▶ my $self = shift;
Subroutine get_most_advanced_leaf: not called CC=3 SCAR=24.8
Pod undocumented
269  
270 # We accept as a parameter the vector of coordinates
271 0 my $coords_ref = shift;
272  
273 0 my @coords = @{$coords_ref};
274  
275 # Get a reference to the contents HDS (= hierarchial data structure)
276 0 my $branch = $self->contents;
277  
278 # Get to the current branch by advancing to the offset
279 0 foreach my $c (@coords)
280 {
281 # Advance to the next level which is at index $c
282 0 $branch = $branch->{'subs'}->[$c];
283 }
284  
285 # As long as there is something deeper
286 0 ▶ while ( exists( $branch->{'subs'} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $branch->{"subs"}) 0 0 0
287 {
288 # Get the index of the most advanced sub-branch
289 0 my $index = scalar( @{ $branch->{'subs'} } ) - 1;
290  
291 # We are going to return it, so store it
292 0 push @coords, $index;
293  
294 # Recurse into the sub-branch
295 0 $branch = $branch->{'subs'}->[$index];
296 }
297  
298 0 return \@coords;
299 }
300  
301 sub get_prev_url
302 {
303 0 ▶ my $self = shift;
Subroutine get_prev_url: not called CC=4 SCAR=30.0
Pod undocumented
304  
305 0 my @coords = @{ $self->coords };
306  
307 0 ▶ if ( scalar(@coords) == 0 )
Branch: 3 branches
BranchTrueFalseTotal
if (scalar @coords == 0) { } 0 0 0
elsif ($coords[$#coords] > 0) { } 0 0 0
elsif (scalar @coords > 0) { } 0 0 0
308 {
309 0 return;
310 }
311 elsif ( $coords[$#coords] > 0 )
312 {
313 # Get the previous leaf
314 0 my @previous_leaf =
315 ( @coords[ 0 .. ( $#coords - 1 ) ], $coords[$#coords] - 1 );
316  
317 # Continue in this leaf to the end.
318 0 my $new_coords = $self->get_most_advanced_leaf( \@previous_leaf );
319  
320 0 return $self->get_url_by_coords($new_coords);
321 }
322 elsif ( scalar(@coords) > 0 )
323 {
324 0 return $self->get_url_by_coords( [ @coords[ 0 .. ( $#coords - 1 ) ] ] );
325 }
326 else
327 {
328 0 return;
329 }
330 }
331  
332 sub get_up_url
333 {
334 0 ▶ my $self = shift;
Subroutine get_up_url: not called CC=2 SCAR=17.9
Pod undocumented
335  
336 0 my @coords = @{ $self->coords };
337  
338 0 ▶ if ( scalar(@coords) == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @coords == 0) { } 0 0 0
339 {
340 0 return;
341 }
342 else
343 {
344 0 return $self->get_url_by_coords( [ @coords[ 0 .. ( $#coords - 1 ) ] ] );
345 }
346 }
347  
348 sub get_relative_url__depcracated
349 {
350 0 ▶ my @this_url = @{ shift(@_) };
Subroutine get_relative_url__depcracated: not called CC=6 SCAR=37.4
Pod undocumented
351 0 my @other_url = @{ shift(@_) };
352 0 my $slash_terminated = shift;
353  
354 0 ▶ while (scalar(@this_url)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @this_url and scalar @other_url and $this_url[0] eq $other_url[0]) 0 0 0
Condition0%0/5
scalar @this_url and scalar @other_url and $this_url[0] eq $other_url[0]
!ll&&!rl&&r
000
scalar @this_url and scalar @other_url
!ll
00
MC/DC0%0/2
scalar @this_url and scalar @other_url and $this_url[0] eq $other_url[0]
scalar @this_url $this_url[0] eq $other_url[0]
Truth table0%0/3
A and B
A= scalar @this_urlB= $this_url[0] eq $other_url[0]
ABresult
0X0
100
111
355 && scalar(@other_url)
356 && ( $this_url[0] eq $other_url[0] ) )
357 {
358 0 shift(@this_url);
359 0 shift(@other_url);
360 }
361  
362 0 my $ret = "";
363  
364 0 ▶ if ($slash_terminated)
Branch: 1 branch
BranchTrueFalseTotal
if ($slash_terminated) { } 0 0 0
365 {
366 0 $ret .= join( "/", ( map { ".." } @this_url ), @other_url );
367 }
368 else
369 {
370 $ret .= (
371 join( "/",
372 0 ( map { ".." } @this_url[ 1 .. $#this_url ] ), @other_url )
373 );
374 0 ▶ $ret = "./$ret" if ( not length $ret );
Branch: 1 branch
BranchTrueFalseTotal
unless length $ret 0 0 0
375 }
376  
377 0 return $ret;
378 }
379  
380 sub get_control_url
381 {
382 0 ▶ my $self = shift;
Subroutine get_control_url: not called CC=2 SCAR=17.9
Pod undocumented
383  
384 0 my $other_url = shift;
385  
386 0 ▶ if ( !defined($other_url) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $other_url) 0 0 0
387 {
388 0 return;
389 }
390  
391 0 my $this_url = $self->doc_id;
392  
393 0 return $this_url->get_relative_url( $other_url,
394 $self->doc_id_slash_terminated );
395 }
396  
397 sub get_control_text
398 {
399 0 ▶ my $self = shift;
Subroutine get_control_text: not called CC=2 SCAR=17.9
Pod undocumented
400  
401 0 my $spec = shift;
402  
403 0 my $text = "";
404  
405 0 my $this_url = $self->doc_id;
406  
407 0 my $other_url = $spec->{'url'}->($self);
408  
409 0 ▶ if ( defined($other_url) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $other_url) { } 0 0 0
410 {
411  
412 0 $text .=
413 "<a href=\""
414 . $self->get_control_url($other_url)
415 . "\" class=\""
416 . $navigation_style_class . "\">";
417  
418 0 $text .= $spec->{'caption'};
419  
420 0 $text .= "</a>";
421 }
422 else
423 {
424 $text .=
425 "<b class=\""
426 . $navigation_style_class . "\">"
427 0 . $spec->{'caption'} . "</b>";
428 }
429  
430 0 return $text;
431 }
432  
433 sub get_navigation_bar
434 {
435 0 ▶ my $self = shift;
Subroutine get_navigation_bar: not called CC=2 SCAR=17.9
Pod undocumented
436  
437 0 ▶ if ( !defined( $self->navigation_bar ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->navigation_bar) 0 0 0
438 {
439 # Render the Navigation Bar
440 0 my $text = "";
441 0 my @controls;
442  
443 0 $text .= "<table>\n";
444 0 $text .= "<tr>\n";
445 0 $text .= "<td>\n";
446  
447 0 push @controls,
448 (
449 $self->get_control_text(
450 {
451 'url' => \&get_contents_url,
452 'caption' => "Contents",
453 },
454 )
455 );
456  
457 0 push @controls,
458 (
459 $self->get_control_text(
460 {
461 'url' => \&get_up_url,
462 'caption' => "Up",
463 },
464 )
465 );
466  
467 0 push @controls,
468 (
469 $self->get_control_text(
470 {
471 'url' => \&get_prev_url,
472 'caption' => "Previous",
473 },
474 )
475 );
476  
477 0 push @controls,
478 (
479 $self->get_control_text(
480 {
481 'url' => \&get_next_url,
482 'caption' => "Next",
483 },
484 )
485 );
486  
487 0 $text .= join( "</td>\n<td>\n", @controls );
488  
489 0 $text .= "</td>\n";
490 0 $text .= "</tr>\n";
491 0 $text .= "</table>\n";
492 0 $text .= "\n";
493  
494 #$text .= "<br><br>";
495  
496 0 $self->navigation_bar($text);
497 }
498  
499 0 return $self->navigation_bar;
500 }
501  
502 sub get_subject_by_coords
503 {
504 0 ▶ my $self = shift;
Subroutine get_subject_by_coords: not called CC=2 SCAR=17.9
Pod undocumented
505 0 my $coords_ref = shift;
506  
507 0 my $branch = $self->contents;
508  
509 0 my @coords = @$coords_ref;
510  
511 0 ▶ for ( my $i = 0 ; $i < scalar(@coords) ; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @coords) 0 0 0
512 {
513 0 $branch = $branch->{'subs'}->[ $coords[$i] ];
514 }
515  
516 0 return $branch->{'title'};
517 }
518  
519 sub get_subject
520 {
521 0 ▶ my $self = shift;
Subroutine get_subject: not called CC=1 SCAR=6.9
Pod undocumented
522  
523 0 return $self->get_subject_by_coords( $self->coords );
524 }
525  
526 sub get_title
527 {
528 0 ▶ my $self = shift;
Subroutine get_title: not called CC=2 SCAR=17.9
Pod undocumented
529  
530 0 my @coords = @{ $self->coords };
531  
532 0 my @coords_plus_1 = ( map { $_ + 1; } @coords );
533 0 my $indexes_str = join( ".", @coords_plus_1 );
534 0 ▶ if ( scalar(@coords) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @coords) 0 0 0
535 {
536 0 $indexes_str .= ". ";
537 }
538  
539 0 return $indexes_str . $self->get_subject();
540 }
541  
542 sub get_style_css_url
543 {
544 0 ▶ my $self = shift;
Subroutine get_style_css_url: not called CC=1 SCAR=6.9
Pod undocumented
545  
546 0 return $self->doc_id->get_relative_url(
547 QuadPres::Url->new( ["style.css"], 0, $self->mode ),
548 $self->doc_id_slash_terminated );
549 }
550  
551 sub get_header
552 {
553 0 ▶ my $self = shift;
Subroutine get_header: not called CC=1 SCAR=6.9
Pod undocumented
554  
555 0 my $text = "";
556 0 my $branch;
557  
558 0 my @coords = @{ $self->coords };
559  
560 0 $text .= "<html>\n";
561 0 $text .= "<head>\n";
562 0 $text .= "<title>" . $self->get_subject() . "</title>\n";
563 0 $text .=
564 "<link rel=\"StyleSheet\" href=\""
565 . $self->get_style_css_url
566 . "\" type=\"text/css\">\n";
567  
568 0 $text .= "</head>\n";
569 0 $text .= "<body>\n";
570 0 $text .= $self->get_navigation_bar();
571  
572 0 $text .= "<h1 class=\"fcs\">" . $self->get_title() . "</h1>";
573  
574 0 return $text;
575 }
576  
577 sub get_footer
578 {
579 0 ▶ my $self = shift;
Subroutine get_footer: not called CC=1 SCAR=6.9
Pod undocumented
580  
581 0 my $text = "";
582  
583 0 $text .= "\n\n<hr>\n";
584  
585 0 $text .= $self->get_navigation_bar();
586  
587 0 $text .= "</body>\n";
588 0 $text .= "</html>\n";
589  
590 0 return $text;
591 }
592  
593 sub get_contents_helper
594 {
595 0 ▶ my $self = shift;
Subroutine get_contents_helper: not called CC=3 SCAR=24.8
Pod undocumented
596  
597 0 my $branch = shift;
598 0 my $url = shift;
599 0 my $coords_ref = shift;
600 0 my @coords = @{$coords_ref};
601  
602 0 my $text = "";
603 0 $text .= "<li>";
604 $text .=
605 "<a href=\""
606 . $self->doc_id->get_relative_url(
607 0 QuadPres::Url->new( [@$url], exists( $branch->{'subs'} ), $self->mode )
608 )
609 . "\" class=\""
610 . $contents_style_class . "\">";
611 0 my @coords_plus_1 = ( map { $_ + 1; } @coords );
612 0 $text .= join( ".", @coords_plus_1 );
613 0 $text .= ". ";
614 0 $text .= $branch->{'title'};
615 0 $text .= "</a>\n";
616  
617 0 ▶ if ( exists( $branch->{'subs'} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $branch->{"subs"}) 0 0 0
618 {
619 0 $text .= "<ul class=\"$contents_style_class\">\n";
620 0 my $index = 0;
621 0 foreach my $sb ( @{ $branch->{'subs'} } )
622 {
623 $text .= $self->get_contents_helper(
624 $sb,
625 0 [ @$url, $sb->{'url'} ],
626 [ @coords, $index ],
627 );
628 0 $index++;
629 }
630 0 $text .= "</ul>\n";
631 }
632 0 $text .= "</li>";
633 0 return $text;
634 }
635  
636 sub get_contents
637 {
638 0 ▶ my $self = shift;
Subroutine get_contents: not called CC=4 SCAR=30.0
Pod undocumented
639  
640 0 my $text = "";
641  
642 0 my @coords = @{ $self->coords };
643 0 my @url;
644  
645 0 my $b = $self->contents;
646  
647 0 my $i;
648  
649 0 ▶ for ( $i = 0 ; $i < scalar(@coords) ; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @coords) 0 0 0
650 {
651 0 $b = $b->{'subs'}->[ $coords[$i] ];
652 0 push @url, $b->{'url'};
653 }
654  
655 0 ▶ if ( exists( $b->{'subs'} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $b->{"subs"}) 0 0 0
656 {
657 0 ▶ for ( $i = 0 ; $i < scalar( @{ $b->{'subs'} } ) ; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$b->{"subs"};}) 0 0 0
658 {
659 $text .= $self->get_contents_helper(
660 $b->{'subs'}->[$i],
661 0 [ @url, $b->{'subs'}->[$i]->{'url'} ],
662 [ @coords, $i ],
663 );
664 }
665 }
666  
667 return
668 0 "<ul class=\"$contents_style_class"
669 . "main\">\n"
670 . $text
671 . "</ul>\n"; # The wrapping <ul>'s are
672 # meant to make sure there are no spaces between the various
673 # lines.
674 # It just works.
675 }
676  
677 sub get_menupath_text
678 {
679 # We are not using $self, but it may prove useful in the future, so a
680 # stitch in time saves nine. So for the while get_menupath_text is treated
681 # as a method function.
682 0 ▶ my $self = shift;
Subroutine get_menupath_text: not called CC=1 SCAR=6.9
Pod undocumented
683  
684 0 my $inside = shift;
685  
686 # Remove new-lines
687 0 $inside =~ s/\n//g;
688  
689 # Remove the existing <tt>'s and such.
690 0 $inside =~ s/< *\/? *tt *>//;
691  
692 # convert these ampersand escapes to normal text.
693 0 if (0)
694 {
695 $inside =~ s/&(amp|lt|gt);/
696 (($1 eq "amp") ?
697 "&" :
698 ($1 eq "lt") ?
699 "<" :
700 ">"
701 )
702 /ge;
703 }
704  
705 # Split to the menu path components
706 0 my @components = split( /\s*-&gt;\s*/, $inside );
707  
708 # Wrap the components of the path with the HTML Cascading Style
709 # Sheets Magic
710 my @components_rendered =
711 0 map { "\n<b class=\"menupathcomponent\">\n" . $_ . "\n" . "</b>\n" }
712 @components;
713  
714 # An arrow wrapped in CSS magic.
715 0 my $separator_string =
716 "\n <font class=\"menupathseparator\">\n" . "-&gt;" . "</font> \n";
717  
718 0 my $final_string = join( $separator_string, @components_rendered );
719  
720 0 $final_string =
721 ( "&nbsp;" x 2 )
722 . "<font class=\"menupath\">"
723 . $final_string
724 . "</font>";
725  
726 0 return $final_string;
727 }
728  
729 sub process_document_text
730 {
731 0 ▶ my $self = shift;
Subroutine process_document_text: not called CC=1 SCAR=6.9
Pod undocumented
732  
733 0 my $text = shift;
734  
735 0 my $header = $self->get_header();
736 0 my $footer = $self->get_footer();
737 0 my $contents = $self->get_contents();
738  
739 0 $text =~
740 s/<!-+ *\& *begin_header *-+>[\x00-\xFF]*?<!-+ *\& *end_header *-+>/$header/;
741 0 $text =~
742 s/<!-+ *\& *begin_footer *-+>[\x00-\xFF]*?<!-+ *\& *end_footer *-+>/$footer/;
743 0 $text =~
744 s/<!-+ *\& *begin_contents *-+>[\x00-\xFF]*?<!-+ *\& *end_contents *-+>/$contents/;
745 0 $text =~
746 0 s/<!-+ *\& *begin_menupath *-+>([\x00-\xFF]*?)<!-+ *\& *end_menupath *-+>/$self->get_menupath_text($1)/ge;
747  
748 0 return $text;
749 }
750  
751 sub render_text
752 {
753 0 ▶ my $self = shift;
Subroutine render_text: not called CC=1 SCAR=6.9
Pod undocumented
754  
755 0 my $base_text = $self->get_document_base_text();
756 0 my $text = $self->process_document_text($base_text);
757  
758 0 return $text;
759 }
760  
761 sub render
762 {
763 0 ▶ my $self = shift;
Subroutine render: not called CC=4 SCAR=30.0
Pod undocumented
764 0 eval {
765 0 $self->_populate_coords();
766 0 my $text = $self->render_text();
767 0 ▶ if ( $self->mode eq 'cgi' )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mode eq "cgi") 0 0 0
768 {
769 0 print "Content-Type: text/html\n\n";
770 }
771 0 print $text;
772 };
773  
774 0 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
775 {
776 0 ▶ if ( $self->mode eq 'cgi' )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mode eq "cgi") 0 0 0
777 {
778 0 print "Content-Type: text/plain\n\n";
779 }
780 0 print "Error!\n\n";
781 0 print $@;
782 }
783  
784 0 return;
785 }
786  
787 sub traverse_tree
788 {
789 0 ▶ my $self = shift;
Subroutine traverse_tree: not called CC=1 SCAR=6.9
Pod undocumented
790 0 my $callback = shift;
791  
792 0 my $contents = $self->contents;
793  
794 0 my $traverse_helper;
795 $traverse_helper = sub {
796 0 ▶ my $path_ref = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
797 0 my $coords = shift;
798 0 my $branch = shift;
799  
800 0 $callback->(
801 'path' => $path_ref,
802 'branch' => $branch,
803 'coords' => $coords,
804 );
805  
806 0 ▶ if ( exists( $branch->{'subs'} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $branch->{"subs"}) 0 0 0
807 {
808 # Let's traverse all the directories
809 0 my $new_coord = 0;
810 0 foreach my $sub_branch ( @{ $branch->{'subs'} } )
811 {
812 $traverse_helper->(
813 0 [ @$path_ref, $sub_branch->{'url'} ],
814 [ @$coords, $new_coord ], $sub_branch,
815 );
816 }
817 continue
818 {
819 0 $new_coord++;
820 }
821 }
822 0 };
823  
824 0 $traverse_helper->( [], [], $contents );
825  
826 0 return;
827 }
828  
829 sub get_breadcrumbs_trail
830 {
831 0 ▶ my $qp = shift;
Subroutine get_breadcrumbs_trail: not called CC=3 SCAR=24.8
Pod undocumented
832 0 my $sep = shift;
833  
834 0 ▶ if ( !defined($sep) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sep) 0 0 0
835 {
836 0 $sep = " → ";
837 }
838  
839 0 my @abs_coords = @{ $qp->{'coords'} };
840  
841 0 my @strs;
842 0 for my $end ( (-1) .. $#abs_coords )
843 {
844 0 my @coords = @abs_coords[ 0 .. $end ];
845 0 my $s =
846 "<a href=\""
847 . escape_html(
848 $qp->get_control_url( $qp->get_url_by_coords( \@coords ) ) )
849 . "\">"
850 . $qp->get_subject_by_coords( \@coords ) . "</a>";
851 0 push @strs, $s;
852 }
853  
854 0 return join( $sep, @strs );
855 }
856  
857 1 1;
858  
859 __END__
860  
861 =pod
862  
863 =encoding UTF-8
864  
865 =head1 NAME
866  
867 QuadPres - a presentation / slides manager.
868  
869 =head1 VERSION
870  
871 version 0.28.2
872  
873 =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
874  
875 =head1 SUPPORT
876  
877 =head2 Websites
878  
879 The following websites have more information about this module, and may be of help to you. As always,
880 in addition to those websites please use your favorite search engine to discover more resources.
881  
882 =over 4
883  
884 =item *
885  
886 MetaCPAN
887  
888 A modern, open-source CPAN search engine, useful to view POD in HTML format.
889  
890 L<https://metacpan.org/release/QuadPres>
891  
892 =item *
893  
894 RT: CPAN's Bug Tracker
895  
896 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
897  
898 L<https://rt.cpan.org/Public/Dist/Display.html?Name=QuadPres>
899  
900 =item *
901  
902 CPANTS
903  
904 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
905  
906 L<http://cpants.cpanauthors.org/dist/QuadPres>
907  
908 =item *
909  
910 CPAN Testers
911  
912 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
913  
914 L<http://www.cpantesters.org/distro/Q/QuadPres>
915  
916 =item *
917  
918 CPAN Testers Matrix
919  
920 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
921  
922 L<http://matrix.cpantesters.org/?dist=QuadPres>
923  
924 =item *
925  
926 CPAN Testers Dependencies
927  
928 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
929  
930 L<http://deps.cpantesters.org/?module=QuadPres>
931  
932 =back
933  
934 =head2 Bugs / Feature Requests
935  
936 Please report any bugs or feature requests by email to C<bug-quadpres at rt.cpan.org>, or through
937 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=QuadPres>. You will be automatically notified of any
938 progress on the request by the system.
939  
940 =head2 Source Code
941  
942 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
943 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
944 from your repository :)
945  
946 L<https://github.com/shlomif/quad-pres>
947  
948 git clone https://github.com/shlomif/quad-pres.git
949  
950 =head1 AUTHOR
951  
952 Shlomi Fish <shlomif@cpan.org>
953  
954 =head1 BUGS
955  
956 Please report any bugs or feature requests on the bugtracker website
957 L<https://github.com/shlomif/quad-pres/issues>
958  
959 When submitting a bug or request, please include a test-file or a
960 patch to an existing test-file that illustrates the bug or desired
961 feature.
962  
963 =head1 COPYRIGHT AND LICENSE
964  
965 This software is Copyright (c) 2019 by Shlomi Fish.
966  
967 This is free software, licensed under:
968  
969 The MIT (X11) License
970  
971 =cut
« blib/lib/QuadPres/WriteContents.pm ↑ Summary blib/lib/QuadPres/FS.pm »