Apache-ASP
view release on metacpan or search on metacpan
lib/Apache/ASP/GlobalASA.pm view on Meta::CPAN
# if we have success compiling, then update the compile time
if(! $@) {
# if file mod times are bad, we need to use them anyway
# for relative comparison, time() was used here before, but
# doesn't work
$compiled->{mtime} = $self->{mtime} || (stat($filename))[9];
# remember whether the file really exists
$compiled->{'exists'} = $exists;
# we cache whether the code was compiled so we can do quick
# lookups before executing it
my $routines = {};
local *stash = *{"$self->{'package'}::"};
for(@Routines) {
if($stash{$_}) {
$routines->{$_} = 1;
}
}
$compiled->{'routines'} = $routines;
$asp->Debug('global.asa routines', $routines);
$self->{'compiled'} = $compiled;
} else {
$asp->CompileErrorThrow($code, "errors compiling global.asa: $@");
}
$self;
}
sub IsCompiled {
my($self, $routine) = @_;
$self->{'compiled'}{routines}{$routine};
}
sub ExecuteEvent {
my($self, $event) = @_;
if($self->{'compiled'}{routines}{$event}) {
$self->{'asp'}->Execute($event);
}
}
sub SessionOnStart {
my $self = shift;
my $asp = $self->{asp};
my $zero_sessions = 0;
if($asp->{session_count}) {
$asp->{Internal}->LOCK();
my $session_count = $asp->{Internal}{SessionCount} || 0;
if($session_count <= 0) {
$asp->{Internal}{SessionCount} = 1;
$zero_sessions = 1;
} else {
$asp->{Internal}{SessionCount} = $session_count + 1;
}
$asp->{Internal}->UNLOCK();
}
#X: would like to run application startup code here after
# zero sessions is true, but doesn't seem to account for
# case of busy server, then 10 minutes later user comes in...
# since group cleanup happens after session, Application
# never starts. Its only when a user times out his own
# session, and comes back that this code would kick in.
$asp->Debug("Session_OnStart", {session => $asp->{Session}->SessionID});
$self->ExecuteEvent('Session_OnStart');
}
sub SessionOnEnd {
my($self, $id) = @_;
my $asp = $self->{asp};
my $internal = $asp->{Internal};
# session count tracking
if($asp->{session_count}) {
$internal->LOCK();
if((my $count = $internal->{SessionCount}) > 0) {
$internal->{SessionCount} = $count - 1;
} else {
$internal->{SessionCount} = 0;
}
$internal->UNLOCK();
}
# only retie session if there is a Session_OnEnd event to execute
if($self->IsCompiled('Session_OnEnd')) {
my $old_session = $asp->{Session};
my $dead_session;
if($id) {
$dead_session = &Apache::ASP::Session::new($asp, $id);
$asp->{Session} = $dead_session;
} else {
$dead_session = $old_session;
}
$asp->{dbg} && $asp->Debug("Session_OnEnd", {session => $dead_session->SessionID()});
$self->ExecuteEvent('Session_OnEnd');
$asp->{Session} = $old_session;
if($id) {
untie %{$dead_session};
}
}
1;
}
sub ApplicationOnStart {
my $self = shift;
$self->{asp}->Debug("Application_OnStart");
%{$self->{asp}{Application}} = ();
$self->ExecuteEvent('Application_OnStart');
}
sub ApplicationOnEnd {
my $self = shift;
my $asp = $self->{asp};
$asp->Debug("Application_OnEnd");
$self->ExecuteEvent('Application_OnEnd');
%{$self->{asp}{Application}} = ();
( run in 0.467 second using v1.01-cache-2.11-cpan-39bf76dae61 )