| 1 | |||
| 2 | package Apache2::ASP::GlobalASA; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings 'all'; | ||
| 6 | BEGIN { | ||
| 7 | use vars '@VARS'; | ||
| 8 | our @VARS = qw( | ||
| 9 | $Request $Response | ||
| 10 | $Server $Application | ||
| 11 | $Session $Form | ||
| 12 | $Config $Stash | ||
| 13 | ); | ||
| 14 | use vars @VARS; | ||
| 15 | } | ||
| 16 | |||
| 17 | |||
| 18 | #============================================================================== | ||
| 19 | sub VARS { @VARS } | ||
| 20 | |||
| 21 | |||
| 22 | #============================================================================== | ||
| 23 | sub init_asp_objects | ||
| 24 | { | ||
| 25 | my ($s, $context) = @_; | ||
| 26 | |||
| 27 | no strict 'refs'; | ||
| 28 | my $selfclass = ref($s) || $s; | ||
| 29 | |||
| 30 | # Get each of this classes' superclasses, and theirs as well, recursively: | ||
| 31 | my %c = map { $_ => 1 } ( | ||
| 32 | grep { $_->isa('Apache2::ASP::GlobalASA') } | ||
| 33 | ( $selfclass, @{"$selfclass\::ISA"} ) | ||
| 34 | ); | ||
| 35 | map { $c{$_}++ } map { | ||
| 36 | @{"$_\::ISA"} | ||
| 37 | } keys(%c); | ||
| 38 | my @classes = keys(%c); | ||
| 39 | |||
| 40 | foreach my $class ( @classes ) | ||
| 41 | { | ||
| 42 | ${"$class\::Request"} = $context->request; | ||
| 43 | ${"$class\::Response"} = $context->response; | ||
| 44 | ${"$class\::Server"} = $context->server; | ||
| 45 | ${"$class\::Session"} = $context->session; | ||
| 46 | ${"$class\::Application"} = $context->application; | ||
| 47 | ${"$class\::Config"} = $context->config; | ||
| 48 | ${"$class\::Form"} = $context->request->Form; | ||
| 49 | ${"$class\::Stash"} = $context->stash; | ||
| 50 | }# end foreach() | ||
| 51 | }# end init_asp_objects() | ||
| 52 | |||
| 53 | |||
| 54 | #============================================================================== | ||
| 55 | sub Application_OnStart() | ||
| 56 | { | ||
| 57 | |||
| 58 | }# end Application_OnStart() | ||
| 59 | |||
| 60 | |||
| 61 | #============================================================================== | ||
| 62 | sub Application_OnEnd() | ||
| 63 | { | ||
| 64 | |||
| 65 | }# end Application_OnEnd() | ||
| 66 | |||
| 67 | |||
| 68 | #============================================================================== | ||
| 69 | sub Server_OnStart() | ||
| 70 | { | ||
| 71 | |||
| 72 | }# end Server_OnStart() | ||
| 73 | |||
| 74 | |||
| 75 | #============================================================================== | ||
| 76 | sub Server_OnEnd() | ||
| 77 | { | ||
| 78 | |||
| 79 | }# end Server_OnEnd() | ||
| 80 | |||
| 81 | |||
| 82 | #============================================================================== | ||
| 83 | sub Session_OnStart() | ||
| 84 | { | ||
| 85 | |||
| 86 | }# end Session_OnStart() | ||
| 87 | |||
| 88 | |||
| 89 | #============================================================================== | ||
| 90 | sub Session_OnEnd() | ||
| 91 | { | ||
| 92 | |||
| 93 | }# end Session_OnEnd() | ||
| 94 | |||
| 95 | |||
| 96 | #============================================================================== | ||
| 97 | sub Script_OnStart() | ||
| 98 | { | ||
| 99 | |||
| 100 | }# end Script_OnStart() | ||
| 101 | |||
| 102 | |||
| 103 | #============================================================================== | ||
| 104 | sub Script_OnEnd() | ||
| 105 | { | ||
| 106 | |||
| 107 | }# end Script_OnEnd() | ||
| 108 | |||
| 109 | |||
| 110 | #============================================================================== | ||
| 111 | sub Script_OnError($); | ||
| 112 | |||
| 113 | 1;# return true: | ||
| 114 | |||
| 115 | =pod | ||
| 116 | |||
| 117 | =head1 NAME | ||
| 118 | |||
| 119 | Apache2::ASP::GlobalASA - Base GlobalASA class | ||
| 120 | |||
| 121 | =head1 SYNOPSIS | ||
| 122 | |||
| 123 | In your C<apache2-asp-config.xml>: | ||
| 124 | |||
| 125 | <?xml version="1.0" ?> | ||
| 126 | <config> | ||
| 127 | ... | ||
| 128 | <web> | ||
| 129 | ... | ||
| 130 | <application_name>MyApp</application_name> | ||
| 131 | ... | ||
| 132 | </web> | ||
| 133 | ... | ||
| 134 | </config> | ||
| 135 | |||
| 136 | Then, in C<htdocs/GlobalASA.pm>: | ||
| 137 | |||
| 138 | package MyApp::GlobalASA; | ||
| 139 | |||
| 140 | use strict; | ||
| 141 | use warnings; | ||
| 142 | use base 'Apache2::ASP::GlobalASA'; | ||
| 143 | use vars __PACKAGE__->VARS; | ||
| 144 | |||
| 145 | # Called when the apache httpd process first initializes, | ||
| 146 | # before Application_OnStart is called | ||
| 147 | sub Server_OnStart | ||
| 148 | { | ||
| 149 | warn "Server_OnStart()"; | ||
| 150 | }# end Server_OnStart() | ||
| 151 | |||
| 152 | # Called the first time an application is actually fired up: | ||
| 153 | sub Application_OnStart | ||
| 154 | { | ||
| 155 | warn "Application_OnStart()"; | ||
| 156 | }# end Application_OnStart() | ||
| 157 | |||
| 158 | # Called on the first request received from a client: | ||
| 159 | sub Session_OnStart | ||
| 160 | { | ||
| 161 | warn "Session_OnStart()"; | ||
| 162 | }# end Session_OnStart() | ||
| 163 | |||
| 164 | # Called *after* RequestFilters, but before the ASP script (or handler) | ||
| 165 | sub Script_OnStart | ||
| 166 | { | ||
| 167 | warn "Script_OnStart()"; | ||
| 168 | }# end Session_OnStart() | ||
| 169 | |||
| 170 | # Called after the ASP script or handler, but before any PerlCleanupHandlers | ||
| 171 | sub Script_OnEnd | ||
| 172 | { | ||
| 173 | warn "Script_OnEnd()"; | ||
| 174 | }# end Script_OnEnd() | ||
| 175 | |||
| 176 | 1;# return true: | ||
| 177 | |||
| 178 | =head1 DESCRIPTION | ||
| 179 | |||
| 180 | In "Classic ASP" the Global.ASA provided a means of hooking into the | ||
| 181 | C<Application_OnStart> and C<Session_OnStart> events. | ||
| 182 | |||
| 183 | In C<Apache2::ASP> more events are provided, taking the same idea a little further. | ||
| 184 | |||
| 185 | =head1 EVENTS | ||
| 186 | |||
| 187 | =head2 Server_OnStart | ||
| 188 | |||
| 189 | Called once per Apache httpd process, before C<Application_OnStart>. | ||
| 190 | |||
| 191 | =head2 Application_OnStart | ||
| 192 | |||
| 193 | Called once in the lifetime of an Application. | ||
| 194 | |||
| 195 | =head2 Session_OnStart | ||
| 196 | |||
| 197 | Called once at the beginning of a browser session. | ||
| 198 | |||
| 199 | This is a good place to initialize any session variables. | ||
| 200 | |||
| 201 | =head2 Script_OnStart | ||
| 202 | |||
| 203 | Called after any/all L<Apache2::ASP::RequestFilter>s have finished. | ||
| 204 | |||
| 205 | This event won't get used much anymore, since we have L<Apache2::ASP::RequestFilter>s now, | ||
| 206 | but we keep it around just in case you want it for something quick. | ||
| 207 | |||
| 208 | =head2 Script_OnEnd | ||
| 209 | |||
| 210 | Called after the script has ended, B<before> any C<PerlCleanupHandler>s are called. | ||
| 211 | |||
| 212 | B<NOTE>: This event is not raised if an error is thrown while executing the request. | ||
| 213 | |||
| 214 | =head1 BUGS | ||
| 215 | |||
| 216 | It's possible that some bugs have found their way into this release. | ||
| 217 | |||
| 218 | Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP> to submit bug reports. | ||
| 219 | |||
| 220 | =head1 HOMEPAGE | ||
| 221 | |||
| 222 | Please visit the Apache2::ASP homepage at L<http://www.devstack.com/> to see examples | ||
| 223 | of Apache2::ASP in action. | ||
| 224 | |||
| 225 | =head1 AUTHOR | ||
| 226 | |||
| 227 | John Drago <jdrago_999@yahoo.com> | ||
| 228 | |||
| 229 | =head1 COPYRIGHT | ||
| 230 | |||
| 231 | Copyright 2008 John Drago. All rights reserved. | ||
| 232 | |||
| 233 | =head1 LICENSE | ||
| 234 | |||
| 235 | This software is Free software and is licensed under the same terms as perl itself. | ||
| 236 | |||
| 237 | =cut | ||
| 238 |