File Coverage

blib/lib/Bubblegum/Singleton.pm
Criterion Covered Total %
statement 26 26 100.0
branch 1 2 50.0
condition 2 3 66.6
subroutine 7 7 100.0
pod n/a
total 36 38 94.7


line stmt bran cond sub pod time code
1             # ABSTRACT: Singleton Pattern for Bubblegum via Moo
2             package Bubblegum::Singleton;
3              
4 2     2   303 use 5.10.0;
  2         5  
  2         67  
5 2     2   850 use namespace::autoclean;
  2         27056  
  2         8  
6              
7 2     2   1012 use Moo 'with';
  2         14464  
  2         9  
8              
9             with 'Bubblegum::Role::Configuration';
10              
11             our $VERSION = '0.45'; # VERSION
12              
13             sub import {
14 2     2   175 my $target = caller;
15 2         4 my $class = shift;
16 2         5 my @export = @_;
17              
18 2         8 $class->prerequisites($target);
19 2         1174 Moo->import::into($target, @export);
20              
21 2         2231 my $inst;
22 2         25 my $orig = $class->can('new');
23 2     2   2663 no strict 'refs';
  2         4  
  2         229  
24 2         9 *{"${target}::new"} = sub {
25 9   66 9   2246 $inst //= $orig->(@_)
26 2         11 };
27              
28 2 50       19 if (!$class->can('renew')) {
29 2         36 *{"${target}::renew"} = sub {
30 1     1   5 $inst = $orig->(@_)
31 2         7 };
32             }
33             }
34              
35             1;
36              
37             __END__