| 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 | 7 | $Apache::Singleton::VERSION = '0.17'; | |||||||||||||||||||||||||||
| 12 | # ABSTRACT: Singleton class for mod_perl | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # load appropriate subclass | ||||||||||||||||||||||||||||
| 18 | 7 | ▶ | if ($ENV{MOD_PERL}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | require Apache::Singleton::Request; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | else { | ||||||||||||||||||||||||||||
| 22 | 7 | require Apache::Singleton::Process; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 22 | ▶ | sub instance { | ||||||||||||||||||||||||||
|
Subroutine
instance: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 22 | my $class = shift; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 22 | my $instance = $class->_get_instance; | |||||||||||||||||||||||||||
| 29 | 22 | ▶ | unless (defined $instance) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 10 | $instance = $class->_new_instance(@_); | |||||||||||||||||||||||||||
| 31 | 10 | $class->_set_instance($instance); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 22 | return $instance; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 10 | ▶ | sub _new_instance { | ||||||||||||||||||||||||||
|
Subroutine
_new_instance: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 37 | 10 | my $class = shift; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my %args = (@_ && ref $_[0] eq 'HASH') ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 10 | bless { %args }, $class; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # Abstract methods, but compatible default | ||||||||||||||||||||||||||||
| 45 | 10 | ▶ | sub _get_instance { | ||||||||||||||||||||||||||
|
Subroutine
_get_instance: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 46 | 10 | my $class = shift; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 10 | ▶ | if ($ENV{MOD_PERL}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | $class->Apache::Singleton::Request::_get_instance(@_); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | else { | ||||||||||||||||||||||||||||
| 52 | 10 | $class->Apache::Singleton::Process::_get_instance(@_); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 4 | ▶ | sub _set_instance { | ||||||||||||||||||||||||||
|
Subroutine
_set_instance: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 57 | 4 | my $class = shift; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 4 | ▶ | if ($ENV{MOD_PERL}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | $class->Apache::Singleton::Request::_set_instance(@_); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||
| 63 | 4 | $class->Apache::Singleton::Process::_set_instance(@_); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 7 | 1; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | __END__ | ||||||||||||||||||||||||||||