File Coverage

blib/lib/Apache/Singleton.pm
Criterion Covered Total %
statement 18 21 85.7
branch 5 8 62.5
condition 2 3 66.6
subroutine 5 5 100.0
pod 0 1 0.0
total 30 38 78.9


line stmt bran cond sub pod time code
1             package Apache::Singleton;
2             $Apache::Singleton::VERSION = '0.16';
3             # ABSTRACT: Singleton class for mod_perl
4              
5 7     7   73055 use strict;
  7         11  
  7         1511  
6              
7             # load appropriate subclass
8             if ($ENV{MOD_PERL}) {
9             require Apache::Singleton::Request;
10             }
11             else {
12             require Apache::Singleton::Process;
13             }
14              
15             sub instance {
16 22     22 0 647 my $class = shift;
17              
18 22         71 my $instance = $class->_get_instance;
19 22 100       74 unless (defined $instance) {
20 10         48 $instance = $class->_new_instance(@_);
21 10         55 $class->_set_instance($instance);
22             }
23 22         501 return $instance;
24             }
25              
26             sub _new_instance {
27 10     10   13 my $class = shift;
28              
29 10 50 66     61 my %args = (@_ && ref $_[0] eq 'HASH') ? %{ $_[0] } : @_;
  0         0  
30              
31 10         40 bless { %args }, $class;
32             }
33              
34             # Abstract methods, but compatible default
35             sub _get_instance {
36 10     10   10 my $class = shift;
37              
38 10 50       21 if ($ENV{MOD_PERL}) {
39 0         0 $class->Apache::Singleton::Request::_get_instance(@_);
40             }
41             else {
42 10         38 $class->Apache::Singleton::Process::_get_instance(@_);
43             }
44             }
45              
46             sub _set_instance {
47 4     4   7 my $class = shift;
48              
49 4 50       13 if ($ENV{MOD_PERL}) {
50 0         0 $class->Apache::Singleton::Request::_set_instance(@_);
51             }
52             else {
53 4         18 $class->Apache::Singleton::Process::_set_instance(@_);
54             }
55             }
56              
57             1;
58              
59             __END__