| 1 | package HO::accessor; | ||||||||||||||||||||||||||||
| 2 | # +++++++++++++++++++ | ||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | our $VERSION='0.053'; | |||||||||||||||||||||||||||
| 5 | # +++++++++++++++++++ | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | ; use Class::ISA () | ||||||||||||||||||||||||||||
| 8 | 13 | ▶ | ; use Package::Subroutine () | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 13 | ▶ | ; use Carp () | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 13 | ▶ | ; our %classes | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 13 | ; my %accessors | |||||||||||||||||||||||||||
| 13 | ; my %methods | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 7 | ▶ | ; our %type = ('@'=>sub () {[]}, '%'=>sub () {{}}, '$'=>sub () {undef}) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 13 | ; our %init = | |||||||||||||||||||||||||||
| 18 | ( 'hash' => sub | ||||||||||||||||||||||||||||
| 19 | 3 | ▶ | { my ($self,%args) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | ; while(my ($method,$value)=each(%args)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 2 | { my $access = "_$method" | |||||||||||||||||||||||||||
| 22 | 2 | ; $self->[$self->$access] = $value | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 3 | ; return $self | |||||||||||||||||||||||||||
| 25 | }, | ||||||||||||||||||||||||||||
| 26 | 'hashref' => sub | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | { my ($self,$args) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | ; while(my ($method,$value)=each(%$args)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | { my $access = "_$method" | |||||||||||||||||||||||||||
| 30 | 0 | ; $self->[$self->$access] = $value | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 0 | ; return $self | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | ) | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 13 | ; our %ro_accessor = | |||||||||||||||||||||||||||
| 37 | 8 | ▶ | ( '$' => sub { my ($n,$class) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 8 | ; my $idx = HO::accessor::_value_of($class, "_$n") | |||||||||||||||||||||||||||
| 39 | ; return sub () | ||||||||||||||||||||||||||||
| 40 | 11 | ▶ | { Carp::confess("Not a class method '$n'.") | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | unless ref($_[0]) | ||||||||||||||||||||||||||||
| 42 | 10 | ; $_[0]->[$idx] | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 8 | } | |||||||||||||||||||||||||||
| 45 | 3 | ▶ | , '@' => sub { my ($n,$class) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 3 | ; my $ai = HO::accessor::_value_of($class, "_$n") | |||||||||||||||||||||||||||
| 47 | ; return sub | ||||||||||||||||||||||||||||
| 48 | 5 | ▶ | { my ($obj,$idx) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 49 | 5 | ▶ | ; if(@_==1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 4 | { return @{$obj->[$ai]} | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | else | ||||||||||||||||||||||||||||
| 53 | 1 | { return $obj->[$ai]->[$idx] | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 3 | }} | |||||||||||||||||||||||||||
| 56 | 3 | ▶ | , '%' => sub { my ($n,$class) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 3 | ; my $idx = HO::accessor::_value_of($class, "_$n") | |||||||||||||||||||||||||||
| 58 | ; return sub | ||||||||||||||||||||||||||||
| 59 | 4 | ▶ | { my ($obj,$key) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 60 | 4 | ; (@_==1) ? {%{$obj->[$idx]}} | |||||||||||||||||||||||||||
| 61 | 4 | ▶ | : $obj->[$idx]->{$key} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 3 | } | |||||||||||||||||||||||||||
| 64 | ) | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 13 | ; our %rw_accessor = | |||||||||||||||||||||||||||
| 67 | 6 | ▶ | ( '$' => sub { my ($n,$class) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | 6 | ; my $idx = HO::accessor::_value_of($class, "_$n") | |||||||||||||||||||||||||||
| 69 | ; return sub | ||||||||||||||||||||||||||||
| 70 | 10 | ▶ | { my ($obj,$val) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 71 | 10 | ▶ | ; Carp::confess("Not a class method '$n'.") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | unless ref($obj) | ||||||||||||||||||||||||||||
| 73 | 9 | ▶ | ; return $obj->[$idx] if @_==1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 2 | ; $obj->[$idx] = $val | |||||||||||||||||||||||||||
| 75 | 2 | ; return $obj | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 6 | } | |||||||||||||||||||||||||||
| 78 | 1 | ▶ | , '@' => sub { my ($n,$class) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | 1 | ; my $ai = HO::accessor::_value_of($class, "_$n") | |||||||||||||||||||||||||||
| 80 | ; return sub | ||||||||||||||||||||||||||||
| 81 | 22 | ▶ | { my ($obj,$idx,$val) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||
| 82 | 22 | ▶ | ; Carp::confess("Not a class method '$n'.") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | unless ref $obj | ||||||||||||||||||||||||||||
| 84 | 22 | ▶ | ; if(@_==1) # get values | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 85 | { # etwas mehr Zugriffsschutz da keine Ref | ||||||||||||||||||||||||||||
| 86 | # einfache Anwendung in bool Kontext | ||||||||||||||||||||||||||||
| 87 | 10 | ; return @{$obj->[$ai]} | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | elsif(@_ == 2) | ||||||||||||||||||||||||||||
| 90 | 4 | ▶ | { unless(ref $idx eq 'ARRAY') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 1 | { return $obj->[$ai]->[$idx] # get one index | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | else | ||||||||||||||||||||||||||||
| 94 | 3 | { $obj->[$ai] = $idx # set complete array | |||||||||||||||||||||||||||
| 95 | 3 | ; return $obj | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | elsif(@_==3) | ||||||||||||||||||||||||||||
| 99 | 8 | ▶ | { if(ref($idx)) | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 100 | 5 | ▶ | { if($val eq '<') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 101 | 1 | { $$idx = shift @{$obj->[$ai]} | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | elsif($val eq '>') | ||||||||||||||||||||||||||||
| 104 | 1 | { $$idx = pop @{$obj->[$ai]} | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | else | ||||||||||||||||||||||||||||
| 107 | 3 | ▶ | { if(@$val == 0) | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 108 | 1 | { @$idx = splice(@{$obj->[$ai]}) | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | elsif(@$val == 1) | ||||||||||||||||||||||||||||
| 111 | 1 | { @$idx = splice(@{$obj->[$ai]},$val->[0]); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | elsif(@$val == 2) | ||||||||||||||||||||||||||||
| 114 | 1 | { @$idx = splice(@{$obj->[$ai]},$val->[0],$val->[1]); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | elsif($idx eq '<') | ||||||||||||||||||||||||||||
| 119 | 1 | { push @{$obj->[$ai]}, $val | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | elsif($idx eq '>') | ||||||||||||||||||||||||||||
| 122 | 1 | { unshift @{$obj->[$ai]}, $val | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | else | ||||||||||||||||||||||||||||
| 125 | 1 | { $obj->[$ai]->[$idx] = $val # set one index | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 8 | ; return $obj | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 1 | } | |||||||||||||||||||||||||||
| 131 | 3 | ▶ | , '%' => sub { my ($n,$class) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 132 | 3 | ; my $idx = HO::accessor::_value_of($class, "_$n") | |||||||||||||||||||||||||||
| 133 | 11 | ▶ | ; return sub { my ($obj,$key) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 134 | 11 | ▶ | ; if(@_==1) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 135 | 5 | { return $obj->[$idx] # for a hash an reference is easier to handle | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | elsif(@_==2) | ||||||||||||||||||||||||||||
| 138 | 5 | ▶ | { if(ref($key) eq 'HASH') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 1 | { $obj->[$idx] = $key | |||||||||||||||||||||||||||
| 140 | 1 | ; return $obj | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | else | ||||||||||||||||||||||||||||
| 143 | 4 | { return $obj->[$idx]->{$key} | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | else | ||||||||||||||||||||||||||||
| 147 | 1 | { shift(@_) | |||||||||||||||||||||||||||
| 148 | 1 | ; my @kv = @_ | |||||||||||||||||||||||||||
| 149 | 1 | ▶ | ; while(@kv) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 1 | { my ($k,$v) = splice(@kv,0,2) | |||||||||||||||||||||||||||
| 151 | 1 | ; $obj->[$idx]->{$k} = $v | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | 1 | ; return $obj | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 3 | }} | |||||||||||||||||||||||||||
| 156 | ) | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 13 | ; our $class | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | ; my $object_builder = sub | ||||||||||||||||||||||||||||
| 161 | 30 | ▶ | { my ($obj,$constructor,$args) = @_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 162 | 30 | ; foreach my $typedefault (@$constructor) | |||||||||||||||||||||||||||
| 163 | 54 | ▶ | { push @{$obj}, ref($typedefault) ? $typedefault->($obj,$args) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | : $typedefault | ||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 13 | ; sub import | |||||||||||||||||||||||||||
| 169 | 31 | ▶ | { my ($package,$ac,$methods,$init,$new) = @_ | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=19 SCAR=30.0
| |||||||||||||||||||||||||||||
| 170 | 31 | ; our %classes | |||||||||||||||||||||||||||
| 171 | 31 | ▶ | ; $ac ||= [] | ||||||||||||||||||||||||||
|
Condition50%1/2
$ac ||= []
MC/DC0%0/1
$ac ||= []
$ac
Truth table50%1/2
A
A= $ac
| |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 31 | ▶ | ; my $caller = $HO::accessor::class || CORE::caller | ||||||||||||||||||||||||||
|
Condition66%2/3
$HO::accessor::class || caller
MC/DC0%0/2
$HO::accessor::class || caller
$HO::accessor::class
caller
Truth table66%2/3
A || B
A= $HO::accessor::classB= caller
| |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 31 | ▶ | ; Carp::croak "HO::accessor::import already called for class $caller." | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
"Package::Subroutine"->isdefined($caller, "new") and $new
MC/DC50%1/2
"Package::Subroutine"->isdefined($caller, "new") and $new
"Package::Subroutine"->isdefined($caller, "new")
$new
Truth table66%2/3
A and B
A= "Package::Subroutine"->isdefined($caller, "new")B= $new
| |||||||||||||||||||||||||||||
| 176 | if Package::Subroutine->isdefined($caller,'new') && $new | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 30 | ▶ | ; $classes{$caller} = [] unless defined $classes{$caller} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 30 | ; push @{$classes{$caller}}, @$ac | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 30 | ; my @build = reverse Class::ISA::self_and_super_path($caller) | |||||||||||||||||||||||||||
| 182 | ; my @constructor | ||||||||||||||||||||||||||||
| 183 | 30 | ; my @class_accessors | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 30 | ; my $count=0 | |||||||||||||||||||||||||||
| 186 | 30 | ; foreach my $class (@build) | |||||||||||||||||||||||||||
| 187 | 34 | ▶ | { $classes{$class} or next | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 34 | ▶ | ; my @acc=@{$classes{$class}} or next | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 22 | ▶ | ; while (@acc) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 51 | { my ($accessor,$type)=splice(@acc,0,2) | |||||||||||||||||||||||||||
| 191 | 51 | ▶ | ; my $proto = ref($type) eq 'CODE' ? $type : $type{$type} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 51 | ▶ | ; unless(ref $proto eq 'CODE') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | { Carp::carp("Unknown property type '$type', in setup for class $caller.") | |||||||||||||||||||||||||||
| 194 | 0 | ▶ | ; $proto=sub{undef} | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 195 | 0 | } | |||||||||||||||||||||||||||
| 196 | 51 | ; my $val=$count | |||||||||||||||||||||||||||
| 197 | 100 | ▶ | ; my $acc=sub {$val} | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 198 | 51 | ; push @class_accessors, $accessor | |||||||||||||||||||||||||||
| 199 | 51 | ; $accessors{$caller}{$accessor}=$acc | |||||||||||||||||||||||||||
| 200 | 51 | ; $constructor[$acc->()] = $proto | |||||||||||||||||||||||||||
| 201 | 51 | ; $count++ | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | # FIXME: Die init Methode sollte Zugriff auf $self haben können. | ||||||||||||||||||||||||||||
| 205 | 13 | ; { no strict 'refs' | |||||||||||||||||||||||||||
| 206 | 13 | ▶ | ; if($new) | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 28 | { *{"${caller}::new"}= | |||||||||||||||||||||||||||
| 208 | ($init || $caller->can('init')) ? | ||||||||||||||||||||||||||||
| 209 | sub | ||||||||||||||||||||||||||||
| 210 | 10 | ▶ | { my ($self,@args)=@_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||
| 211 | 10 | ▶ | ; my $obj = bless [], ref $self || $self | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 212 | 10 | ; $object_builder->($obj,\@constructor,\@args) | |||||||||||||||||||||||||||
| 213 | 10 | ; return $obj->init(@args) | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | : sub | ||||||||||||||||||||||||||||
| 216 | 20 | ▶ | { my ($self,@args)=@_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 217 | 20 | ▶ | ; my $obj = bless [], ref $self || $self | ||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 218 | 20 | ; $object_builder->($obj,\@constructor,\@args) | |||||||||||||||||||||||||||
| 219 | 20 | ; return $obj | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | 28 | ▶ | } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$init or $caller->can("init")
MC/DC100%2/2
$init or $caller->can("init")
$init
$caller->can("init")
Truth table100%3/3
A or B
A= $initB= $caller->can("init")
| |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 30 | ; foreach my $acc (@class_accessors) | |||||||||||||||||||||||||||
| 224 | 51 | { *{"${caller}::${acc}"} = $accessors{$caller}{$acc} | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 30 | ; my %class_methods = @$methods | |||||||||||||||||||||||||||
| 228 | 30 | ; $methods{$caller} = \%class_methods | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | # setup init method | ||||||||||||||||||||||||||||
| 232 | 30 | ▶ | ; if($init) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 2 | ▶ | { unless(ref($init) eq 'CODE' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 2 | { $init = $init{$init} | |||||||||||||||||||||||||||
| 235 | 2 | ▶ | ; unless(defined $init) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 0 | { Carp::croak("There is no init defined for init argument $init.") | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | 13 | ; no strict 'refs' | |||||||||||||||||||||||||||
| 240 | 13 | ▶ | ; *{"${caller}::init"}= $init | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | # Package Method | ||||||||||||||||||||||||||||
| 245 | ; sub accessors_for_class | ||||||||||||||||||||||||||||
| 246 | 0 | ▶ | { my ($self,$class)=@_ | ||||||||||||||||||||||||||
|
Subroutine
accessors_for_class: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 247 | 0 | ; return $classes{$class} | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | # Package Function | ||||||||||||||||||||||||||||
| 251 | ; sub _value_of | ||||||||||||||||||||||||||||
| 252 | 32 | ▶ | { my ($class,$accessorname) = @_ | ||||||||||||||||||||||||||
|
Subroutine
_value_of: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 253 | 32 | ; return $accessors{$class}{$accessorname}->() | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | ; sub _methods_code | ||||||||||||||||||||||||||||
| 257 | 1 | ▶ | { my ($class,$methodname) = @_ | ||||||||||||||||||||||||||
|
Subroutine
_methods_code: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 258 | 1 | ; return $methods{$class}{$methodname} | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 13 | ; 1 | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | __END__ | ||||||||||||||||||||||||||||