File Coverage

blib/lib/Data/Object/Singleton.pm
Criterion Covered Total %
statement 25 25 100.0
branch 3 4 75.0
condition n/a
subroutine 7 7 100.0
pod n/a
total 35 36 97.2


line stmt bran cond sub pod time code
1             # ABSTRACT: Singleton Declaration for Perl 5
2             package Data::Object::Singleton;
3              
4 1     1   760 use 5.010;
  1         4  
5 1     1   786 use parent 'Moo';
  1         361  
  1         7  
6              
7             our $VERSION = '0.41'; # VERSION
8              
9             sub import {
10 1     1   13 my $class = shift;
11 1         3 my $target = caller;
12 1         1 my $state = undef;
13              
14 1     1   7 eval "package $target; use Moo; 1;";
  1         2  
  1         9  
  1         88  
15              
16 1         10 my $new = $target->can('new');
17 1         4 my $renew = $target->can('renew');
18              
19 1     1   16986 no strict 'refs';
  1         3  
  1         162  
20              
21 1 100   3   4 *{"${target}::new"} = sub { $state = $new->(@_) if !$state; $state };
  1         3  
  3         622  
  3         37  
22 1 50   1   5 *{"${target}::renew"} = sub { $state = $new->(@_) } if !$renew;
  1         3  
  1         7  
23              
24 1         10 return;
25             }
26              
27             1;
28              
29             __END__