blib/lib/ASP4/MasterPage.pm

filter: Statementstmt 100% 10 / 10 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 13 / 13 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/ASP4/FormHandler.pm ↑ Summary blib/lib/ASP4/RequestFilter.pm »
1  
2 package ASP4::MasterPage;
3  
4 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use base 'ASP4::Page';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 15 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</eg-master.asp>):
19  
20 <%@ MasterPage %>
21 <html>
22 <body>
23 <h1><asp:ContentPlaceHolder id="heading">Default Heading</asp:ContentPlaceHolder></h1>
24 <p>
25 <asp:ContentPlaceHolder id="content">Default Content</asp:ContentPlaceHolder>
26 </p>
27 </body>
28 </html>
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</eg-master.asp>;
44 $s->{filename} = q</home/john/Projects/www.example.com/htdocs/eg-master.asp>;
45 $s->{base_class} = q<ASP4::MasterPage>;
46 $s->{compiled_as} = q<MyApp/_eg_master_asp.pm>;
47 $s->{package} = q<MyApp::_eg_master_asp>;
48  
49 return;
50 }
51  
52 sub run {
53 use warnings 'all';
54 my ($__self, $__context) = @_;
55 #line 1
56 ;$Response->Write(q~
57 <html>
58 <body>
59 <h1>~); $__self->heading($__context); $Response->Write(q~</h1>
60 <p>
61 ~); $__self->content($__context); $Response->Write(q~
62 </p>
63 </body>
64 </html>
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 <html>
85 <body>
86 <h1>Default Heading</h1>
87 <p>
88 Default Content
89 </p>
90 </body>
91 </html>
92  
93 =head2 But Wait - There's More!
94  
95 MasterPages only get interesting when we add "child" pages to them:
96  
97 (C</eg-child.asp>)
98  
99 <%@ Page UseMasterPage="/eg-master.asp" %>
100  
101 <asp:Content PlaceHolderID="heading">New Heading</asp:Content>
102  
103 <asp:Content PlaceHolderID="content">New Content</asp:Content>
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</eg-child.asp>;
119 $s->{filename} = q</home/john/Projects/www.example.com/htdocs/eg-child.asp>;
120 $s->{base_class} = q<MyApp::_eg_master_asp>;
121 $s->{compiled_as} = q<MyApp/_eg_child_asp.pm>;
122 $s->{package} = q<MyApp::_eg_child_asp>;
123 $s->{masterpage} = ASP4::PageLoader->load( script_name => q</eg-master.asp> );
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 <html>
144 <body>
145 <h1>New Heading</h1>
146 <p>
147 New Content
148 </p>
149 </body>
150 </html>
151  
152 =head2 And Even More!
153  
154 Child pages can also be master pages:
155  
156 (C</eg-subpage.asp>):
157  
158 <%@ MasterPage %>
159 <%@ Page UseMasterPage="/eg-master.asp" %>
160  
161 <asp:Content PlaceHolderID="heading">New Heading</asp:Content>
162  
163 <asp:Content PlaceHolderID="content">
164 New Content
165 <span id="copyright">
166 Copyright
167 <asp:ContentPlaceHolder id="copyright"></asp:ContentPlaceHolder>:
168 All Rights Reserved
169 </span>
170 </asp:Content>
171  
172 And inherited from again:
173  
174 (C</eg-subchild.asp>):
175  
176 <%@ Page UseMasterPage="/eg-master.asp" %>
177  
178 <asp:Content PlaceHolderID="copyright">SuperMegaCorp, Inc.</asp:Content>
179  
180 Which - when executed, produces:
181  
182 <html>
183 <body>
184 <h1>New Heading</h1>
185 <p>
186
187 New Content
188 <span id="copyright">
189 Copyright
190 SuperMegaCorp, Inc.:
191 All Rights Reserved
192 </span>
193  
194 </p>
195 </body>
196 </html>
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 =head1 BUGS
206  
207 It's possible that some bugs have found their way into this release.
208  
209 Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ASP4> to submit bug reports.
210  
211 =head1 HOMEPAGE
212  
213 Please visit the ASP4 homepage at L<http://0x31337.org/code/> to see examples
214 of ASP4 in action.
215  
216 =cut
217  
« blib/lib/ASP4/FormHandler.pm ↑ Summary blib/lib/ASP4/RequestFilter.pm »