File Coverage

blib/lib/ResourcePool/Singleton.pm
Criterion Covered Total %
statement 17 21 80.9
branch 2 2 100.0
condition 4 10 40.0
subroutine 4 5 80.0
pod 2 2 100.0
total 29 40 72.5


line stmt bran cond sub pod time code
1             #*********************************************************************
2             #*** ResourcePool::Singleton.pm
3             #*** Copyright (c) 2002,2003 by Markus Winand
4             #*** $Id: Singleton.pm,v 1.18 2013-04-16 10:14:44 mws Exp $
5             #*********************************************************************
6              
7             package ResourcePool::Singleton;
8              
9 9     9   536 use strict;
  9         17  
  9         291  
10 9     9   46 use vars qw($VERSION);
  9         16  
  9         1897  
11              
12             $VERSION = "1.0107";
13              
14             BEGIN {
15 9     9   217 my $key_hash = {};
16             sub new($$) {
17 94     94 1 420 my $proto = shift;
18 94   66     350 my $class = ref($proto) || $proto;
19 94   100     646 my $key = shift || 'UKN';
20 94         157 my $self = {};
21            
22 94         253 my $rv = $key_hash->{$class}->{$key};
23 94 100       226 if ($rv) {
24 45         155 return $rv;
25             }
26              
27 49         139 $key_hash->{$class}->{$key} = $self;
28              
29 49         144 bless($self, $class);
30            
31 49         141 return $self;
32              
33             }
34              
35             sub is_created($$) {
36 0     0 1   my $proto = shift;
37 0   0       my $class = ref($proto) || $proto;
38 0   0       my $key = shift || 'UKN';
39              
40 0           return defined $key_hash->{$class}->{$key};
41             }
42              
43             }
44             1;