File Coverage

blib/lib/Bubblegum/Singleton.pm
Criterion Covered Total %
statement 12 26 46.1
branch 0 2 0.0
condition 0 3 0.0
subroutine 4 7 57.1
pod n/a
total 16 38 42.1


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