blib/lib/Bot/Cobalt/Core/Role/Singleton.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 45 SCAR 17.9
CC
2
Cov
0%
instance
6.0
has_instance
2.0
clear_instance
2.0
CRAP 6.0
1 package Bot::Cobalt::Core::Role::Singleton;
2 $Bot::Cobalt::Core::Role::Singleton::VERSION = '0.021002';
3 use Carp 'confess';
4 use strictures 2;
5  
6 use Moo::Role;
7  
8 no strict 'refs';
9  
10 sub instance {
11 my $class = $_[0];
12  
13 my $this_obj = \${$class.'::_singleton'};
14
15 defined $$this_obj ? $$this_obj
16 : ( $$this_obj = $class->new(@_[1 .. $#_]) )
17 }
18  
19 sub has_instance {
20 my $class = ref $_[0] || $_[0];
21 !! ${$class.'::_singleton'};
22 }
23  
24 sub clear_instance {
25 my $class = ref $_[0] || $_[0];
26 ${$class.'::_singleton'} = undef;
27 1
28 }
29  
30 sub is_instanced {
31 confess "is_instanced is deprecated; use has_instance"
32 }
33  
34 1;
35 __END__