blib/lib/Text/Slidez.pm

filter: Statementstmt 25.2% 66 / 261 Branchbran 15.0% 18 / 120 Conditioncond 6.5% 3 / 46 MC/DCmcdc 3.3% 1 / 30 Subroutinesub 35.9% 14 / 39 Podpod 100% 9 / 9 totaltotal 21.9% 111 / 505 CC 84 SCAR 46.2
CC
84
Cov
20%
_handle_parts
420.0
_part_slide
132.0
_mk_script
90.0
CRAP 101.3
↑ Summary
1 package Text::Slidez;
2 2 $VERSION = v0.0.1;
3  
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use base 'Shebangml';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Class::Accessor::Classy;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 lw 'slides';
11 2 ▶no Class::Accessor::Classy;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use XML::Bits qw(T);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 Text::Slidez - format slideshows into XHTML
18  
19 =head1 SYNOPSIS
20  
21 See L<slidez> for the command-line frontend.
22  
23 use Text::Slidez;
24  
25 my $slidez = Text::Slidez->new;
26 $slidez->load('my_slides.hbml');
27 foreach my $slide ($slidez->slides) {
28 ...
29 }
30  
31 =cut
32  
33  
34 =head2 load
35  
36 $slidez->load('my_slides.hbml');
37  
38 =cut
39  
40 1 ▶sub load {
Subroutine load: called CC=5 SCAR=27.1
Pod documented
41 1 my $self = shift;
42 1 my $input = shift;
43  
44 1 local $self->{ctx};
45 1 local $self->{started};
46  
47 1 $self->process($input);
48  
49 # bit of cleanup on the innards:
50 0 foreach my $slide ($self->slides) {
51 my @kids =
52 0 ▶ grep({not ($_->tag eq '' and "$_" eq '')} $slide->children);
Condition0%0/3
$_->tag eq '' && "$_" eq ''
!ll&&!rl&&r
000
MC/DC0%0/2
$_->tag eq '' && "$_" eq ''
$_->tag eq '' "$_" eq ''
Truth table0%0/3
A && B
A= $_->tag eq ''B= "$_" eq ''
ABresult
0X0
100
111
53 0 ▶ shift(@kids) while($kids[0] =~ m/^\s+$/);
Branch: 1 branch
BranchTrueFalseTotal
$kids[0] =~ /^\s+$/ and do { shift @kids } 0 0 0
54 0 ▶ pop(@kids) if($kids[-1] =~ m/^\n\s*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $kids[-1] =~ /^\n\s*$/ 0 0 0
55 0 $slide->{children} = [@kids];
56 }
57  
58 #warn join("\n---\n", @{$self->{slides}});
59 0 return($self);
60 } # load ###############################################################
61  
62 =head2 dump
63  
64 Dump a marked-up version of the raw data.
65  
66 warn $slidez->dump;
67  
68 =cut
69  
70 0 ▶sub dump {
Subroutine dump: not called CC=1 SCAR=6.9
Pod documented
71 0 my $self = shift;
72 return join("\n---\n",
73 0 map({join("|", map({"($_)=" . $_->tag} $_->children))}
74 $self->slides)
75 ), "\n";
76 } # dump ###############################################################
77  
78 =head2 format_slide
79  
80 Format a single slide for output.
81  
82 my $xhtml = $slidez->format_slide($slide, %opts);
83  
84 =cut
85  
86 0 ▶sub format_slide {
Subroutine format_slide: not called CC=5 SCAR=34.0
Pod documented
87 0 my $self = shift;
88 0 my ($slide, %opts) = @_;
89  
90 0 my @parts = $self->_part_slide($slide);
91  
92 # see if we can deduce a title from the first time we see one
93 0 ▶ unless($opts{title} or $self->{title}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"title"} or $self->{"title"}) 0 0 0
Condition0%0/3
$opts{"title"} or $self->{"title"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"title"} or $self->{"title"}
$opts{"title"} $self->{"title"}
Truth table0%0/3
A or B
A= $opts{"title"}B= $self->{"title"}
ABresult
1X1
011
000
94 0 ▶ if($parts[2] and @{$parts[1]} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parts[2] and @{$parts[1];} == 0) 0 0 0
Condition0%0/3
$parts[2] and @{$parts[1];} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$parts[2] and @{$parts[1];} == 0
$parts[2] @{$parts[1];} == 0
Truth table0%0/3
A and B
A= $parts[2]B= @{$parts[1];} == 0
ABresult
0X0
100
111
95 0 my $text = join('', @{$parts[0]});
96 0 ($text) = split(/\n/, $text);
97 0 $text =~ s/<[^>]+>//g;
98 0 $self->{title} = $text;
99 }
100 }
101  
102 0 ▶ my $page = T{html =>
Subroutine __ANON__: not called CC=1 SCAR=6.9
103 0 ▶ T{head =>
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 0 ▶ T{title => $opts{title}||$self->{title}||'slidez'},
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
$opts{"title"} or $self->{"title"} or "slidez" 0 0 0
Condition0%0/3
$opts{"title"} or $self->{"title"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"title"} or $self->{"title"}
$opts{"title"} $self->{"title"}
Truth table0%0/3
A or B
A= $opts{"title"}B= $self->{"title"}
ABresult
1X1
011
000
105 0 ▶ T{meta =>
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 ['http-equiv' => "Content-Type",
107 content => "text/html;charset=utf-8"]},
108 0 ▶ T{meta =>
Subroutine __ANON__: not called CC=1 SCAR=6.9
109 ['http-equiv'=>"Content-Style-Type",
110 content => "text/css"]},
111 0 ▶ T{link =>
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 [rel=> 'stylesheet', href => 'style.css', type => 'text/css']},
113 0 ▶ T{script => [type => 'text/javascript'],
Subroutine __ANON__: not called CC=1 SCAR=6.9
114 $self->_mk_script(%opts);
115 },
116 0 },
117 0 ▶ T{body =>}
Subroutine __ANON__: not called CC=1 SCAR=6.9
118 0 };
119 0 $page->set_doctype('html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
120 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"');
121  
122 0 my $div = $page->child(-1)->create_child(div => [class => 'slide']);
123  
124 $self->_handle_parts($div, \@parts,
125 0 ▶ calc_width => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
126 0 my $n = $self->_calc_width(shift);
127 0 ▶ $n > 20 ? '900px' : $n . 'em';
Branch: 1 branch
BranchTrueFalseTotal
$n > 20 ? : 0 0 0
128 },
129 0 );
130  
131 0 return($page);
132
133 } # format_slide #######################################################
134  
135 =head2 as_single_page
136  
137 $slidez->as_single_page;
138  
139 =cut
140  
141 0 ▶sub as_single_page {
Subroutine as_single_page: not called CC=5 SCAR=34.0
Pod documented
142 0 my $self = shift;
143  
144 0 my @slides = $self->slides;
145  
146 0 ▶ my $page = T{html =>
Subroutine __ANON__: not called CC=1 SCAR=6.9
147 0 ▶ T{head =>
Subroutine __ANON__: not called CC=1 SCAR=6.9
148 0 ▶ T{title => },
Subroutine __ANON__: not called CC=1 SCAR=6.9
149 0 ▶ T{meta =>
Subroutine __ANON__: not called CC=1 SCAR=6.9
150 ['http-equiv' => "Content-Type",
151 content => "text/html;charset=utf-8"]},
152 0 ▶ T{meta =>
Subroutine __ANON__: not called CC=1 SCAR=6.9
153 ['http-equiv'=>"Content-Style-Type",
154 content => "text/css"]},
155 0 ▶ T{link =>
Subroutine __ANON__: not called CC=1 SCAR=6.9
156 [rel=> 'stylesheet', href => 'style-flat.css', type => 'text/css']},
157 0 },
158 0 ▶ T{body =>}
Subroutine __ANON__: not called CC=1 SCAR=6.9
159 0 };
160 0 $page->set_doctype('html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
161 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"');
162  
163 0 my $title = $page->child(0)->child(0);
164 0 my $body = $page->child(-1);
165 0 my $outer = $body->create_child(div => [style=> "width: 600px"]);
166  
167 0 for my $i (0..$#slides) {
168 0 my $div = $outer->create_child(div => [class => 'slide']);
169  
170 0 my @parts = $self->_part_slide($slides[$i]);
171 0 ▶ unless($i) { # look for title on the first slide
Branch: 1 branch
BranchTrueFalseTotal
unless ($i) 0 0 0
172 0 ▶ if($parts[2] and @{$parts[1]} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parts[2] and @{$parts[1];} == 0) 0 0 0
Condition0%0/3
$parts[2] and @{$parts[1];} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$parts[2] and @{$parts[1];} == 0
$parts[2] @{$parts[1];} == 0
Truth table0%0/3
A and B
A= $parts[2]B= @{$parts[1];} == 0
ABresult
0X0
100
111
173 0 my $text = join('', @{$parts[0]});
174 0 ($text) = split(/\n/, $text);
175 0 $text =~ s/^\s+//;
176 0 $text =~ s/<[^>]+>//g;
177 0 $title->create_child(''=> $text);
178 }
179 }
180  
181 #warn "\n\nhandle $i\n\n\n";
182 $self->_handle_parts($div, \@parts,
183 0 ▶ calc_width => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
184 0 my $n = $self->_calc_width(shift);
185 0 ▶ $n > 20 ? '500px' : $n . 'em';
Branch: 1 branch
BranchTrueFalseTotal
$n > 20 ? : 0 0 0
186 },
187 0 );
188  
189 0 $outer->create_child(div =>
190 [class => 'wee', style => "width:100%; text-align: right"],
191 )->create_child('' =>
192 '' => $i+1 . ' / ' . scalar(@slides));
193 0 $outer->create_child(hr =>);
194 }
195  
196 0 return($page);
197 } # as_single_page #####################################################
198  
199 2 my %span_map = (
200 L => 'large',
201 M => 'medium',
202 S => 'small',
203 );
204  
205 5 ▶sub _atag {
Subroutine _atag: called CC=10 SCAR=27.4
206 5 my $self = shift;
207 5 my ($tag, $atts) = @_;
208  
209 5 ▶ my @attr = $atts ? $atts->atts : ();
Branch: 1 branch
BranchTrueFalseTotal
$atts ? : 0 5 5
210 5 ▶ if(my $class = $span_map{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = $span_map{$tag}) 0 5 5
211 0 $tag = 'span';
212 0 push(@attr, class => $class);
213 }
214  
215 5 ▶ my $el = XML::Bits->new($tag, @attr ? \@attr : ());
Branch: 1 branch
BranchTrueFalseTotal
@attr ? : 0 5 5
216  
217 5 ▶ if($self->{ctx}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ctx'}) { } 0 5 5
218 0 ▶ croak("no nested slides") if($tag eq 'slide');
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "slide" 0 0 0
219 0 $self->{ctx}->add_child($el);
220 0 $self->{ctx} = $el;
221 }
222 else {
223 5 ▶ if($tag eq 'slide') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag eq 'slide') { } 4 1 5
elsif ($tag eq 'slides') { } 1 0 1
224 4 ▶ croak("no start element") unless($self->{started});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 0 4 4
225 4 ▶ my $sl = $self->{slides} ||= [];
Condition100%2/2
$self->{"slides"} ||= []
l!l
31
MC/DC100%1/1
$self->{"slides"} ||= []
$self->{"slides"}
Truth table100%2/2
A
A= $self->{"slides"}
Aresult
11
00
226 4 $self->{ctx} = $el;
227 4 push(@$sl, $el);
228 }
229 elsif($tag eq 'slides') {
230 1 $self->{started} = 1;
231 }
232 else {
233 0 croak("content '$tag' outside of slide!");
234 }
235 }
236  
237 5 return($el);
238 }
239  
240 =head2 do_code
241  
242 $slidez->do_code($tag, $atts, $string);
243  
244 =cut
245  
246 1 ▶sub do_code {
Subroutine do_code: called CC=11 SCAR=44.8
Pod documented
247 1 my $self = shift;
248 1 my ($tag, $atts, $string) = @_;
249  
250 1 ▶ my %atts = $atts ? $atts->atts : ();
Branch: 1 branch
BranchTrueFalseTotal
$atts ? : 1 0 1
251  
252 0 ▶ my $make = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
253 0 my $pre = $self->{ctx}->create_child(pre => [%atts]);
254 0 $pre->create_child('' => $_) for(@_);
255 1 };
256  
257 1 my $ft = delete($atts{type});
258  
259 1 require Text::VimColor;
260 0 my $cache;
261 0 ▶ if($string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string) { } 0 0 0
262 # XXX how to do the caching?
263 # warn "string code is slow: $string\n";
264 }
265 else {
266 0 ▶ my $src = delete $atts{src} or croak("must have src");
Branch: 1 branch
BranchTrueFalseTotal
my $src = delete $atts{"src"} or croak("must have src") 0 0 0
267 0 my $input = File::Fu->file($src);
268 0 my $cache_dir = File::Fu->dir('.cache');
269 0 ▶ if($cache_dir->d) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_dir->d) 0 0 0
270 0 $cache = $cache_dir + $input->file;
271 0 ▶ if($cache->e and $cache->stat->mtime >= $input->stat->mtime) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache->e and $cache->stat->mtime >= $input->stat->mtime) 0 0 0
Condition0%0/3
$cache->e and $cache->stat->mtime >= $input->stat->mtime
!ll&&!rl&&r
000
MC/DC0%0/2
$cache->e and $cache->stat->mtime >= $input->stat->mtime
$cache->e $cache->stat->mtime >= $input->stat->mtime
Truth table0%0/3
A and B
A= $cache->eB= $cache->stat->mtime >= $input->stat->mtime
ABresult
0X0
100
111
272 0 warn "load $input from cache\n";
273 0 return($make->(scalar $cache->read));
274 }
275 }
276 0 my %ftmap = (
277 html => 'html',
278 hbml => 'hbml',
279 pl => 'perl',
280 pm => 'perl',
281 );
282 0 ▶ unless($ft) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ft) 0 0 0
283 0 my ($ext) = $input =~ m/\.([^\.]+)$/;
284 0 ▶ $ft = $ftmap{$ext} if($ftmap{$ext});
Branch: 1 branch
BranchTrueFalseTotal
if $ftmap{$ext} 0 0 0
285 }
286 0 $string = $input->read;
287 }
288 0 ▶ my $html = Text::VimColor->new(
Branch: 1 branch
BranchTrueFalseTotal
$ft ? : 0 0 0
289 string => $string,
290 $ft ? (filetype => $ft) : (),
291 )->html;
292  
293 # leading whitespace cleanup
294 0 $html =~ s{<span[^>]*>(\s+)</span>}{$1}g;
295 # pull whitespace out front
296 0 $html =~ s{^(<span [^>]+>)(\s+)}{$2$1}mg;
297 0 $html =~ s/\n+$//;
298 0 $make->($html);
299 0 ▶ $cache->write($html) if($cache);
Branch: 1 branch
BranchTrueFalseTotal
if $cache 0 0 0
300
301 } # do_code ############################################################
302  
303 =head1 Shebangml Callbacks
304  
305 These are really part of the parser class and not the API.
306  
307 =head2 put_tag
308  
309 $slidez->put_tag($tag, $atts, $string);
310  
311 =cut
312  
313 1 ▶sub put_tag {
Subroutine put_tag: called CC=4 SCAR=22.3
Pod documented
314 1 my $self = shift;
315 1 my ($tag, $atts, $string) = @_;
316  
317 1 ▶ return $self->do_code(@_) if($tag eq 'code');
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "code" 1 0 1
318 0 ▶ return $self->do_include($atts) if($tag eq '.include');
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq ".include" 0 0 0
319  
320 0 my $el = $self->_atag($tag, $atts);
321  
322 0 ▶ $el->create_child('' => $self->escape_text($string))
Branch: 1 branch
BranchTrueFalseTotal
if defined $string 0 0 0
323 if(defined($string));
324  
325 0 $self->{ctx} = $el->parent;
326  
327 } # put_tag ############################################################
328  
329 =head2 put_tag_start
330  
331 $slidez->put_tag_start($tag, $atts);
332  
333 =cut
334  
335 5 ▶sub put_tag_start {
Subroutine put_tag_start: called CC=1 SCAR=0.0
Pod documented
336 5 my $self = shift;
337 5 my ($tag, $atts) = @_;
338  
339 5 my $el = $self->_atag($tag, $atts);
340  
341 } # put_tag_start ######################################################
342  
343 =head2 put_tag_end
344  
345 $slidez->put_tag_end($tag);
346  
347 =cut
348  
349 3 ▶sub put_tag_end {
Subroutine put_tag_end: called CC=6 SCAR=19.9
Pod documented
350 3 my $self = shift;
351 3 my ($tag) = @_;
352  
353 3 ▶ $tag = 'span' if($span_map{$tag});
Branch: 1 branch
BranchTrueFalseTotal
if $span_map{$tag} 0 3 3
354  
355 3 my $ctx = delete($self->{ctx});
356 3 ▶ return() if($tag eq 'slides');
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "slides" 0 3 3
357 3 ▶ ($ctx->tag eq $tag) or croak($ctx->tag, " is not a $tag!");
Branch: 1 branch
BranchTrueFalseTotal
$ctx->tag eq $tag or croak($ctx->tag, " is not a $tag!") 3 0 3
358 croak("context fail $tag")
359 3 ▶ unless($self->{ctx} = $ctx->parent or $tag eq 'slide');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ctx"} = $ctx->parent or $tag eq "slide" 0 3 3
Condition33%1/3
$self->{"ctx"} = $ctx->parent or $tag eq "slide"
l!l&&r!l&&!r
030
MC/DC0%0/2
$self->{"ctx"} = $ctx->parent or $tag eq "slide"
$self->{"ctx"} = $ctx->parent $tag eq "slide"
Truth table33%1/3
A or B
A= $self->{"ctx"} = $ctx->parentB= $tag eq "slide"
ABresult
1X1
011
000
360  
361 } # put_tag_end ########################################################
362  
363 =head2 put_text
364  
365 $slidez->put_text($text);
366  
367 =cut
368  
369 39 ▶sub put_text {
Subroutine put_text: called CC=3 SCAR=11.0
Pod documented
370 39 my $self = shift;
371 39 my ($text) = @_;
372  
373 39 ▶ my $ctx = $self->{ctx} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ctx = $self->{"ctx"} or return 26 13 39
374 26 ▶ $ctx->create_child('',
Branch: 1 branch
BranchTrueFalseTotal
length $text ? : 21 5 26
375 length($text) ? $self->escape_text($text) : '');
376 # TODO escaped text might actually contain some certain tags :-/
377  
378 } # put_text ###########################################################
379  
380 =head2 _part_slide
381  
382 my @parts = $self->_part_slide($slide);
383  
384 =cut
385  
386 0 ▶sub _part_slide {
Subroutine _part_slide: not called CC=11 SCAR=48.8
387 0 my $self = shift;
388 0 my ($slide) = @_;
389  
390 0 my @children = $slide->children;
391 0 ▶ pop(@children) if($children[-1] =~ m/^\s*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $children[-1] =~ /^\s*$/ 0 0 0
392 0 my @parts = ([]);
393 0 my $sp;
394 # warn join(",", map({$_->type} @children));
395 # if($children[0]->is_text) { # undenting :-/
396 # $children[0]->{content} =~ s/^(\s+)//;
397 # $sp = $1;
398 # }
399 # warn "sp is >$sp<\n";
400 0 ▶ while(@children) {
Branch: 1 branch
BranchTrueFalseTotal
if (@children) 0 0 0
401 0 my $bit = shift(@children);
402 0 ▶ if($bit->is_text and $bit->{content} =~ s/\n$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bit->is_text and $bit->{'content'} =~ s/\n$//) { } 0 0 0
Condition0%0/3
$bit->is_text and $bit->{"content"} =~ s/\n$//
!ll&&!rl&&r
000
MC/DC0%0/2
$bit->is_text and $bit->{"content"} =~ s/\n$//
$bit->is_text $bit->{"content"} =~ s/\n$//
Truth table0%0/3
A and B
A= $bit->is_textB= $bit->{"content"} =~ s/\n$//
ABresult
0X0
100
111
403 #$bit->{content} =~ s/^$sp// if(defined($sp));
404 0 ▶ push(@{$parts[-1]}, $bit) if(length($bit));
Branch: 1 branch
BranchTrueFalseTotal
if length $bit 0 0 0
405 0 push(@parts, []); # start a new group
406 }
407 else {
408 #if($bit->is_text) { $bit->{content} =~ s/^$sp// if(defined($sp)); }
409 0 push(@{$parts[-1]}, $bit);
410 }
411 }
412  
413 0 foreach my $part (@parts) {
414 0 ▶ next unless(@$part);
Branch: 1 branch
BranchTrueFalseTotal
unless @$part 0 0 0
415 0 ▶ shift(@$part)
Branch: 1 branch
BranchTrueFalseTotal
$part->[0]->is_text and $part->[0] =~ /^\s+$/ and do { shift @$part } 0 0 0
Condition0%0/3
$part->[0]->is_text and $part->[0] =~ /^\s+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$part->[0]->is_text and $part->[0] =~ /^\s+$/
$part->[0]->is_text $part->[0] =~ /^\s+$/
Truth table0%0/3
A and B
A= $part->[0]->is_textB= $part->[0] =~ /^\s+$/
ABresult
0X0
100
111
416 while($part->[0]->is_text and $part->[0] =~ m/^\s+$/);
417 }
418  
419 # drop the trailing chunk
420 0 ▶ pop(@parts) if(@{$parts[-1]} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @{$parts[-1];} == 0 0 0 0
421  
422 0 if(0) {
423 warn "slide:\n";
424 warn join("\n---\n", map({join('|', @$_)} @parts)), "\n";
425 warn "\n\n\n";
426 }
427  
428 0 return(@parts);
429 } # _part_slide ########################################################
430  
431 =head2 _calc_width
432  
433 my $n = $self->_calc_width($text);
434  
435 =cut
436  
437 0 ▶sub _calc_width {
Subroutine _calc_width: not called CC=1 SCAR=6.9
438 0 my $self = shift;
439 0 my $text = shift;
440  
441 0 my @lines = split(/\n|<br\s*\/>/, $text);
442 0 my ($width) = sort({$b <=> $a}
443 0 map({s/<[^>]+>//g; s/&[^;]+;/./g; length($_)} @lines));
444 0 $width *= 0.625; # emperical em-width adjustment
445 } # _calc_width ########################################################
446  
447 =head2 _handle_parts
448  
449 $self->_handle_parts($ctx, \@parts, %opts);
450  
451 =cut
452  
453 0 ▶sub _handle_parts {
Subroutine _handle_parts: not called CC=20 SCAR=60.4
454 0 my $self = shift;
455 0 my ($ctx, $parts, %opts) = @_;
456  
457 0 my @parts = @$parts;
458 0 my $calc_width = $opts{calc_width};
459  
460 0 ▶ if($parts[2] and @{$parts[1]} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parts[2] and @{$parts[1];} == 0) { } 0 0 0
Condition0%0/3
$parts[2] and @{$parts[1];} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$parts[2] and @{$parts[1];} == 0
$parts[2] @{$parts[1];} == 0
Truth table0%0/3
A and B
A= $parts[2]B= @{$parts[1];} == 0
ABresult
0X0
100
111
461 0 my $title_chunk = shift(@parts);
462 0 shift(@parts); # scrap
463 0 $ctx->create_child(div => [class => 'title'], @$title_chunk);
464 0 $ctx->create_child('br');
465 }
466 else {
467 # center the whole thing vertically
468 0 $ctx = $ctx->create_child(div => [class => 'cell']);
469 }
470  
471 0 ▶ while(@parts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts) 0 0 0
472 0 my $part = shift(@parts);
473 0 ▶ next unless(@$part);
Branch: 1 branch
BranchTrueFalseTotal
unless @$part 0 0 0
474 0 ▶ if(@$part == 1 and $part->[0] =~ m/^[^<]*<hr\s*\/>[^<]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$part == 1 and $part->[0] =~ m[^[^<]*<hr\s*/>[^<]*$]) 0 0 0
Condition0%0/3
@$part == 1 and $part->[0] =~ m[^[^<]*<hr\s*/>[^<]*$]
!ll&&!rl&&r
000
MC/DC0%0/2
@$part == 1 and $part->[0] =~ m[^[^<]*<hr\s*/>[^<]*$]
@$part == 1 $part->[0] =~ m[^[^<]*<hr\s*/>[^<]*$]
Truth table0%0/3
A and B
A= @$part == 1B= $part->[0] =~ m[^[^<]*<hr\s*/>[^<]*$]
ABresult
0X0
100
111
475 0 $ctx->add_child($part->[0]);
476 0 next;
477 }
478 # pre fixup
479 0 ▶ if(@$part == 1 and $part->[0]->tag eq 'pre') {
Branch: 1 branch
BranchTrueFalseTotal
if (@$part == 1 and $part->[0]->tag eq "pre") 0 0 0
Condition0%0/3
@$part == 1 and $part->[0]->tag eq "pre"
!ll&&!rl&&r
000
MC/DC0%0/2
@$part == 1 and $part->[0]->tag eq "pre"
@$part == 1 $part->[0]->tag eq "pre"
Truth table0%0/3
A and B
A= @$part == 1B= $part->[0]->tag eq "pre"
ABresult
0X0
100
111
480 0 my ($pre) = @$part;
481 0 my $text = join('', $pre->children);
482 0 $text =~ s/^\n//;
483 0 ▶ if($text =~ s/^(\s+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ s/^(\s+)//) 0 0 0
484 0 my $sp = $1;
485 0 $text =~ s/^$sp//mg;
486 }
487 0 my %atts = $pre->atts;
488 0 ▶ my $class = $atts{class} || '';
Condition0%0/2
$atts{'class'} || ''
l!l
00
MC/DC0%0/1
$atts{'class'} || ''
$atts{'class'}
Truth table0%0/2
A
A= $atts{'class'}
Aresult
11
00
489 0 $pre->{children} = [];
490 0 $pre->create_child('' => $text);
491 0 my $width = $calc_width->($text);
492 0 my $inner = $ctx->create_child(
493 div => [class => "auto left $class",
494 style => "width: $width"]);
495 0 $inner->add_child($pre);
496 0 next;
497 }
498 # bullet points
499 0 ▶ if($part->[0] =~ m/^(\s*)\* /) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part->[0] =~ /^(\s*)\* /) 0 0 0
500 0 my $sp = $1;
501 0 my @points = $part;
502 # then go back to the well:
503 0 ▶ while(@parts and $parts[0][0] =~ m/^\s*\* /) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts and $parts[0][0] =~ /^\s*\* /) 0 0 0
Condition0%0/3
@parts and $parts[0][0] =~ /^\s*\* /
!ll&&!rl&&r
000
MC/DC0%0/2
@parts and $parts[0][0] =~ /^\s*\* /
@parts $parts[0][0] =~ /^\s*\* /
Truth table0%0/3
A and B
A= @partsB= $parts[0][0] =~ /^\s*\* /
ABresult
0X0
100
111
504 0 push(@points, shift(@parts));
505 }
506 0 foreach my $point (@points) {
507 0 ▶ $point->[0]->is_text or die;
Branch: 1 branch
BranchTrueFalseTotal
$point->[0]->is_text or die 0 0 0
508 0 $point->[0]->{content} =~ s/^$sp//;
509 }
510  
511 0 my $width = $calc_width->(join("\n", map({@$_} @points)));
512 0 my $inner = $ctx->create_child(
513 div => [class => "auto left", style => "width: $width"]);
514 0 my $top = $inner->create_child(ul =>);
515 0 my @d = ($top);
516 0 foreach my $point (@points) {
517 0 $point->[0]->{content} =~ s/(\s*)\*\s+//;
518 0 my $ws = length($1)/2;
519 # warn "ws: $ws ($point->[0]->{content})\n";
520 0 ▶ if($ws) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ws) { } 0 0 0
521 0 ▶ $d[$ws] ||= $d[$ws-1]->child(-1)->create_child(ul =>);
Condition0%0/3
$d[$ws] ||= $d[$ws - 1]->child(-1)->create_child("ul")
l!l&&r!l&&!r
000
MC/DC0%0/2
$d[$ws] ||= $d[$ws - 1]->child(-1)->create_child("ul")
$d[$ws] $d[$ws - 1]->child(-1)->create_child("ul")
Truth table0%0/3
A ||= B
A= $d[$ws]B= $d[$ws - 1]->child(-1)->create_child("ul")
ABresult
1X1
011
000
522 }
523 else {
524 0 @d = ($top);
525 }
526 0 $d[$ws]->create_child(li => @$point);
527 }
528 # warn "yay: $top\n";
529 0 next;
530 }
531 0 my $inner = $ctx->create_child(div =>);
532 0 $inner->add_child($_) for(@$part);
533 }
534  
535 } # _handle_parts ######################################################
536  
537 =head2 _mk_script
538  
539 $self->_mk_script(%opts);
540  
541 =cut
542  
543 0 ▶sub _mk_script {
Subroutine _mk_script: not called CC=9 SCAR=45.0
544 0 my $self = shift;
545 0 my (%opts) = @_;
546  
547 my $script =
548 ($opts{next} ? qq(var next="$opts{next}"\n) .
549 "var down=0; document.onmousedown=function(e) { down=1 }\n".
550 " document.onmousemove=function(e) { down=0; }\n".
551 "document.onmouseup=function(e) {\n" .
552 "if(down == 1) {window.location = next;}; }\n" : ''
553 ) .
554 ($opts{prev} ? qq(var prev="$opts{prev}"\n) : '') .
555 ($opts{first} ? qq(var first="$opts{first}"\n) : '') .
556 0 ▶ ($opts{last} ? qq(var last="$opts{last}"\n) : '');
Branch: 4 branches
BranchTrueFalseTotal
$opts{'next'} ? : 0 0 0
$opts{'prev'} ? : 0 0 0
$opts{'first'} ? : 0 0 0
$opts{'last'} ? : 0 0 0
557 0 my $func = <<' ---';
558 document.onkeypress=function(e) {
559 var e=window.event || e
560 var n=e.keyCode || e.which
561 switch (n) {
562 -SWITCH-
563 }
564 }
565 ---
566 0 ▶ my $switch = join("\n", map({$_ . ' break;'}
Branch: 4 branches
BranchTrueFalseTotal
$opts{'next'} ? : 0 0 0
$opts{'prev'} ? : 0 0 0
$opts{'first'} ? : 0 0 0
$opts{'last'} ? : 0 0 0
567 ($opts{next} ? 'case 32 : window.location = next;' : ()),
568 ($opts{prev} ? 'case 8 : window.location = prev;' : ()),
569 ($opts{first} ? 'case 36 : window.location = first;' : ()),
570 0 ($opts{last} ? 'case 35 : window.location = last;' : ()),
571 ));
572 0 $func =~ s/-SWITCH-/$switch/;
573  
574 0 return($script . $func);
575 } # _mk_script #########################################################
576  
577 =head1 AUTHOR
578  
579 Eric Wilhelm @ <ewilhelm at cpan dot org>
580  
581 http://scratchcomputing.com/
582  
583 =head1 BUGS
584  
585 If you found this module on CPAN, please report any bugs or feature
586 requests through the web interface at L<http://rt.cpan.org>. I will be
587 notified, and then you'll automatically be notified of progress on your
588 bug as I make changes.
589  
590 If you pulled this development version from my /svn/, please contact me
591 directly.
592  
593 =head1 COPYRIGHT
594  
595 Copyright (C) 2009 Eric L. Wilhelm, All Rights Reserved.
596  
597 =head1 NO WARRANTY
598  
599 Absolutely, positively NO WARRANTY, neither express or implied, is
600 offered with this software. You use this software at your own risk. In
601 case of loss, no person or entity owes you anything whatsoever. You
602 have been warned.
603  
604 =head1 LICENSE
605  
606 This program is free software; you can redistribute it and/or modify it
607 under the same terms as Perl itself.
608  
609 =cut
610  
611 # vi:ts=2:sw=2:et:sta
612 2 1;
↑ Summary