Kamelon/Format/HTML4.pm

filter: Statementstmt 15.0% 30 / 200 Branchbran 0.0% 0 / 86 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 29.1% 7 / 24 Podpod 100% 17 / 17 totaltotal 16.5% 54 / 327 CC 44 SCAR 55.6
CC
44
Cov
10%
new
657.3
Format
20.0
LoadFile
12.0
CRAP 259.3
↑ Summary Kamelon/Format/Base.pm »
1 package Syntax::Kamelon::Format::HTML4;
2  
3 1 ▶use 5.006;
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 Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 $VERSION="0.15";
10  
11 1 ▶use base qw(Syntax::Kamelon::Format::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 my $default_header = <<__EOF;
14 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
15 <html>
16 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
17 <head>
18 [% IF foldmarkers == 1 ~%]
19 [% javascript ~%]
20 [% END ~%]
21 [% IF inlinecss == 1 ~%]
22 <style>
23 [%- layoutcss ~%]
24 [%- themecss ~%]
25 </style>
26 [% ELSE ~%]
27 <link rel="stylesheet" href="[% layoutcss %]" type="text/css">
28 <link rel="stylesheet" href="[% themecss %]" type="text/css">
29 [% END ~%]
30 <title>[% title %]</title>
31 </head>
32 <body>
33 __EOF
34  
35 1 my $default_footer = <<__EOF;
36 </body>
37 </html>
38 __EOF
39  
40 1 my $default_template = <<__EOF;
41 [% header %]
42 [% panel.begin ~%]
43 [% IF lineoffset.defined ~%]
44 [% linenum = lineoffset ~%]
45 [% ELSE ~%]
46 [% linenum = 1 ~%]
47 [% END ~%]
48 [% FOREACH line = content ~%]
49 [% IF folds.exists(linenum) ~%]
50 [% node = folds.\$linenum ~%]
51 [% END ~%]
52 [% IF sections == 1 ~%]
53 [% IF folds.exists(linenum) ~%]
54 [% IF node.depth == 1 ~%]
55 [% panel.end ~%]
56 <br>
57 [% panel.begin ~%]
58 [% END ~%]
59 [% END ~%]
60 [% END ~%]
61 <div id="[% linenum %]" class="line">
62 [%~ IF foldmarkers == 1 ~%]
63 [% IF folds.exists(linenum) ~%]
64 <div id="[% linenum %]f" class="fold" onclick="block_fold('[% linenum %]', '[% node.end %]')">-</div><div id="[% linenum %]e" class="fold" onclick="block_expand('[% linenum %]', '[% node.end %]')" style="display:none;">+</div>
65 [% ELSE ~%]
66 <div class="fold">&nbsp;</div>
67 [% END ~%]
68 [% END ~%]
69 [% IF lineoffset.defined ~%]
70 <div class="number">[% linenum %]</div>
71 [%~ END ~%]
72 [%~ FOREACH snippet = line ~%]
73 <font class="[% snippet.tag %]">
74 [%~ snippet.text FILTER html FILTER replace('\\040', '&nbsp;') FILTER replace('\\t', '&nbsp;&nbsp;&nbsp;') ~%]
75 </font>
76 [%~ END %]</br></div>
77 [%~ linenum = linenum + 1 %]
78 [% END ~%]
79 [% panel.end ~%]
80 [% footer %]
81 __EOF
82  
83 1 my $default_script = <<__EOF;
84 <script type="text/javascript" language="JavaScript"><!--
85 function block_expand(b, e) {
86 var marker_e = b.concat('e');
87 var marker_f = b.concat('f');
88 document.getElementById(marker_e).style.display="none";
89 document.getElementById(marker_f).style.display="inline";
90 for (i = Number(b) + 1; i <= Number(e); ++i) {
91 document.getElementById(i).style.display="inline";
92 var im_e = i.toString().concat('e');
93 var im_f = i.toString().concat('f');
94 if (document.getElementById(im_f) !== null) {
95 document.getElementById(im_e).style.display="none";
96 document.getElementById(im_f).style.display="inline";
97 }
98 }
99 }
100 function block_fold(b, e) {
101 var marker_e = b.concat('e');
102 var marker_f = b.concat('f');
103 document.getElementById(marker_e).style.display="inline";
104 document.getElementById(marker_f).style.display="none";
105 for (i = Number(b) + 1; i <= Number(e); ++i) {
106 document.getElementById(i).style.display="none";
107 }
108 }
109 //--></script>
110 __EOF
111  
112 1 my $style_plain_begin = <<__EOF;
113 <div class="content">
114 __EOF
115  
116 1 my $style_plain_end = <<__EOF;
117 </div>
118 __EOF
119  
120 1 my $style_scrolled_begin = <<__EOF;
121 <div class="content" style="overflow:scroll; height:750px;">
122 __EOF
123  
124 1 my $style_scrolled_end = <<__EOF;
125 </div>
126 __EOF
127  
128  
129 0 ▶sub new {
Subroutine new: not called CC=26 SCAR=64.9
Pod documented
130 0 my $class = shift;
131 0 my $engine = shift;
132 0 my %args = (@_);
133  
134 #We overwrite the following options for parent Base unless the user already set an option
135 0 ▶ unless (exists $args{template}) { $args{template} = \$default_template }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"template"}) 0 0 0
136 0 ▶ unless (exists $args{tagend}) { $args{tagend} = </font> }
Subroutine BEGIN: called CC=1 SCAR=1.7
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"tagend"}) 0 0 0
137  
138 #We retrieve our own options
139 0 my $foldmarkers = delete $args{foldmarkers};
140 0 ▶ unless (defined $foldmarkers) { $foldmarkers = 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $foldmarkers) 0 0 0
141 0 ▶ if ($foldmarkers eq 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($foldmarkers eq 1) 0 0 0
142 0 ▶ unless (exists $args{foldingdepth}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"foldingdepth"}) 0 0 0
143 0 $args{foldingdepth} = 99
144 }
145 }
146  
147 0 my $footer = delete $args{footer};
148 0 ▶ unless (defined $footer) { $footer = \$default_footer }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $footer) 0 0 0
149  
150 0 my $header = delete $args{header};
151 0 ▶ unless (defined $header) { $header = \$default_header }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $header) 0 0 0
152  
153 0 my $inlinecss = delete $args{inlinecss};
154 0 ▶ unless (defined $inlinecss) { $inlinecss = 1 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $inlinecss) 0 0 0
155  
156 0 my $javascript = delete $args{javascript};
157 0 ▶ unless (defined $javascript) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $javascript) 0 0 0
158 0 $javascript = \$default_script
159 };
160  
161 #We deal with the layoutcss later on
162 0 my $layoutcss = delete $args{layoutcss};
163  
164 0 my $plainpanel = delete $args{plainpanel};
165 0 ▶ unless (defined $plainpanel) { $plainpanel = {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $plainpanel) 0 0 0
166 begin => \$style_plain_begin,
167 end => \$style_plain_end,
168 }};
169  
170 0 my $scrolled = delete $args{scrolled};
171 0 ▶ unless (defined $scrolled) { $scrolled = 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $scrolled) 0 0 0
172  
173 0 my $scrolledpanel = delete $args{scrolledpanel};
174 0 ▶ unless (defined $scrolledpanel) { $scrolledpanel = {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $scrolledpanel) 0 0 0
175 begin => \$style_scrolled_begin,
176 end => \$style_scrolled_end,
177 }};
178  
179 0 my $sections = delete $args{sections};
180 0 ▶ unless (defined $sections) { $sections = 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sections) 0 0 0
181 0 ▶ if ($sections) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sections) 0 0 0
182 0 ▶ unless (exists $args{foldingdepth}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"foldingdepth"}) 0 0 0
183 0 $args{foldingdepth} = 1
184 }
185 }
186  
187 #We deal with the themecss later on
188 0 my $themecss = delete $args{themecss};
189  
190  
191 0 my $themefolder = delete $args{themefolder};
192 0 ▶ unless (defined $themefolder) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $themefolder) 0 0 0
193 0 $themefolder = $engine->GetIndexer->FindINC('Syntax/Kamelon/Format/HTML4')
194 }
195 0 ▶ unless (defined $themefolder) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $themefolder) 0 0 0
196 0 die "theme folder not found"
197 }
198 0 ▶ unless (-e $themefolder) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $themefolder) 0 0 0
199 0 die "theme folder does not exist"
200 }
201 0 ▶ unless (-d $themefolder) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $themefolder) 0 0 0
202 0 die "theme folder is not a folder"
203 }
204  
205  
206 0 ▶ unless (defined $layoutcss) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $layoutcss) 0 0 0
207 0 $layoutcss = "$themefolder/layout.css";
208 }
209 0 ▶ unless (-e $layoutcss) { die "layout stylesheet not found" }
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $layoutcss) 0 0 0
210  
211 0 my $theme = delete $args{theme};
212 0 ▶ unless (defined $theme) { $theme = 'DarkGray' }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $theme) 0 0 0
213  
214 0 ▶ unless (defined $themecss) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $themecss) 0 0 0
215 0 $themecss = "$themefolder/$theme.css";
216 }
217 0 ▶ unless (-e $themecss) { die "theme stylesheet not found" }
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $themecss) 0 0 0
218  
219 0 my $title = delete $args{title};
220 0 ▶ unless (defined $title) { $title = 'Kamelon output' }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $title) 0 0 0
221  
222 0 my $self = $class->SUPER::new($engine, %args);
223  
224 0 $self->{FOLDMARKERS} = $foldmarkers;
225 0 $self->{FOOTER} = $footer;
226 0 $self->{HEADER} = $header;
227 0 $self->{INLINECSS} = $inlinecss;
228 0 $self->{JAVASCRIPT} = $javascript;
229 0 $self->{LAYOUTCSS} = $layoutcss;
230 0 $self->{PLAINPANEL} = $plainpanel;
231 0 $self->{SCROLLED} = $scrolled;
232 0 $self->{SCROLLEDPANEL} = $scrolledpanel;
233 0 $self->{SECTIONS} = $sections;
234 0 $self->{THEMECSS} = $themecss;
235 0 $self->{THEMEFOLDER} = $themefolder;
236 0 $self->{TITLE} = $title;
237 0 return $self;
238 }
239  
240 0 ▶sub FoldMarkers {
Subroutine FoldMarkers: not called CC=2 SCAR=17.9
Pod documented
241 0 my $self = shift;
242 0 ▶ if (@_) { $self->{FOLDMARKERS} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
243 return $self->{FOLDMARKERS}
244 0 }
245  
246 0 ▶sub Format {
Subroutine Format: not called CC=4 SCAR=30.0
Pod documented
247 0 my $self = shift;
248  
249 #processing the header
250 0 my $themecss;
251 my $layoutcss;
252 0 my $javascript;
253 0 my $d = $self->{DATA};
254 0 ▶ if ($self->{FOLDMARKERS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"FOLDMARKERS"}) 0 0 0
255 0 $javascript = $self->Process($self->{JAVASCRIPT}, $d);
256 }
257 0 ▶ if ($self->{INLINECSS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'INLINECSS'}) { } 0 0 0
258 0 $themecss = $self->LoadFile($self->{THEMECSS});
259 0 $layoutcss = $self->LoadFile($self->{LAYOUTCSS});
260 } else {
261 0 $themecss = $self->{THEMECSS};
262 0 $layoutcss = $self->{LAYOUTCSS};
263 }
264 my %data = (%$d,
265 foldmarkers => $self->{FOLDMARKERS},
266 javascript=> $javascript,
267 inlinecss => $self->{INLINECSS},
268 layoutcss => $layoutcss,
269 themecss => $themecss,
270 title => $self->{TITLE},
271 0 );
272 0 $self->{HEADERTEXT} = $self->Process($self->{HEADER}, \%data,);
273  
274 #process the footer
275 0 $self->{FOOTERTEXT} = $self->Process($self->{FOOTER}, $d);
276  
277 #processing the style elements
278 0 my $panel_begin = '';
279 0 my $panel_end = '';
280 0 ▶ if ($self->{SCROLLED}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'SCROLLED'}) { } 0 0 0
281 0 $panel_begin = $self->Process($self->{SCROLLEDPANEL}->{begin}, $self->{DATA});
282 0 $panel_end = $self->Process($self->{SCROLLEDPANEL}->{end}, $self->{DATA});
283 } else {
284 0 $panel_begin = $self->Process($self->{PLAINPANEL}->{begin}, $self->{DATA});
285 0 $panel_end = $self->Process($self->{PLAINPANEL}->{end}, $self->{DATA});
286 }
287 $self->{PANELTEXT} = {
288 0 begin => $panel_begin,
289 end => $panel_end,
290 };
291  
292 #format the whole bunch with the parsed text
293 0 return $self->SUPER::Format;
294 }
295  
296 0 ▶sub Footer {
Subroutine Footer: not called CC=2 SCAR=17.9
Pod documented
297 0 my $self = shift;
298 0 ▶ if (@_) { $self->{FOOTER} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
299 return $self->{FOOTER}
300 0 }
301  
302 0 ▶sub GetData {
Subroutine GetData: not called CC=1 SCAR=6.9
Pod documented
303 0 my $self = shift;
304 0 my $data = $self->SUPER::GetData;
305 0 $data->{foldmarkers} = $self->{FOLDMARKERS};
306 0 $data->{header} = $self->{HEADERTEXT};
307 0 $data->{footer} = $self->{FOOTERTEXT};
308 0 $data->{panel} = $self->{PANELTEXT};
309 0 $data->{sections} = $self->{SECTIONS};
310 0 return $data
311 }
312  
313 0 ▶sub Header {
Subroutine Header: not called CC=2 SCAR=17.9
Pod documented
314 0 my $self = shift;
315 0 ▶ if (@_) { $self->{HEADER} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
316 return $self->{HEADER}
317 0 }
318  
319 0 ▶sub InlineCSS {
Subroutine InlineCSS: not called CC=2 SCAR=17.9
Pod documented
320 0 my $self = shift;
321 0 ▶ if (@_) { $self->{INLINECSS} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
322 return $self->{INLINECSS}
323 0 }
324  
325 0 ▶sub Javascript {
Subroutine Javascript: not called CC=2 SCAR=17.9
Pod documented
326 0 my $self = shift;
327 0 ▶ if (@_) { $self->{JAVASCRIPT} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
328 return $self->{JAVASCRIPT}
329 0 }
330  
331 0 ▶sub LayoutCSS {
Subroutine LayoutCSS: not called CC=2 SCAR=17.9
Pod documented
332 0 my $self = shift;
333 0 ▶ if (@_) { $self->{LAYOUTCSS} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
334 return $self->{LAYOUTCSS}
335 0 }
336  
337 0 ▶sub LoadFile {
Subroutine LoadFile: not called CC=3 SCAR=24.8
Pod documented
338 0 my ($self, $file) = @_;
339 0 ▶ open IN, "<$file" or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open IN, "<$file" or return undef 0 0 0
340 0 my $out = '';
341 0 ▶ while (my $line = <IN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline IN)) 0 0 0
342 0 $out = $out . $line;
343 }
344 0 close IN;
345 0 return $out
346 }
347  
348 0 ▶sub PlainPanel {
Subroutine PlainPanel: not called CC=2 SCAR=17.9
Pod documented
349 0 my $self = shift;
350 0 ▶ if (@_) { $self->{PLAINPANEL} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
351 return $self->{PLAINPANEL}
352 0 }
353  
354 0 ▶sub Scrolled {
Subroutine Scrolled: not called CC=2 SCAR=17.9
Pod documented
355 0 my $self = shift;
356 0 ▶ if (@_) { $self->{SCROLLED} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
357 return $self->{SCROLLED}
358 0 }
359  
360 0 ▶sub ScrolledPanel {
Subroutine ScrolledPanel: not called CC=2 SCAR=17.9
Pod documented
361 0 my $self = shift;
362 0 ▶ if (@_) { $self->{SCROLLEDPANEL} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
363 return $self->{SCROLLEDPANEL}
364 0 }
365  
366 0 ▶sub Sections {
Subroutine Sections: not called CC=2 SCAR=17.9
Pod documented
367 0 my $self = shift;
368 0 ▶ if (@_) { $self->{SECTIONS} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
369 return $self->{SECTIONS}
370 0 }
371  
372 0 ▶sub ThemeCSS {
Subroutine ThemeCSS: not called CC=2 SCAR=17.9
Pod documented
373 0 my $self = shift;
374 0 ▶ if (@_) { $self->{THEMECSS} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
375 return $self->{THEMECSS}
376 0 }
377  
378 0 ▶sub ThemeFolder {
Subroutine ThemeFolder: not called CC=2 SCAR=17.9
Pod documented
379 0 my $self = shift;
380 0 ▶ if (@_) { $self->{THEMEFOLDER} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
381 return $self->{THEMEFOLDER}
382 0 }
383  
384 0 ▶sub Title {
Subroutine Title: not called CC=2 SCAR=17.9
Pod documented
385 0 my $self = shift;
386 0 ▶ if (@_) { $self->{TITLE} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
387 return $self->{TITLE}
388 0 }
389  
390 1 1;
391 __END__
↑ Summary Kamelon/Format/Base.pm »