blib/lib/LibWeb/HTML/Default.pm

filter: Statementstmt 94.3% 50 / 53 Branchbran 50.0% 3 / 6 Conditioncond 34.7% 8 / 23 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 8 totaltotal 61.0% 72 / 118 CC 13 SCAR 15.1
CC
13
Cov
74%
display
9.2
_parse_construct
5.6
new
3.2
CRAP 4.5
« blib/lib/LibWeb/Time.pm ↑ Summary blib/lib/LibWeb/Crypt.pm »
1 #=============================================================================
2 # LibWeb::HTML::Default -- `stdout' HTML display for libweb applications.
3  
4 package LibWeb::HTML::Default;
5  
6 # Copyright (C) 2000 Colin Kong
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #=============================================================================
22  
23 # $Id: Default.pm,v 1.6 2000/07/19 20:31:57 ckyc Exp $
24  
25 1 $VERSION = '0.02';
26  
27 #-################################
28 # Use standard libraries.
29 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 #-################################
34 # Use custom libraries.
35 1 require LibWeb::HTML::Standard;
36 1 require LibWeb::HTML::Error;
37 1 require LibWeb::Themes::Default;
38  
39 #-################################
40 # Inheritance.
41 # Order of ISA is important here!
42 1 @ISA = qw( LibWeb::HTML::Standard LibWeb::Themes::Default LibWeb::HTML::Error );
43  
44 #-################################
45 # Methods.
46 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.8
Pod undocumented
47 #
48 # Params: _class_, _rc_file_ [, _error_obj_]
49 #
50 # - _class_ is the class/package name of this package, be it a string
51 # or a reference.
52 # - _rc_file_ is the absolute path to the rc file for LibWeb.
53 #
54 # Usage: my $html = new LibWeb::HTML::Default( _rc_file_ );
55 #
56 # PLEASE do not edit anything in this ``new'' method unless you know
57 # what you are doing.
58 #
59 1 my ($class, $Class, $self);
60 1 $class = shift;
61 1 ▶ $Class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
62 1 ▶ $self = $Class->SUPER::new( shift, shift || bless( {}, $Class ) );
Condition50%1/2
shift() || bless({}, $Class)
l!l
01
MC/DC0%0/1
shift() || bless({}, $Class)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
63 1 bless( $self, $Class );
64 }
65  
66 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
67  
68 6 ▶sub _parse_construct {
Subroutine _parse_construct: called CC=5 SCAR=17.3
69 6 my ($ref, @construct_display);
70 6 my $construct = $_[0];
71
72 6 eval {
73 6 foreach (@$construct) {
74 6 $ref = ref($_);
75 0 ▶ if ( $ref eq 'SCALAR' ) { push(@construct_display, $$_); }
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'SCALAR') { } 0 6 6
elsif ($ref eq 'ARRAY') { } 0 6 6
76 0 elsif ( $ref eq 'ARRAY' ) { push(@construct_display, @$_); }
77 6 else { push(@construct_display, $_); }
78 }
79 };
80 6 ▶ croak "$@" if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 6 6
81  
82 6 return \@construct_display;
83 }
84  
85 #==================================================================================
86 # ISA this class (LibWeb::HTML::Default) and override the following method to
87 # customize normal display. To customize error message display, ISA this class
88 # (LibWeb::HTML::Default) and override LibWeb::Error::display_error().
89 #
90 1 ▶sub display {
Subroutine display: called CC=7 SCAR=22.1
Pod undocumented
91 #
92 # Implementing base class method: LibWeb::HTML::Standard::display().
93 # Params: -content=>, [ -sheader=>, -lpanel=>, -rpanel=>, -header=>, -footer=> ].
94 #
95 # -content, -sheader, -lpanel, -rpanel, -header and -footer must be an ARRAY
96 # ref. to elements which are scalar/SCALAR ref/ARRAY ref.
97 # If the the elements are ARRAY ref., then the elements in that ARRAY ref. must
98 # be scalar and NOT ref.
99 #
100 # -content default is lines read from $self->content().
101 # -sheader default is lines read from $self->sheader().
102 # -lpanel default is lines read from $self->lpanel().
103 # -rpanel default is lines read from $self->rpanel().
104 # -header default is lines read from $self->header().
105 # -footer default is lines read from $self->footer().
106 #
107 # Return a scalar ref. to a formatted page in HTML format for display
108 # to Web client.
109 #
110 1 my ($self, $content, $sheader, $lpanel, $rpanel, $header, $footer,
111 $content_display, $sheader_display, $lpanel_display, $rpanel_display,
112 $header_display, $footer_display);
113 1 $self = shift;
114 1 ($content, $sheader, $lpanel, $rpanel, $header, $footer) =
115 $self->rearrange(['CONTENT', 'SHEADER', 'LPANEL', 'RPANEL', 'HEADER',
116 'FOOTER'], @_);
117  
118 1 ▶ $content ||= $self->content();
Condition33%1/3
$content ||= $self->content
l!l&&r!l&&!r
100
MC/DC0%0/2
$content ||= $self->content
$content $self->content
Truth table33%1/3
A ||= B
A= $contentB= $self->content
ABresult
1X1
011
000
119 1 ▶ $sheader ||= $self->sheader();
Condition33%1/3
$sheader ||= $self->sheader
l!l&&r!l&&!r
010
MC/DC0%0/2
$sheader ||= $self->sheader
$sheader $self->sheader
Truth table33%1/3
A ||= B
A= $sheaderB= $self->sheader
ABresult
1X1
011
000
120 1 ▶ $lpanel ||= $self->lpanel();
Condition33%1/3
$lpanel ||= $self->lpanel
l!l&&r!l&&!r
010
MC/DC0%0/2
$lpanel ||= $self->lpanel
$lpanel $self->lpanel
Truth table33%1/3
A ||= B
A= $lpanelB= $self->lpanel
ABresult
1X1
011
000
121 1 ▶ $rpanel ||= $self->rpanel();
Condition33%1/3
$rpanel ||= $self->rpanel
l!l&&r!l&&!r
010
MC/DC0%0/2
$rpanel ||= $self->rpanel
$rpanel $self->rpanel
Truth table33%1/3
A ||= B
A= $rpanelB= $self->rpanel
ABresult
1X1
011
000
122 1 ▶ $header ||= $self->header();
Condition33%1/3
$header ||= $self->header
l!l&&r!l&&!r
010
MC/DC0%0/2
$header ||= $self->header
$header $self->header
Truth table33%1/3
A ||= B
A= $headerB= $self->header
ABresult
1X1
011
000
123 1 ▶ $footer ||= $self->footer();
Condition33%1/3
$footer ||= $self->footer
l!l&&r!l&&!r
010
MC/DC0%0/2
$footer ||= $self->footer
$footer $self->footer
Truth table33%1/3
A ||= B
A= $footerB= $self->footer
ABresult
1X1
011
000
124  
125 1 $content_display = _parse_construct($content);
126 1 $sheader_display = _parse_construct($sheader);
127 1 $lpanel_display = _parse_construct($lpanel);
128 1 $rpanel_display = _parse_construct($rpanel);
129 1 $header_display = _parse_construct($header);
130 1 $footer_display = _parse_construct($footer);
131  
132 #<!-- Begin template -->
133 1 return \<<HTML;
134 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
135 <html><head><meta name="description" content="$self->{SITE_DESCRIPTION}">
136 <meta name="keywords" content="$self->{SITE_KEYWORDS}">
137 <title>$self->{SITE_NAME}</title><link rel="stylesheet" href="$self->{CSS}"></head>
138 <body bgcolor="$self->{SITE_BG_COLOR}" text="$self->{SITE_TXT_COLOR}">
139 @$header_display
140 @$sheader_display
141 <table width="100%" cellspacing="10" cellpadding="0" border="0" bgcolor="$self->{SITE_BG_COLOR}">
142 <Tr>
143  
144 <!-- Left panel -->
145 <td width="20%" valign="top">
146 @$lpanel_display</td><!-- end left panel -->
147  
148 <!-- Content -->
149 <td width="60%" valign="top">
150 @$content_display</td><!-- end content -->
151  
152 <!-- Right panel -->
153 <td width="20%" valign="top">
154 @$rpanel_display</td><!-- end right panel -->
155  
156 </Tr>
157 </table>
158  
159 @$footer_display</body></html>
160  
161 HTML
162 #<!-- End template -->
163 }
164  
165 #=================================================================================
166 # Begin implementation for site's default header, sub header, left panel,
167 # right panel, content, footer and possibly other HTML constructs.
168 1 ▶sub header {
Subroutine header: called CC=1 SCAR=0.0
Pod undocumented
169 1 return [' '];
170 }
171  
172 1 ▶sub sheader {
Subroutine sheader: called CC=1 SCAR=0.0
Pod undocumented
173 1 return [' '];
174 }
175  
176 1 ▶sub lpanel {
Subroutine lpanel: called CC=1 SCAR=0.0
Pod undocumented
177 1 return [' '];
178 }
179  
180 0 ▶sub content {
Subroutine content: not called CC=1 SCAR=6.9
Pod undocumented
181 0 return [' '];
182 }
183  
184 1 ▶sub rpanel {
Subroutine rpanel: called CC=1 SCAR=0.0
Pod undocumented
185 1 return [' '];
186 }
187  
188 1 ▶sub footer {
Subroutine footer: called CC=1 SCAR=0.0
Pod undocumented
189 1 return [' '];
190 }
191  
192 1 1;
193 __DATA__
« blib/lib/LibWeb/Time.pm ↑ Summary blib/lib/LibWeb/Crypt.pm »