| 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::Process; | ||||||||||||||||||||
| 11 | 7 | $Apache::Singleton::Process::VERSION = '0.17'; | |||||||||||||||||||
| 12 | # ABSTRACT: One instance per One Process | ||||||||||||||||||||
| 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 | 7 | ▶ | use base 'Apache::Singleton'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 7 | my %INSTANCES; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 14 | ▶ | sub _get_instance { | ||||||||||||||||||
|
Subroutine
_get_instance: called CC=2 SCAR=7.6
| |||||||||||||||||||||
| 24 | 14 | my $class = shift; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 14 | ▶ | $class = ref $class || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 14 | return $INSTANCES{$class}; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 6 | ▶ | sub _set_instance { | ||||||||||||||||||
|
Subroutine
_set_instance: called CC=2 SCAR=7.6
| |||||||||||||||||||||
| 32 | 6 | my($class, $instance) = @_; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 6 | ▶ | $class = ref $class || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 6 | $INSTANCES{$class} = $instance; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 7 | ▶ | END { | ||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | # dereferences and causes orderly destruction of all instances | ||||||||||||||||||||
| 41 | 7 | undef(%INSTANCES); | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 7 | 1; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | __END__ | ||||||||||||||||||||