MxScreen/Layout.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 44 CC 1 SCAR 6.9
CC
1
Cov
0%
make
2.0
start_HTML
2.0
end_HTML
2.0
CRAP 2.0
1 # -*- Mode: perl -*-
2 #
3 # $Id: Layout.pm,v 0.1 2001/04/22 17:57:03 ram Exp $
4 #
5 # Copyright (c) 1998-2001, Raphael Manfredi
6 # Copyright (c) 2000-2001, Christophe Dehaudt
7 #
8 # You may redistribute only under the terms of the Artistic License,
9 # as specified in the README file that comes with the distribution.
10 #
11 # HISTORY
12 # $Log: Layout.pm,v $
13 # Revision 0.1 2001/04/22 17:57:03 ram
14 # Baseline for first Alpha release.
15 #
16 # $EndLog$
17 #
18  
19 use strict;
20  
21 package CGI::MxScreen::Layout;
22  
23 use Carp::Datum;
24 require CGI;
25  
26 #
27 # ->make
28 #
29 # Creation routine.
30 #
31 sub make {
32 DFEATURE my $f_;
33 my $self = bless {}, shift;
34 return DVAL $self;
35 }
36  
37 #
38 # ->start_HTML
39 #
40 # Emit the HTML headers.
41 #
42 # NB: Can't call it "start_html", because if one uses CGI within heirs, that
43 # routine would no longer be visible (CGI exports a start_html routine).
44 #
45 sub start_HTML {
46 DFEATURE my $f_;
47 my $self = shift;
48  
49 print CGI::header(-nph => 0);
50 print CGI::start_html(@_);
51  
52 return DVOID;
53 }
54  
55 #
56 # ->end_HTML
57 #
58 # Emit the HTML trailers.
59 #
60 # NB: Can't call it "end_html", because if one uses CGI within heirs, that
61 # routine would no longer be visible (CGI exports an end_html routine).
62 #
63 sub end_HTML {
64 DFEATURE my $f_;
65 my $self = shift;
66  
67 print CGI::end_html;
68  
69 return DVOID;
70 }
71  
72 #
73 # ->init
74 #
75 # Initialize yourself.
76 # Routine called before start_HTML() with the screen to display.
77 # In case of internal errors, screen may be undef.
78 #
79 # When bouncing from screen to screen, this routine may be called more than
80 # once, for each screen we bounce to. In particular, the $screen variable
81 # may or may not be different each time.
82 #
83 sub init {
84 DFEATURE my $f_;
85 my $self = shift;
86 my ($screen) = @_;
87 ### to be redefined, optionally
88 return DVOID;
89 }
90  
91 #
92 # ->preamble
93 #
94 # Emit layout preamble, before screen generates any output.
95 #
96 sub preamble {
97 DFEATURE my $f_;
98 ### to be redefined, optionally
99 return DVOID;
100 }
101  
102 #
103 # ->postamble
104 #
105 # Emit layout postamble, after screen has generated its output.
106 #
107 sub postamble {
108 DFEATURE my $f_;
109 ### to be redefined, optionally
110 return DVOID;
111 }
112  
113 1;
114  
115 =head1 NAME
116  
117 CGI::MxScreen::Layout - ancestor for layout objects
118  
119 =head1 SYNOPSIS
120  
121 use base qw(CGI::MxScreen::Layout);
122  
123 sub init { # redefine initialization
124 my $self = shift;
125 my ($screen) = @_;
126 ...
127 }
128  
129 sub preamble { # redefine pre-amble
130 my $self = shift;
131 ...
132 }
133  
134 sub postamble { # redefine post-amble
135 my $self = shift;
136 ...
137 }
138  
139 =head1 DESCRIPTION
140  
141 This class is meant to be the ancestor of all the layout objects
142 that can be given to the C<CGI::MxScreen> manager via the C<-layout>
143 argument.
144  
145 In order to define your own layout, you must create a class inheriting
146 from C<CGI::MxScreen::Layout> and redefine the C<init()>, C<preamble()>
147 and C<postamble()> features, which do nothing by default.
148  
149 Because this kind in inheritance is a I<specialization> of some behaviour,
150 you need to understand the various operations that get carried on, so
151 that you may plug your layout properly.
152  
153 It works as follows:
154  
155 =over 4
156  
157 =item *
158  
159 The C<init()> routine is called for each screen we are about to display.
160 It is given one argument, the screen object. That object may be C<undef>
161 if we're displaying an internal error. See L<CGI::MxScreen::Screen/INTERFACE>
162 to know what can be done with a screen object.
163  
164 The C<display()> routine of a screen may request bouncing to some other
165 state, in which case C<init()> will be called again with another screen
166 object. Therefore, you must not assume that C<init()> will be called
167 only once.
168  
169 =item *
170  
171 The C<start_HTML()> routine is called with the following arguments:
172  
173 -title => $screen->screen_title,
174 -bgcolor => $screen->bgcolor,
175  
176 when there is a screen object, or with simply a title for internal errors.
177 The default C<start_HTML()> routine does this:
178  
179 print CGI::header(-nph => 0);
180 print CGI::start_html(@_);
181  
182 but you may choose to optionally redefine it.
183  
184 =item *
185  
186 Immediately after, C<preamble()> is called. It does nothing by default,
187 but this is a feature you're likely to redefine.
188  
189 Since it is an object feature, it has access to everything you decided to
190 initialize in C<init()>, based on the screen or other internal variables.
191  
192 If your C<preamble()> routine opens an HTML container tag, you must make
193 sure it is able to contain everything that can be generated during
194 C<display()>.
195  
196 =item *
197  
198 Unless we're generating an internal error, the CGI form is started.
199 Then C<$screen-E<gt>display(...)> is called. This is where the regular
200 output is generated.
201  
202 =item *
203  
204 Upon return from C<display()>, the CGI form is closed, then C<postamble()
205 is called.
206  
207 This is the opportunity to close any tag opened in C<preamble()>, or to
208 emit a common trailer to all your script outputs.
209  
210 =item *
211  
212 Finally, the C<end_HTML()> routine is called. It does
213  
214 print CGI::end_html;
215  
216 in case you would like to redefine that. Don't make the mistake to
217 redefine C<end_HTML()> simply to add a postamble before closing the HTML tags.
218 You must use C<postamble()> for that.
219  
220 You could conceivably need to redefine C<end_HTML()> when you redefined
221 C<start_HTML()>, but then again, it's a possibility, not a certitude.
222  
223 =back
224  
225 =head1 AUTHOR
226  
227 Raphael Manfredi F<E<lt>Raphael_Manfredi@pobox.comE<gt>>
228  
229 =head1 SEE ALSO
230  
231 CGI::MxScreen(3), CGI::MxScreen::Screen(3).
232  
233 =cut
234