| 1 | package Bot::Cobalt::Core::Role::Singleton; | ||||||||||||||||||||
| 2 | 1 | $Bot::Cobalt::Core::Role::Singleton::VERSION = '0.021003'; | |||||||||||||||||||
| 3 | 1 | ▶ | use Carp 'confess'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strictures 2; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use Moo::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | ▶ | sub instance { | ||||||||||||||||||
|
Subroutine
instance: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 11 | 2 | my $class = $_[0]; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | my $this_obj = \${$class.'::_singleton'}; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | ▶ | defined $$this_obj ? $$this_obj | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 16 | : ( $$this_obj = $class->new(@_[1 .. $#_]) ) | ||||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 2 | ▶ | sub has_instance { | ||||||||||||||||||
|
Subroutine
has_instance: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 20 | 2 | ▶ | my $class = ref $_[0] || $_[0]; | ||||||||||||||||||
|
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||
| 21 | 2 | !! ${$class.'::_singleton'}; | |||||||||||||||||||
| 22 | } | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | ▶ | sub clear_instance { | ||||||||||||||||||
|
Subroutine
clear_instance: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||
| 25 | 1 | ▶ | my $class = ref $_[0] || $_[0]; | ||||||||||||||||||
|
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||
| 26 | 1 | ${$class.'::_singleton'} = undef; | |||||||||||||||||||
| 27 | 1 | 1 | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | ▶ | sub is_instanced { | ||||||||||||||||||
|
Subroutine
is_instanced: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 31 | 0 | confess "is_instanced is deprecated; use has_instance" | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 1 | 1; | |||||||||||||||||||
| 35 | __END__ | ||||||||||||||||||||