line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of Apache-Singleton |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is copyright (c) 2009 by Michael Schout. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
7
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package Apache::Singleton; |
11
|
|
|
|
|
|
|
$Apache::Singleton::VERSION = '0.17'; |
12
|
|
|
|
|
|
|
# ABSTRACT: Singleton class for mod_perl |
13
|
|
|
|
|
|
|
|
14
|
7
|
|
|
7
|
|
199090
|
use strict; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
177
|
|
15
|
7
|
|
|
7
|
|
34
|
use warnings; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
1559
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# load appropriate subclass |
18
|
|
|
|
|
|
|
if ($ENV{MOD_PERL}) { |
19
|
|
|
|
|
|
|
require Apache::Singleton::Request; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
else { |
22
|
|
|
|
|
|
|
require Apache::Singleton::Process; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub instance { |
26
|
22
|
|
|
22
|
0
|
1103
|
my $class = shift; |
27
|
|
|
|
|
|
|
|
28
|
22
|
|
|
|
|
57
|
my $instance = $class->_get_instance; |
29
|
22
|
100
|
|
|
|
78
|
unless (defined $instance) { |
30
|
10
|
|
|
|
|
36
|
$instance = $class->_new_instance(@_); |
31
|
10
|
|
|
|
|
40
|
$class->_set_instance($instance); |
32
|
|
|
|
|
|
|
} |
33
|
22
|
|
|
|
|
56
|
return $instance; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _new_instance { |
37
|
10
|
|
|
10
|
|
26
|
my $class = shift; |
38
|
|
|
|
|
|
|
|
39
|
10
|
50
|
66
|
|
|
41
|
my %args = (@_ && ref $_[0] eq 'HASH') ? %{ $_[0] } : @_; |
|
0
|
|
|
|
|
0
|
|
40
|
|
|
|
|
|
|
|
41
|
10
|
|
|
|
|
27
|
bless { %args }, $class; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Abstract methods, but compatible default |
45
|
|
|
|
|
|
|
sub _get_instance { |
46
|
10
|
|
|
10
|
|
11
|
my $class = shift; |
47
|
|
|
|
|
|
|
|
48
|
10
|
50
|
|
|
|
19
|
if ($ENV{MOD_PERL}) { |
49
|
0
|
|
|
|
|
0
|
$class->Apache::Singleton::Request::_get_instance(@_); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
10
|
|
|
|
|
28
|
$class->Apache::Singleton::Process::_get_instance(@_); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _set_instance { |
57
|
4
|
|
|
4
|
|
6
|
my $class = shift; |
58
|
|
|
|
|
|
|
|
59
|
4
|
50
|
|
|
|
8
|
if ($ENV{MOD_PERL}) { |
60
|
0
|
|
|
|
|
0
|
$class->Apache::Singleton::Request::_set_instance(@_); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
4
|
|
|
|
|
10
|
$class->Apache::Singleton::Process::_set_instance(@_); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |