blib/lib/ASP4/MasterPage.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 9 | 9 | 100.0 |
branch | n/a | ||
condition | n/a | ||
subroutine | 3 | 3 | 100.0 |
pod | n/a | ||
total | 12 | 12 | 100.0 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | |||||||
2 | package ASP4::MasterPage; | ||||||
3 | |||||||
4 | 9 | 9 | 44 | use strict; | |||
9 | 15 | ||||||
9 | 254 | ||||||
5 | 9 | 9 | 32 | use warnings 'all'; | |||
9 | 15 | ||||||
9 | 304 | ||||||
6 | 9 | 9 | 36 | use base 'ASP4::Page'; | |||
9 | 14 | ||||||
9 | 836 | ||||||
7 | |||||||
8 | 1;# return true: | ||||||
9 | |||||||
10 | =pod | ||||||
11 | |||||||
12 | =head1 NAME | ||||||
13 | |||||||
14 | ASP4::MasterPage - Root class for MasterPage classes. | ||||||
15 | |||||||
16 | =head1 SYNOPSIS | ||||||
17 | |||||||
18 | In your ASP script (C): | ||||||
19 | |||||||
20 | <%@ MasterPage %> | ||||||
21 | |||||||
22 | |||||||
23 | |
||||||
24 |
|
||||||
25 | |
||||||
26 | |||||||
27 | |||||||
28 | |||||||
29 | |||||||
30 | It gets compiled down to: | ||||||
31 | |||||||
32 | package MyApp::_eg_master_asp; | ||||||
33 | |||||||
34 | use strict; | ||||||
35 | use warnings 'all'; | ||||||
36 | no warnings 'redefine'; | ||||||
37 | use base 'ASP4::MasterPage'; | ||||||
38 | use vars __PACKAGE__->VARS; | ||||||
39 | use ASP4::PageLoader; | ||||||
40 | |||||||
41 | sub _init { | ||||||
42 | my ($s) = @_; | ||||||
43 | $s->{script_name} = q; | ||||||
44 | $s->{filename} = q; | ||||||
45 | $s->{base_class} = q |
||||||
46 | $s->{compiled_as} = q |
||||||
47 | $s->{package} = q |
||||||
48 | |||||||
49 | return; | ||||||
50 | } | ||||||
51 | |||||||
52 | sub run { | ||||||
53 | use warnings 'all'; | ||||||
54 | my ($__self, $__context) = @_; | ||||||
55 | #line 1 | ||||||
56 | ;$Response->Write(q~ | ||||||
57 | |||||||
58 | |||||||
59 | ~); $__self->heading($__context); $Response->Write(q~ |
||||||
60 |
|
||||||
61 | ~); $__self->content($__context); $Response->Write(q~ | ||||||
62 | |||||||
63 | |||||||
64 | |||||||
65 | ~); | ||||||
66 | } | ||||||
67 | |||||||
68 | sub heading { | ||||||
69 | my ($__self, $__context) = @_; | ||||||
70 | #line 4 | ||||||
71 | $Response->Write(q~Default Heading~); | ||||||
72 | }# end heading | ||||||
73 | |||||||
74 | sub content { | ||||||
75 | my ($__self, $__context) = @_; | ||||||
76 | #line 6 | ||||||
77 | $Response->Write(q~Default Content~); | ||||||
78 | }# end content | ||||||
79 | |||||||
80 | 1;# return true: | ||||||
81 | |||||||
82 | Which, when executed, produces: | ||||||
83 | |||||||
84 | |||||||
85 | |||||||
86 | Default Heading |
||||||
87 |
|
||||||
88 | Default Content | ||||||
89 | |||||||
90 | |||||||
91 | |||||||
92 | |||||||
93 | =head2 But Wait - There's More! | ||||||
94 | |||||||
95 | MasterPages only get interesting when we add "child" pages to them: | ||||||
96 | |||||||
97 | (C) | ||||||
98 | |||||||
99 | <%@ Page UseMasterPage="/eg-master.asp" %> | ||||||
100 | |||||||
101 | |
||||||
102 | |||||||
103 | |
||||||
104 | |||||||
105 | Which compiles down to: | ||||||
106 | |||||||
107 | package MyApp::_eg_child_asp; | ||||||
108 | |||||||
109 | use strict; | ||||||
110 | use warnings 'all'; | ||||||
111 | no warnings 'redefine'; | ||||||
112 | use base 'MyApp::_eg_master_asp'; | ||||||
113 | use vars __PACKAGE__->VARS; | ||||||
114 | use ASP4::PageLoader; | ||||||
115 | |||||||
116 | sub _init { | ||||||
117 | my ($s) = @_; | ||||||
118 | $s->{script_name} = q; | ||||||
119 | $s->{filename} = q; | ||||||
120 | $s->{base_class} = q |
||||||
121 | $s->{compiled_as} = q |
||||||
122 | $s->{package} = q |
||||||
123 | $s->{masterpage} = ASP4::PageLoader->load( script_name => q ); | ||||||
124 | return; | ||||||
125 | } | ||||||
126 | |||||||
127 | sub heading { | ||||||
128 | my ($__self, $__context) = @_; | ||||||
129 | #line 3 | ||||||
130 | $Response->Write(q~New Heading~); | ||||||
131 | }# end heading | ||||||
132 | |||||||
133 | sub content { | ||||||
134 | my ($__self, $__context) = @_; | ||||||
135 | #line 5 | ||||||
136 | $Response->Write(q~New Content~); | ||||||
137 | }# end content | ||||||
138 | |||||||
139 | 1;# return true: | ||||||
140 | |||||||
141 | And when executed produces: | ||||||
142 | |||||||
143 | |||||||
144 | |||||||
145 | New Heading |
||||||
146 |
|
||||||
147 | New Content | ||||||
148 | |||||||
149 | |||||||
150 | |||||||
151 | |||||||
152 | =head2 And Even More! | ||||||
153 | |||||||
154 | Child pages can also be master pages: | ||||||
155 | |||||||
156 | (C): | ||||||
157 | |||||||
158 | <%@ MasterPage %> | ||||||
159 | <%@ Page UseMasterPage="/eg-master.asp" %> | ||||||
160 | |||||||
161 | |
||||||
162 | |||||||
163 | |
||||||
164 | New Content | ||||||
165 | |||||||
166 | Copyright | ||||||
167 | |
||||||
168 | All Rights Reserved | ||||||
169 | |||||||
170 | |||||||
171 | |||||||
172 | And inherited from again: | ||||||
173 | |||||||
174 | (C): | ||||||
175 | |||||||
176 | <%@ Page UseMasterPage="/eg-master.asp" %> | ||||||
177 | |||||||
178 | |
||||||
179 | |||||||
180 | Which - when executed, produces: | ||||||
181 | |||||||
182 | |||||||
183 | |||||||
184 | New Heading |
||||||
185 |
|
||||||
186 | |||||||
187 | New Content | ||||||
188 | |||||||
189 | Copyright | ||||||
190 | SuperMegaCorp, Inc.: | ||||||
191 | All Rights Reserved | ||||||
192 | |||||||
193 | |||||||
194 | |||||||
195 | |||||||
196 | |||||||
197 | |||||||
198 | =head1 DESCRIPTION | ||||||
199 | |||||||
200 | MasterPages provide a means of rich page composition. This means that instead | ||||||
201 | of a tangle of server-side includes, you can actually take advantage of this | ||||||
202 | new concept (came out decades ago) called "class inheritance" - and apply it | ||||||
203 | to your web pages. | ||||||
204 | |||||||
205 | =cut | ||||||
206 |