| 1 | package Class::SingletonProxy; | ||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||
| 3 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | 1 | our %target; | |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||
| 12 | 1 | ▶ | sub import { | ||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 13 | 1 | my $class = shift; | |||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||
| 16 | 0 | ▶ | sub new { Carp::croak "new called on a singleton class" } | ||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||
| 18 | 0 | ▶ | sub singleton { | ||||||||||||||||||||||
|
Subroutine
singleton: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||
| 19 | 0 | my $class = shift; | |||||||||||||||||||||||
| 20 | 0 | ▶ | @_ ? $target{$class} = shift : $target{$class} | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||
| 23 | 0 | ▶ | sub SINGLETON { | ||||||||||||||||||||||
|
Subroutine
SINGLETON: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||
| 24 | 0 | my $class = shift; | |||||||||||||||||||||||
| 25 | 0 | Carp::croak("SINGLETON subroutine not defined in class $class"); | |||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||
| 28 | 1 | our $AUTOLOAD; | |||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||
| 30 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=1 SCAR=4.4
| |||||||||||||||||||||||||
| 31 | 0 | my $class = $_[0]; | |||||||||||||||||||||||
| 32 | 0 | my ($method) = $AUTOLOAD =~ /([^:]*)$/; | |||||||||||||||||||||||
| 33 | # print "autoloading ${class} -> ${method} ($AUTOLOAD)\n"; | ||||||||||||||||||||||||
| 34 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 35 | 0 | *{$AUTOLOAD} = | |||||||||||||||||||||||
| 36 | 0 | ▶ | sub { | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||
| 37 | 0 | my $class = shift; | |||||||||||||||||||||||
| 38 | # print "class=$class target=$target{$class}\n"; | ||||||||||||||||||||||||
| 39 | 0 | ▶ | my $self = $target{$class} ||= | ||||||||||||||||||||||
|
Condition0%0/5
$Class::SingletonProxy::target{$class} ||= $class->SINGLETON || Carp::croak("$class->SINGLETON returned undef")
$class->SINGLETON || Carp::croak("$class->SINGLETON returned undef")
MC/DC0%0/2
$Class::SingletonProxy::target{$class} ||= $class->SINGLETON || Carp::croak("$class->SINGLETON returned undef")
$Class::SingletonProxy::target{$class}
$class->SINGLETON
Truth table0%0/3
A ||= B
A= $Class::SingletonProxy::target{$class}B= $class->SINGLETON
| |||||||||||||||||||||||||
| 40 | ( $class->SINGLETON or Carp::croak "$class->SINGLETON returned undef" ); | ||||||||||||||||||||||||
| 41 | 0 | $self->$method(@_) | |||||||||||||||||||||||
| 42 | 0 | }; | |||||||||||||||||||||||
| 43 | 0 | goto &{$AUTOLOAD}; | |||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||
| 48 | 1 | 1; | |||||||||||||||||||||||
| 49 | __END__ | ||||||||||||||||||||||||