| 1 | package exact::class; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Simple class interface extension for exact | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use exact; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use Import::Into; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use feature (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use Class::Method::Modifiers (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use Role::Tiny (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 9 | our $VERSION = '1.21'; # VERSION | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 9 | my $store; | |||||||||||||||||||||||||||
| 15 | 9 | my ($perl_version) = $^V =~ /^v5\.(\d+)/; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 29 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||
| 18 | 29 | my ( $self, $params, $caller ) = @_; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 29 | ▶ | if ($caller) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 26 | exact->late_parent; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||
| 24 | 3 | ▶ | $caller //= caller(); | ||||||||||||||||||||||||||
|
Condition33%1/3
$caller //= caller()
MC/DC0%0/2
$caller //= caller()
$caller
caller()
Truth table33%1/3
A //= B
A= $callerB= caller()
| |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | exact->add_isa( $self, $caller ) if ( $self eq 'exact::class' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 29 | $store->{struc}{$caller} = {}; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 29 | Class::Method::Modifiers->import::into($caller); | |||||||||||||||||||||||||||
| 31 | 29 | ▶ | feature->unimport('class') if ( $perl_version > 36 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 29 | exact->monkey_patch( $caller, $_, \&$_ ) for ( qw( has class_has with ) ); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub DESTROY {} | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 81 | ▶ | sub ____parents { | ||||||||||||||||||||||||||
|
Subroutine
____parents: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 81 | my ($namespace) = @_; | |||||||||||||||||||||||||||
| 40 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 81 | my @parents = @{ $namespace . '::ISA' }; | |||||||||||||||||||||||||||
| 42 | 81 | return @parents, map { ____parents($_) } @parents; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 107 | ▶ | sub ____install { | ||||||||||||||||||||||||||
|
Subroutine
____install: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 46 | 107 | my ( $self, $namespace, $input ) = @_; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 107 | ▶ | if ( ref $store->{struc}{$namespace} eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 68 | my @has_names = keys %{ $store->{struc}{$namespace}->{has} }; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 68 | for my $class_has_name ( | |||||||||||||||||||||||||||
| 52 | grep { | ||||||||||||||||||||||||||||
| 53 | 239 | my $name = $_; | |||||||||||||||||||||||||||
| 54 | 239 | not grep { $_ eq $name } @has_names; | |||||||||||||||||||||||||||
| 55 | 68 | } keys %{ $store->{struc}{$namespace}->{name} } | |||||||||||||||||||||||||||
| 56 | ) { | ||||||||||||||||||||||||||||
| 57 | 68 | ▶ | $self->$class_has_name( $input->{$class_has_name} ) if ( exists $input->{$class_has_name} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 68 | for my $has_name (@has_names) { | |||||||||||||||||||||||||||
| 61 | 171 | ▶ | if ( exists $input->{$has_name} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 62 | 10 | $self->attr( $has_name, $input->{$has_name} ); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | elsif ( exists $store->{struc}{$namespace}->{value}{$has_name} ) { | ||||||||||||||||||||||||||||
| 65 | 111 | $self->attr( $has_name, $store->{struc}{$namespace}->{value}{$has_name} ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||
| 68 | 50 | $self->attr($has_name); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 38 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 38 | my $class = shift; | |||||||||||||||||||||||||||
| 76 | 38 | ▶ | my $input = @_ ? @_ > 1 ? {@_} : { %{ $_[0] } } : {}; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 77 | 38 | ▶ | my $self = bless( { %$input }, 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
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 38 | for my $namespace ( reverse ( ref $self, ____parents( ref $self ) ) ) { | |||||||||||||||||||||||||||
| 80 | 81 | ▶ | if ( ref $store->{roles}{$namespace} eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 26 | for my $role ( @{ $store->{roles}->{$namespace} } ) { | |||||||||||||||||||||||||||
| 82 | 26 | ____install( $self, $role, $input ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 81 | ____install( $self, $namespace, $input ); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 38 | return $self; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 4 | ▶ | sub tap { | ||||||||||||||||||||||||||
|
Subroutine
tap: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 4 | my ( $self, $cb ) = ( shift, shift ); | |||||||||||||||||||||||||||
| 94 | 4 | $_->$cb(@_) for $self; | |||||||||||||||||||||||||||
| 95 | 4 | return $self; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 179 | ▶ | sub attr { | ||||||||||||||||||||||||||
|
Subroutine
attr: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 179 | my ( $self, $attrs, $value ) = @_; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 179 | ▶ | my $set = { | ||||||||||||||||||||||||||
|
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
| |||||||||||||||||||||||||||||
| 102 | attrs => $attrs, | ||||||||||||||||||||||||||||
| 103 | caller => ref($self) || $self, | ||||||||||||||||||||||||||||
| 104 | set_has => 1, | ||||||||||||||||||||||||||||
| 105 | self => $self, | ||||||||||||||||||||||||||||
| 106 | obj_accessor => 1, | ||||||||||||||||||||||||||||
| 107 | }; | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 179 | ▶ | $set->{value} = $value if ( @_ > 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 179 | return ____attrs($set); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 12 | ▶ | sub class_has { | ||||||||||||||||||||||||||
|
Subroutine
class_has: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 114 | 12 | my ( $attrs, $value ) = @_; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 12 | my $set = { | |||||||||||||||||||||||||||
| 117 | attrs => $attrs, | ||||||||||||||||||||||||||||
| 118 | caller => scalar( caller() ), | ||||||||||||||||||||||||||||
| 119 | }; | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 12 | ▶ | $set->{value} = $value if ( @_ > 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 12 | ____attrs($set); | |||||||||||||||||||||||||||
| 123 | 12 | return; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 45 | ▶ | sub has { | ||||||||||||||||||||||||||
|
Subroutine
has: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 45 | my ( $attrs, $value ) = @_; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 45 | my $set = { | |||||||||||||||||||||||||||
| 130 | attrs => $attrs, | ||||||||||||||||||||||||||||
| 131 | caller => scalar( caller() ), | ||||||||||||||||||||||||||||
| 132 | set_has => 1, | ||||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 45 | ▶ | $set->{value} = $value if ( @_ > 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 45 | ____attrs($set); | |||||||||||||||||||||||||||
| 137 | 45 | return; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 265 | ▶ | sub ____attrs { | ||||||||||||||||||||||||||
|
Subroutine
____attrs: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||
| 141 | 265 | for my $set (@_) { | |||||||||||||||||||||||||||
| 142 | 265 | ▶ | for my $name ( ( ref $set->{attrs} ) ? @{ $set->{attrs} } : $set->{attrs} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | my $accessor = ( $set->{obj_accessor} ) | ||||||||||||||||||||||||||||
| 144 | 264 | ▶ | ? sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 145 | 264 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 264 | ▶ | if ( @_ > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 151 | $self->{$name} = $value; | |||||||||||||||||||||||||||
| 149 | 151 | return $self; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | else { | ||||||||||||||||||||||||||||
| 152 | 4 | return ${ $self->{$name} } if ( | |||||||||||||||||||||||||||
| 153 | ref $self->{$name} eq 'REF' and | ||||||||||||||||||||||||||||
| 154 | 113 | ▶ | ref ${ $self->{$name} } eq 'CODE' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $self->{$name} eq "REF" and ref ${$self->{$name};} eq "CODE"
MC/DC50%1/2
ref $self->{$name} eq "REF" and ref ${$self->{$name};} eq "CODE"
ref $self->{$name} eq "REF"
ref ${$self->{$name};} eq "CODE"
Truth table66%2/3
A and B
A= ref $self->{$name} eq "REF"B= ref ${$self->{$name};} eq "CODE"
| |||||||||||||||||||||||||||||
| 155 | ); | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 109 | ▶ | $self->{$name} = $self->{$name}->($self) if ( ref $self->{$name} eq 'CODE' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 109 | return $self->{$name}; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | 85 | ▶ | : sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.8
| |||||||||||||||||||||||||||||
| 162 | 85 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 85 | ▶ | if ( @_ > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 16 | $store->{struc}{ $set->{caller} }->{value}{$name} = $value; | |||||||||||||||||||||||||||
| 166 | 16 | return $self; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | else { | ||||||||||||||||||||||||||||
| 169 | 0 | return ${ $store->{struc}{ $set->{caller} }->{value}{$name} } if ( | |||||||||||||||||||||||||||
| 170 | ref $store->{struc}{ $set->{caller} }->{value}{$name} eq 'REF' and | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | ref ${ $store->{struc}{ $set->{caller} }->{value}{$name} } eq 'CODE' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $store->{"struc"}{$set->{"caller"}}{"value"}{$name} eq "REF" and ref ${$store->{"struc"}{$set->{"caller"}}{"value"}{$name};} eq "CODE"
MC/DC0%0/2
ref $store->{"struc"}{$set->{"caller"}}{"value"}{$name} eq "REF" and ref ${$store->{"struc"}{$set->{"caller"}}{"value"}{$name};} eq "CODE"
ref $store->{"struc"}{$set->{"caller"}}{"value"}{$name} eq "REF"
ref ${$store->{"struc"}{$set->{"caller"}}{"value"}{$name};} eq "CODE"
Truth table33%1/3
A and B
A= ref $store->{"struc"}{$set->{"caller"}}{"value"}{$name} eq "REF"B= ref ${$store->{"struc"}{$set->{"caller"}}{"value"}{$name};} eq "CODE"
| |||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | $store->{struc}{ $set->{caller} }->{value}{$name} = | ||||||||||||||||||||||||||||
| 175 | $store->{struc}{ $set->{caller} }->{value}{$name}->($self) | ||||||||||||||||||||||||||||
| 176 | 69 | ▶ | if ( ref $store->{struc}{ $set->{caller} }->{value}{$name} eq 'CODE' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 69 | return $store->{struc}{ $set->{caller} }->{value}{$name}; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | 277 | ▶ | }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | { | ||||||||||||||||||||||||||||
| 182 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 183 | 9 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 184 | 277 | *{ $set->{caller} . '::' . $name } = $accessor; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 277 | ▶ | if ( ref $set->{self} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 179 | ▶ | $set->{self}->$name( $set->{value} ) if ( exists $set->{value} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | else { | ||||||||||||||||||||||||||||
| 191 | 98 | ▶ | $store->{struc}{ $set->{caller} }->{has}{$name} = 1 if ( $set->{set_has} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 98 | $store->{struc}{ $set->{caller} }->{name}{$name} = 1; | |||||||||||||||||||||||||||
| 193 | 98 | ▶ | $store->{struc}{ $set->{caller} }->{value}{$name} = $set->{value} if ( exists $set->{value} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 265 | return; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 16 | ▶ | sub ____role_attrs { | ||||||||||||||||||||||||||
|
Subroutine
____role_attrs: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 202 | 16 | my ( $caller, $roles, $object ) = @_; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 16 | for my $role (@$roles) { | |||||||||||||||||||||||||||
| 205 | 21 | for my $name ( | |||||||||||||||||||||||||||
| 206 | 21 | keys %{ $store->{struc}{$role}{name} } | |||||||||||||||||||||||||||
| 207 | ) { | ||||||||||||||||||||||||||||
| 208 | 29 | my $set = { | |||||||||||||||||||||||||||
| 209 | attrs => $name, | ||||||||||||||||||||||||||||
| 210 | caller => $caller, | ||||||||||||||||||||||||||||
| 211 | }; | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 29 | ▶ | if ( $store->{struc}{$role}{has}{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 18 | $set->{self} = $object; | |||||||||||||||||||||||||||
| 215 | 18 | $set->{obj_accessor} = 1; | |||||||||||||||||||||||||||
| 216 | 18 | $set->{set_has} = 1; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | $set->{value} = $store->{struc}{$role}{value}{$name} | ||||||||||||||||||||||||||||
| 220 | 29 | ▶ | if ( exists $store->{struc}{$role}{value}{$name} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 29 | ____attrs($set); | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 16 | return; | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 11 | ▶ | sub with { | ||||||||||||||||||||||||||
|
Subroutine
with: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 230 | 11 | my $caller = scalar(caller); | |||||||||||||||||||||||||||
| 231 | 11 | push( @{ $store->{roles}->{$caller} }, @_ ); | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 11 | try { | |||||||||||||||||||||||||||
| 234 | 11 | Role::Tiny->apply_roles_to_package( $caller, $_ ) for @_; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | catch ($e) { | ||||||||||||||||||||||||||||
| 237 | 0 | $e =~ s/\s+at\s.+\sline\s\d+\.\s*$//g; | |||||||||||||||||||||||||||
| 238 | 0 | croak $e; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 11 | ____role_attrs( $caller, [@_] ); | |||||||||||||||||||||||||||
| 242 | 11 | return; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 5 | ▶ | sub with_roles { | ||||||||||||||||||||||||||
|
Subroutine
with_roles: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||
| 246 | 5 | my ( $self, @roles ) = @_; | |||||||||||||||||||||||||||
| 247 | 5 | my $object; | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 5 | ▶ | unless ( my $class = Scalar::Util::blessed($self) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | $object = Role::Tiny->create_class_with_roles( | ||||||||||||||||||||||||||||
| 251 | $self, | ||||||||||||||||||||||||||||
| 252 | 1 | ▶ | map { /^\+(.+)$/ ? "${self}::Role::$1" : $_ } @roles | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | ); | ||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | else { | ||||||||||||||||||||||||||||
| 256 | $object = Role::Tiny->apply_roles_to_object( | ||||||||||||||||||||||||||||
| 257 | $self, | ||||||||||||||||||||||||||||
| 258 | 4 | ▶ | map { /^\+(.+)$/ ? "${class}::Role::$1" : $_ } @roles | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | ); | ||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 5 | ▶ | ____role_attrs( Scalar::Util::blessed($object) || $object, [@_], $object ); | ||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($object) || $object
MC/DC0%0/2
builtin::blessed($object) || $object
builtin::blessed($object)
$object
Truth table66%2/3
A || B
A= builtin::blessed($object)B= $object
| |||||||||||||||||||||||||||||
| 263 | 5 | return $object; | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 9 | 1; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | __END__ | ||||||||||||||||||||||||||||