| 1 | package HO::mixin; | ||||||||||||||||||||||||||||||||||
| 2 | # ****************** | ||||||||||||||||||||||||||||||||||
| 3 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||
| 4 | # ******************** | ||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | ; use strict; use warnings | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | ; use Carp () | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | ; use Package::Subroutine () | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | ; use Data::Dumper | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | ; our $class | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | ; sub import | ||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | { my ($self, $mixin, @args) = @_ | ||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=15 SCAR=29.8
| |||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | ; my $class = $HO::mixin::class || CORE::caller | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$HO::mixin::class || caller
MC/DC0%0/2
$HO::mixin::class || caller
$HO::mixin::class
caller
Truth table33%1/3
A || B
A= $HO::mixin::classB= caller
| |||||||||||||||||||||||||||||||||||
| 16 | 3 | ; my ($without,$only) | |||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | ; while(@args) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 18 | 1 | { my $arg = shift @args | |||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | ; if( $arg eq 'without' ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 20 | 1 | { my %skip = map { $_ => 1 } @{shift(@args)} | |||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | ; $without = sub { !$skip{$_[0]} } | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 22 | 1 | } | |||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | ; if( $arg eq 'only' ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 24 | 0 | { my %only = map { $_ => 1 } @{shift(@args)} | |||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | ; $only = sub { $only{$_[0]} } | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 26 | 0 | } | |||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | ; unless (defined $mixin) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 29 | 0 | { Carp::croak("Which class do you want to mix into ${self}?") | |||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | ; if($only && $without) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$only and $without
MC/DC0%0/2
$only and $without
$only
$without
Truth table33%1/3
A and B
A= $onlyB= $without
| |||||||||||||||||||||||||||||||||||
| 32 | 0 | { Carp::croak "Option 'without' and 'only' can't be used together in mixin $class." | |||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||
| 34 | 3 | ; eval "require $mixin" | |||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | ; if($HO::class::class_args{$mixin}) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 37 | { $HO::class::mixin_classes{$class} = [] unless | ||||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | defined $HO::class::mixin_classes{$class} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 39 | 3 | ; push @{$HO::class::mixin_classes{$class}}, @{$HO::class::class_args{$mixin}} | |||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | ; my $filter = $only || $without || sub { 1 } | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 3 | ▶ | ; $HO::accessor::classes{$class} = [] unless | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
$only || $without || sub {
1;
}
$only or $without
MC/DC0%0/3
$only || $without || sub {
1;
}
$only
$without
sub {
1;
}
Truth table50%2/4
A or B || C
A= $onlyB= $withoutC= sub {
1;
}
| |||||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | defined $HO::accessor::classes{$class} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | 3 | ; my $mix = $HO::accessor::classes{$mixin} | |||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | ; $mix = [] unless ref $mix | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 47 | 3 | ; push @{$HO::accessor::classes{$class}}, @$mix | |||||||||||||||||||||||||||||||||
| 48 | 3 | ; my %acc = @$mix | |||||||||||||||||||||||||||||||||
| 49 | ; my @methods = | ||||||||||||||||||||||||||||||||||
| 50 | 4 | grep { $filter->($_) } | |||||||||||||||||||||||||||||||||
| 51 | 11 | ▶ | grep { !(/^(init|new)$/ || defined($acc{$_})) } | ||||||||||||||||||||||||||||||||
|
Condition100%3/3
/^(init|new)$/ || defined $acc{$_}
MC/DC100%2/2
/^(init|new)$/ || defined $acc{$_}
/^(init|new)$/
defined $acc{$_}
Truth table100%3/3
A || B
A= /^(init|new)$/B= defined $acc{$_}
| |||||||||||||||||||||||||||||||||||
| 52 | 3 | grep { ! $HO::class::class_methods{$mixin}{$_} } | |||||||||||||||||||||||||||||||||
| 53 | Package::Subroutine->findsubs( $mixin ) | ||||||||||||||||||||||||||||||||||
| 54 | 3 | ; Package::Subroutine->export_to($class)->($mixin,@methods) | |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 1 | ; 1 | |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||||||||||||||||