| 1 | |||
| 2 | package ASP4; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings 'all'; | ||
| 6 | our $VERSION = '0.001_05'; | ||
| 7 | |||
| 8 | |||
| 9 | 1;# return true: | ||
| 10 | |||
| 11 | =pod | ||
| 12 | |||
| 13 | =head1 NAME | ||
| 14 | |||
| 15 | ASP4 - Fast, Simple, Scalable Web Development | ||
| 16 | |||
| 17 | =head1 DESCRIPTION | ||
| 18 | |||
| 19 | ASP4 is a web development environment. It takes lessons learned from other web | ||
| 20 | development environments such as Microsoft ASP.Net, Ruby on Rails and Catalyst. | ||
| 21 | |||
| 22 | This project has some top-level priorities: | ||
| 23 | |||
| 24 | =over 4 | ||
| 25 | |||
| 26 | =item * Test-Driven | ||
| 27 | |||
| 28 | ASP4 is made for the test-writing fanatic. Anything your web application might do | ||
| 29 | can be tested - using L<Test::Simple>, L<HTML::Form> and L<ASP4::UserAgent>. | ||
| 30 | |||
| 31 | ASP4 supports test-fixtures, properties files (useful for error messages, etc) | ||
| 32 | and uses a simple plain-text JSON configuration file format. | ||
| 33 | |||
| 34 | =item * Keep It Simple, Smartypants (KISS) | ||
| 35 | |||
| 36 | ASP4 provides a clean slate on which to build web applications. It does not go | ||
| 37 | out of its way to do everything for the developer, and does not enforce any kind | ||
| 38 | of specific coding style. | ||
| 39 | |||
| 40 | =item * Go Faster | ||
| 41 | |||
| 42 | On a server configuration which can serve a static "HELLO WORLD" page at 12,000 requests per second, | ||
| 43 | ASP4 can serve the "HELLO WORLD" equivalent at 1,200 requests per second. A more | ||
| 44 | complex page that involves deeply-nested MasterPages and server-side includes may | ||
| 45 | come in at 1,000 requests per second. | ||
| 46 | |||
| 47 | =item * Easy to Learn | ||
| 48 | |||
| 49 | The intrinsic ASP objects - C<$Request>, C<$Response>, C<$Session>, C<$Server> - | ||
| 50 | and ASP4 extensions - C<$Form>, C<$Config>, C<$Stash> - focus developer attention | ||
| 51 | on a simplified environment, while still offering direct access to the "metal" underneath. | ||
| 52 | |||
| 53 | The classic Perl L<Apache2::RequestRec> C<$r> and L<CGI> objects are always accessible | ||
| 54 | via the L<ASP4::HTTPContext> api. | ||
| 55 | |||
| 56 | =item * Easy to Scale | ||
| 57 | |||
| 58 | Session state can be stored in a database (or distributed via memcached) which means | ||
| 59 | that ASP4 web applications can be served by one machine or many machines. | ||
| 60 | |||
| 61 | B<Outward Scalability> is in the DNA of ASP4. | ||
| 62 | |||
| 63 | =back | ||
| 64 | |||
| 65 | =head1 EXAMPLES | ||
| 66 | |||
| 67 | =head2 ASP Scripts | ||
| 68 | |||
| 69 | ASP scripts are pretty much as you might expect, if you've ever seen an ASP script before: | ||
| 70 | |||
| 71 | <html> | ||
| 72 | <body> | ||
| 73 | <h1>Welcome Back, <%= $Session->{email} || "You" %>!</h1> | ||
| 74 | <% | ||
| 75 | for(1..5) { | ||
| 76 | %> | ||
| 77 | <%= $_ %>: Hello, World!<br/> | ||
| 78 | <% | ||
| 79 | } | ||
| 80 | %> | ||
| 81 | <p> | ||
| 82 | Favorite Color: <%= $Server->HTMLEncode( $Form->{favorite_color} ) %> | ||
| 83 | </p> | ||
| 84 | </body> | ||
| 85 | </html> | ||
| 86 | |||
| 87 | =head2 Form Handlers | ||
| 88 | |||
| 89 | Like "Controllers" in the MVC paradigm, "Handlers" respond to user input without | ||
| 90 | any of the Perl-embedded-in-HTML distraction. | ||
| 91 | |||
| 92 | Some URL-masking happens, so a request to C</handlers/hello.world> would go to: | ||
| 93 | |||
| 94 | package hello::world; | ||
| 95 | |||
| 96 | use strict; | ||
| 97 | use warnings 'all'; | ||
| 98 | use base 'ASP4::FormHandler'; | ||
| 99 | use vars __PACKAGE__->VARS; # Import $Request, $Response, $Session, etc: | ||
| 100 | |||
| 101 | sub run { | ||
| 102 | my ($self, $context) = @_; | ||
| 103 | |||
| 104 | $Response->SetCookie( | ||
| 105 | name => "last-seen", | ||
| 106 | value => scalar(localtime()), | ||
| 107 | expires => 30 * 60 * 60 * 24, # 30 days: | ||
| 108 | ); | ||
| 109 | $Response->Write("Hello World!"); | ||
| 110 | } | ||
| 111 | |||
| 112 | 1;# return true: | ||
| 113 | |||
| 114 | =head2 MasterPages | ||
| 115 | |||
| 116 | Similar to ASP.Net's concept of MasterPages, ASP4's MasterPages allow Page Composition. | ||
| 117 | |||
| 118 | Example: (eg: C</masters/global.asp>) | ||
| 119 | |||
| 120 | <%@ MasterPage %> | ||
| 121 | <html> | ||
| 122 | <head> | ||
| 123 | <title> | ||
| 124 | <asp:ContentPlaceHolder id="meta_title">Default Title</asp:ContentPlaceHolder> | ||
| 125 | </title> | ||
| 126 | <meta name="keywords" content="<asp:ContentPlaceHolder id="meta_keywords"></asp:ContentPlaceHolder>" /> | ||
| 127 | <meta name="description" content="<asp:ContentPlaceHolder id="meta_description"></asp:ContentPlaceHolder>" /> | ||
| 128 | </head> | ||
| 129 | <body> | ||
| 130 | <h1> | ||
| 131 | <asp:ContentPlaceHolder id="page_heading">HELLO</asp:ContentPlaceHolder> | ||
| 132 | </h1> | ||
| 133 | <p> | ||
| 134 | <asp:ContentPlaceHolder id="page_body">Content coming soon!</asp:ContentPlaceHolder> | ||
| 135 | </p> | ||
| 136 | </body> | ||
| 137 | </html> | ||
| 138 | |||
| 139 | If you access the page directly, you would see the default content displayed. | ||
| 140 | |||
| 141 | =head2 Child Pages | ||
| 142 | |||
| 143 | Child pages inherit from MasterPages - exactly like child classes inherit from super classes. | ||
| 144 | |||
| 145 | Example: (eg: C</child.asp>) | ||
| 146 | |||
| 147 | <%@ Page UseMasterPage="/masters/global.asp" %> | ||
| 148 | |||
| 149 | <asp:Content PlaceHolderID="meta_title">Child Title</asp:Content> | ||
| 150 | |||
| 151 | <asp:Content PlaceHolderID="meta_keywords">child keywords</asp:Content> | ||
| 152 | |||
| 153 | <asp:Content PlaceHolderID="meta_description">child description</asp:Content> | ||
| 154 | |||
| 155 | <asp:Content PlaceHolderID="page_heading">The Child Page</asp:Content> | ||
| 156 | |||
| 157 | <asp:Content PlaceHolderID="page_body">Hello from the Child Page - hooray!</asp:Content> | ||
| 158 | |||
| 159 | The result after accessing C</child.asp> you would see the following: | ||
| 160 | |||
| 161 | <html> | ||
| 162 | <head> | ||
| 163 | <title> | ||
| 164 | Child Title | ||
| 165 | </title> | ||
| 166 | <meta name="keywords" content="child keywords" /> | ||
| 167 | <meta name="description" content="child description" /> | ||
| 168 | </head> | ||
| 169 | <body> | ||
| 170 | <h1> | ||
| 171 | The Child Page | ||
| 172 | </h1> | ||
| 173 | <p> | ||
| 174 | Hello from the Child Page - hooray! | ||
| 175 | </p> | ||
| 176 | </body> | ||
| 177 | </html> | ||
| 178 | |||
| 179 | =head2 MasterPage Inheritance | ||
| 180 | |||
| 181 | MasterPages can also inherit from other MasterPages. | ||
| 182 | |||
| 183 | Example: (eg: C</masters/submaster.asp>) | ||
| 184 | |||
| 185 | <%@ MasterPage %> | ||
| 186 | <%@ Page UseMasterPage="/masters/global.asp" %> | ||
| 187 | |||
| 188 | <asp:Content PlaceHolderID="meta_title">Submaster Title</asp:Content> | ||
| 189 | |||
| 190 | <asp:Content PlaceHolderID="meta_keywords">submaster keywords</asp:Content> | ||
| 191 | |||
| 192 | <asp:Content PlaceHolderID="meta_description">submaster description</asp:Content> | ||
| 193 | |||
| 194 | <asp:Content PlaceHolderID="page_heading">The Submaster Page</asp:Content> | ||
| 195 | |||
| 196 | <asp:Content PlaceHolderID="page_body"> | ||
| 197 | The first part.<br/> | ||
| 198 | <asp:ContentPlaceHolder id="sub_section">Hello from the subsection!</asp:ContentPlaceHolder> | ||
| 199 | The final part. | ||
| 200 | </asp:Content> | ||
| 201 | |||
| 202 | A page inheriting from C</masters/submaster.asp> could get by with only: | ||
| 203 | |||
| 204 | <%@ Page UseMasterPage="/masters/submaster.asp" %> | ||
| 205 | |||
| 206 | <asp:Content PlaceHolderID="sub_section"> | ||
| 207 | <b>Hello from the subsection!</b><br/> | ||
| 208 | </asp:Content> | ||
| 209 | |||
| 210 | The resulting content would be: | ||
| 211 | |||
| 212 | <html> | ||
| 213 | <head> | ||
| 214 | <title> | ||
| 215 | Submaster Title | ||
| 216 | </title> | ||
| 217 | <meta name="keywords" content="submaster keywords" /> | ||
| 218 | <meta name="description" content="submaster description" /> | ||
| 219 | </head> | ||
| 220 | <body> | ||
| 221 | <h1> | ||
| 222 | The Submaster Page | ||
| 223 | </h1> | ||
| 224 | <p> | ||
| 225 | The first part.<br/> | ||
| 226 | <b>Hello from the subsection!</b><br/> | ||
| 227 | The final part. | ||
| 228 | </p> | ||
| 229 | </body> | ||
| 230 | </html> | ||
| 231 | |||
| 232 | B<**THEN**> you could further subclass like this: | ||
| 233 | |||
| 234 | <%@ Page UseMasterPage="/masters/submaster.asp" %> | ||
| 235 | |||
| 236 | <asp:Content PlaceHolderID="meta_title">My Title!</asp:Content> | ||
| 237 | |||
| 238 | <asp:Content PlaceHolderID="sub_section">My Content Too!</asp:Content> | ||
| 239 | |||
| 240 | The output would be: | ||
| 241 | |||
| 242 | <html> | ||
| 243 | <head> | ||
| 244 | <title> | ||
| 245 | My Title! | ||
| 246 | </title> | ||
| 247 | <meta name="keywords" content="submaster keywords" /> | ||
| 248 | <meta name="description" content="submaster description" /> | ||
| 249 | </head> | ||
| 250 | <body> | ||
| 251 | <h1> | ||
| 252 | The Submaster Page | ||
| 253 | </h1> | ||
| 254 | <p> | ||
| 255 | |||
| 256 | The first part.<br/> | ||
| 257 | My Content Too! | ||
| 258 | The final part. | ||
| 259 | |||
| 260 | </p> | ||
| 261 | </body> | ||
| 262 | </html> | ||
| 263 | |||
| 264 | =head1 AUTHOR | ||
| 265 | |||
| 266 | John Drago <jdrago_999@yahoo.com> | ||
| 267 | |||
| 268 | =head1 COPYRIGHT | ||
| 269 | |||
| 270 | This software is Free software and may be used and redistributed under the same | ||
| 271 | terms as perl itself. | ||
| 272 | |||
| 273 | =cut | ||
| 274 |