| 1 | package Object::Container; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use parent qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | our $VERSION = '0.15'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | __PACKAGE__->mk_accessors(qw/registered_classes autoloader_rules objects/); | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | our $_HAVE_EAC = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 13 | eval { local $SIG{__DIE__}; require Exporter::AutoClean; }; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | $_HAVE_EAC = 0; | |||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | do { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | my @EXPORTS; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | sub import { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 17 | ▶ | my ($class, $name) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 17 | ▶ | return unless $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 8 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 13 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | ▶ | if ($name =~ /^-base$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | push @{"${caller}::ISA"}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | my $r = $class->can('register'); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | my $l = $class->can('autoloader'); | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | my %exports = ( | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | ▶ | register => sub { $r->($caller, @_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | autoloader => sub { $l->($caller, @_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | preload => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $caller->instance->get($_) for @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | preload_all_except => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | $caller->instance->load_all_except(@_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | preload_all => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | $caller->instance->load_all; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | ▶ | if ($Object::Container::_HAVE_EAC) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | Exporter::AutoClean->export( $caller, %exports ); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | while (my ($name, $fn) = each %exports) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 10 | *{"${caller}::${name}"} = $fn; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | @EXPORTS = keys %exports; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 13 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | *{"${caller}::${name}"} = sub { | |||||||||||||||||||||||||||||||||||||||||
| 62 | 11 | ▶ | my ($target) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 11 | ▶ | return $target ? $class->get($target) : $class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | sub unimport { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | my $caller = caller; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unimport: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 13 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | for my $name (@EXPORTS) { | |||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | delete ${ $caller . '::' }{ $name }; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | 1; # for EOF | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 13 | my %INSTANCES; | |||||||||||||||||||||||||||||||||||||||||
| 82 | sub instance { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 24 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
instance: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 24 | ▶ | return $INSTANCES{$class} ||= $class->new; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$INSTANCES{$class} ||= $class->new
MC/DC0%0/2
$INSTANCES{$class} ||= $class->new
$INSTANCES{$class}
$class->new
Truth table66%2/3
A ||= B
A= $INSTANCES{$class}B= $class->new
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | sub has_instance { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_instance: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | $class = ref $class || $class; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | return $INSTANCES{$class}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 17 | ▶ | $_[0]->SUPER::new( +{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | registered_classes => +{}, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | autoloader_rules => +[], | ||||||||||||||||||||||||||||||||||||||||||
| 97 | objects => +{}, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | sub register { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 22 | ▶ | my ($self, $args, @rest) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=11 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 22 | ▶ | $self = $self->instance unless ref $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 22 | my ($class, $initializer, $is_preload); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 22 | ▶ | if (defined $args && !ref $args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $args and not ref $args
MC/DC50%1/2
defined $args and not ref $args
defined $args
not ref $args
Truth table66%2/3
A and not(B)
A= defined $argsB= not ref $args
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 19 | $class = $args; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 19 | ▶ | if (@rest == 1 and ref $rest[0] eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@rest == 1 and ref $rest[0] eq "CODE"
MC/DC50%1/2
@rest == 1 and ref $rest[0] eq "CODE"
@rest == 1
ref $rest[0] eq "CODE"
Truth table66%2/3
A and B
A= @rest == 1B= ref $rest[0] eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | $initializer = $rest[0]; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | $initializer = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 11 | ▶ | $self->ensure_class_loaded($class); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 11 | $class->new(@rest); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | elsif (ref $args eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | $class = $args->{class}; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | ▶ | if (exists $args->{initializer} && ref $args->{initializer} eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $args->{"initializer"} and ref $args->{"initializer"} eq "CODE"
MC/DC50%1/2
exists $args->{"initializer"} and ref $args->{"initializer"} eq "CODE"
exists $args->{"initializer"}
ref $args->{"initializer"} eq "CODE"
Truth table66%2/3
A and B
A= exists $args->{"initializer"}B= ref $args->{"initializer"} eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | $initializer = $args->{initializer}; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 124 | $initializer = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | $self->ensure_class_loaded($class); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | $class->new(@{exists $args->{args} ? $args->{args} : []}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | ▶ | $is_preload = 1 if $args->{preload}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | croak "Usage: $self->register($class || { class => $class ... })"; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 22 | $self->registered_classes->{$class} = $initializer; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 22 | ▶ | $self->get($class) if $is_preload; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 22 | return $initializer; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | sub unregister { | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | my ($self, $class) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unregister: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | ▶ | $self = $self->instance unless ref $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | delete $self->registered_classes->{$class} and $self->remove($class); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | sub autoloader { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | my ($self, $rule, $trigger) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
autoloader: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | $self = $self->instance unless ref $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | push @{ $self->autoloader_rules }, [$rule, $trigger]; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | sub get { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 32 | ▶ | my ($self, $class) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 32 | ▶ | $self = $self->instance unless ref $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 32 | ▶ | my $obj = $self->objects->{ $class } ||= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->objects->{$class} ||= do {
my $initializer = $self->registered_classes->{$class};
$initializer ? &$initializer($self) : ()
}
MC/DC100%2/2
$self->objects->{$class} ||= do {
my $initializer = $self->registered_classes->{$class};
$initializer ? &$initializer($self) : ()
}
$self->objects->{$class}
do {
my $initializer = $self->registered_classes->{$class};
$initializer ? &$initializer($self) : ()
}
Truth table100%3/3
A ||= B
A= $self->objects->{$class}B= do {
my $initializer = $self->registered_classes->{$class};
$initializer ? &$initializer($self) : ()
}
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 21 | my $initializer = $self->registered_classes->{ $class }; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 21 | ▶ | $initializer ? $initializer->($self) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 32 | ▶ | unless ($obj) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | # autoloaderer | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 3 | ▶ | if (my ($trigger) = grep { $class =~ /$_->[0]/ } @{ $self->autoloader_rules }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | $trigger->[1]->($self, $class); | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | ▶ | $obj = $self->objects->{ $class } ||= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->objects->{$class} ||= do {
my $initializer = $self->registered_classes->{$class};
$initializer ? &$initializer($self) : ()
}
MC/DC50%1/2
$self->objects->{$class} ||= do {
my $initializer = $self->registered_classes->{$class};
$initializer ? &$initializer($self) : ()
}
$self->objects->{$class}
do {
my $initializer = $self->registered_classes->{$class};
$initializer ? &$initializer($self) : ()
}
Truth table66%2/3
A ||= B
A= $self->objects->{$class}B= do {
my $initializer = $self->registered_classes->{$class};
$initializer ? &$initializer($self) : ()
}
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | my $initializer = $self->registered_classes->{ $class }; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | ▶ | $initializer ? $initializer->($self) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 32 | ▶ | $obj or croak qq["$class" is not registered in @{[ ref $self ]}]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | sub remove { | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | ▶ | my ($self, $class) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | ▶ | $self = $self->instance unless ref $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | delete $self->objects->{ $class }; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | sub load_all { | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | $self->load_all_except; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | sub load_all_except { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | ▶ | my ($self, @except) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_all_except: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 3 | ▶ | $self = $self->instance unless ref $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | for my $class (keys %{ $self->registered_classes }) { | |||||||||||||||||||||||||||||||||||||||||
| 196 | 6 | ▶ | next if grep { $class eq $_ } @except; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | $self->get($class); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | # taken from Mouse | ||||||||||||||||||||||||||||||||||||||||||
| 202 | sub _is_class_loaded { | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 12 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_class_loaded: called CC=17 SCAR=36.6
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 12 | ▶ | return 0 if ref($class) || !defined($class) || !length($class); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $class or not defined $class or not length $class
ref $class or not defined $class
MC/DC0%0/3
ref $class or not defined $class or not length $class
ref $class
not defined $class
not length $class
Truth table25%1/4
A or not(B) or not(C)
A= ref $classB= not defined $classC= not length $class
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | # walk the symbol table tree to avoid autovififying | ||||||||||||||||||||||||||||||||||||||||||
| 208 | # \*{${main::}{"Foo::"}{"Bar::"}} == \*main::Foo::Bar:: | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 12 | my $pack = \%::; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 12 | foreach my $part (split('::', $class)) { | |||||||||||||||||||||||||||||||||||||||||
| 212 | 14 | $part .= '::'; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 14 | ▶ | return 0 if !exists $pack->{$part}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 11 | my $entry = \$pack->{$part}; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 11 | ▶ | return 0 if ref($entry) ne 'GLOB'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 11 | $pack = *{$entry}{HASH}; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 9 | ▶ | return 0 if !%{$pack}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | # check for $VERSION or @ISA | ||||||||||||||||||||||||||||||||||||||||||
| 223 | return 1 if exists $pack->{VERSION} | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 9 | ▶ | && defined *{$pack->{VERSION}}{SCALAR} && defined ${ $pack->{VERSION} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
exists $pack->{"VERSION"} and defined *{$pack->{"VERSION"};}{"SCALAR"} and defined ${$$pack{"VERSION"};}
exists $pack->{"VERSION"} and defined *{$pack->{"VERSION"};}{"SCALAR"}
MC/DC33%1/3
exists $pack->{"VERSION"} and defined *{$pack->{"VERSION"};}{"SCALAR"} and defined ${$$pack{"VERSION"};}
exists $pack->{"VERSION"}
defined *{$pack->{"VERSION"};}{"SCALAR"}
defined ${$$pack{"VERSION"};}
Truth table50%2/4
A and B and C
A= exists $pack->{"VERSION"}B= defined *{$pack->{"VERSION"};}{"SCALAR"}C= defined ${$$pack{"VERSION"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | return 1 if exists $pack->{ISA} | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 6 | ▶ | && defined *{$pack->{ISA}}{ARRAY} && @{ $pack->{ISA} } != 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $pack->{"ISA"} and defined *{$pack->{"ISA"};}{"ARRAY"} and @{$pack->{"ISA"};} != 0
exists $pack->{"ISA"} and defined *{$pack->{"ISA"};}{"ARRAY"}
MC/DC0%0/3
exists $pack->{"ISA"} and defined *{$pack->{"ISA"};}{"ARRAY"} and @{$pack->{"ISA"};} != 0
exists $pack->{"ISA"}
defined *{$pack->{"ISA"};}{"ARRAY"}
@{$pack->{"ISA"};} != 0
Truth table25%1/4
A and B and C
A= exists $pack->{"ISA"}B= defined *{$pack->{"ISA"};}{"ARRAY"}C= @{$pack->{"ISA"};} != 0
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | # check for any method | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | foreach my $name( keys %{$pack} ) { | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $entry = \$pack->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | return 1 if ref($entry) ne 'GLOB' || defined *{$entry}{CODE}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $entry ne "GLOB" or defined *{$entry;}{"CODE"}
MC/DC0%0/2
ref $entry ne "GLOB" or defined *{$entry;}{"CODE"}
ref $entry ne "GLOB"
defined *{$entry;}{"CODE"}
Truth table0%0/3
A or B
A= ref $entry ne "GLOB"B= defined *{$entry;}{"CODE"}
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | # fail | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | sub _try_load_one_class { | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 12 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_try_load_one_class: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 12 | ▶ | return '' if _is_class_loaded($class); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 3 | my $klass = $class; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 3 | $klass =~ s{::}{/}g; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 3 | $klass .= '.pm'; | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 3 | return do { | |||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 3 | eval { require $klass }; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 3 | $@; | |||||||||||||||||||||||||||||||||||||||||
| 251 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | sub ensure_class_loaded { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 12 | ▶ | my ($self, $class) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ensure_class_loaded: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 12 | my $e = _try_load_one_class($class); | |||||||||||||||||||||||||||||||||||||||||
| 257 | 12 | ▶ | Carp::confess "Could not load class ($class) because : $e" if $e; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 12 | return $class; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 263 | __END__ | ||||||||||||||||||||||||||||||||||||||||||