File Coverage

blib/lib/Apache/ASP/Application.pm
Criterion Covered Total %
statement 46 53 86.7
branch 12 20 60.0
condition 3 6 50.0
subroutine 12 12 100.0
pod 0 5 0.0
total 73 96 76.0


line stmt bran cond sub pod time code
1              
2             package Apache::ASP::Application;
3              
4 13     13   81 use Apache::ASP::State;
  13         31  
  13         379  
5 13     13   78 use Apache::ASP::Collection;
  13         28  
  13         365  
6              
7 13     13   72 use strict;
  13         26  
  13         520  
8 13     13   76 no strict qw(refs);
  13         30  
  13         383  
9 13     13   148 use vars qw(@ISA);
  13         23  
  13         809  
10             @ISA = qw(Apache::ASP::Collection Apache::ASP::State);
11 13     13   85 use Fcntl qw(:flock O_RDWR O_CREAT );
  13         28  
  13         8265  
12              
13             sub new {
14 28     28 0 49 my($asp) = @_;
15 28         45 my(%self);
16              
17 28 50       148 unless(
18             tie(
19             %self,'Apache::ASP::State', $asp,
20             'application', 'server',
21             )
22             )
23             {
24 0         0 $asp->Error("can't tie to application state");
25 0         0 return;
26             }
27              
28 28         290 bless \%self;
29             }
30              
31 2     2 0 26 sub Lock { shift->SUPER::LOCK };
32 12     12 0 93 sub UnLock { shift->SUPER::UNLOCK };
33              
34             sub SessionCount {
35 30     30 0 42 my $asp = tied(%{$_[0]})->{asp};
  30         84  
36 30 50       89 if($asp->{session_count}) {
37 30         151 $asp->{Internal}{SessionCount};
38             } else {
39 0         0 undef;
40             }
41             }
42              
43             sub GetSession {
44 11     11 0 76 my($self, $id) = @_;
45 11         22 my $asp = tied(%$self)->{'asp'};
46 11 50 33     62 unless(defined $id and $id) {
47 0         0 $asp->Warn("session id not defined");
48 0         0 return;
49             }
50 11 50       28 unless(length($id) >= 8) {
51 0         0 $asp->Warn("session id must be of at least 8 in length");
52 0         0 return;
53             }
54              
55 11 100 66     56 if($asp->{Session} and $asp->{Session}->SessionID() eq $id) {
56 1         4 return $asp->{Session};
57             } else {
58 10         31 my $new_session = Apache::ASP::Session::new($asp, $id, O_RDWR, 'NOERR');
59 10 50       26 if($new_session) {
60 10 100       26 if ($asp->{get_session_last}) {
61 9         11 my $session_obj = tied %{$asp->{get_session_last}};
  9         17  
62 9 50       23 $asp->{dbg} && $asp->Debug("freeing last session $asp->{get_session_last} $session_obj");
63 9 50       36 $session_obj && $session_obj->DESTROY;
64             }
65 10         17 $asp->{get_session_last} = $new_session;
66             $asp->RegisterCleanup(sub {
67 10     10   17 my $session_obj = tied %$new_session;
68 10 50       40 $session_obj && $session_obj->DESTROY;
69 10         59 });
70             }
71 10         30 $new_session;
72             }
73             }
74              
75             1;