File Coverage

blib/lib/Data/Object/Singleton.pm
Criterion Covered Total %
statement 26 26 100.0
branch 2 4 50.0
condition 3 6 50.0
subroutine 7 7 100.0
pod n/a
total 38 43 88.3


line stmt bran cond sub pod time code
1             # A Singleton Class for Perl 5
2             package Data::Object::Singleton;
3              
4 1     1   650 use 5.010;
  1         3  
  1         42  
5 1     1   345 use Data::Object::Class ();
  1         2  
  1         66  
6              
7             our $VERSION = '0.20'; # VERSION
8              
9             sub import {
10 1     1   11 my $target = caller;
11 1         2 my $class = shift;
12 1         2 my @export = @_;
13              
14 1         8 Data::Object::Class->import($target, @export);
15              
16 1         1223 my $hold;
17              
18 1 50       15 if (my $orig = $class->can('new')) {
19 1     1   7 no strict 'refs';
  1         2  
  1         141  
20 1         7 *{"${target}::new"} = sub {
21 3   66 3   1516 $hold //= $orig->(@_)
22 1         4 };
23             }
24              
25 1 50 33     19 if (my $orig = $class->can('new') and !$class->can('renew')) {
26 1     1   5 no strict 'refs';
  1         2  
  1         73  
27 1         5 *{"${target}::renew"} = sub {
28 1     1   5 $hold = $orig->(@_)
29 1         4 };
30             }
31              
32 1         13 return;
33             }
34              
35             1;