| 1 | package CHI::Cascade::Rule; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 26 | ▶ | my ($class, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 26 | ▶ | my $from = ref($class) ? $class : \%opts; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | $opts{depends} = [ defined( $opts{depends} ) ? ( $opts{depends} ) : () ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 26 | ▶ | unless ref( $opts{depends} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # To do clone or new object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 130 | map( { $_ => $from->{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 26 | ▶ | grep { exists $from->{$_} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | qw( target depends depends_catch code params busy_lock cascade recomputed actual_term ttl value_expires ) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | qr_params => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | matched_target => undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | }, ref($class) || $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 26 | ▶ | if ( $opts{run_instance} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 23 | $self->{run_instance} = $opts{run_instance}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 23 | weaken $self->{run_instance}; # It is against memory leaks | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 26 | weaken $self->{cascade}; # It is against memory leaks | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 26 | $self->{resolved_depends} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 26 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | sub qr_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 40 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
qr_params: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 40 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 11 | $self->{qr_params} = [ @_ ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 29 | return @{ $self->{qr_params} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | sub depends { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 20 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
depends: called CC=6 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | return $self->{resolved_depends} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 20 | ▶ | if $self->{resolved_depends}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 20 | ▶ | if ( ref( $self->{depends} ) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $res = $self->{depends}->( $self, $self->qr_params ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $self->{resolved_depends} = ref($res) eq 'ARRAY' ? [ @$res ] : [ $res ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 20 | $self->{resolved_depends} = [ @{ $self->{depends} } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 20 | for ( @{ $self->{resolved_depends} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 11 | ▶ | $_ = $_->( $self, $self->qr_params ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | if ( ref eq 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 20 | $self->{resolved_depends}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | sub value_expires { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value_expires: called CC=4 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 10 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->{value_expires} = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 10 | ▶ | ( ref $self->{value_expires} eq 'CODE' ? $self->{value_expires}->( $self ) : $self->{value_expires} ) // 'never'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
(ref $self->{"value_expires"} eq "CODE" ? $self->{"value_expires"}->($self) : $self->{"value_expires"}) // "never"
MC/DC0%0/1
(ref $self->{"value_expires"} eq "CODE" ? $self->{"value_expires"}->($self) : $self->{"value_expires"}) // "never"
(ref $self->{"value_expires"} eq "CODE" ? $self->{"value_expires"}->($self) : $self->{"value_expires"})
Truth table50%1/2
A
A= (ref $self->{"value_expires"} eq "CODE" ? $self->{"value_expires"}->($self) : $self->{"value_expires"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | sub target_expires { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 18 | ▶ | my ( $self, $trg_obj ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
target_expires: called CC=5 SCAR=19.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | $trg_obj->locked | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 18 | ▶ | $self->{busy_lock} || $self->{cascade}{busy_lock} || 'never' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition37%3/8
$self->{"busy_lock"} or $self->{"cascade"}{"busy_lock"} or "never"
$self->{"busy_lock"} or $self->{"cascade"}{"busy_lock"}
$trg_obj->expires // $trg_obj->expires($self->value_expires)
MC/DC0%0/2
$self->{"busy_lock"} or $self->{"cascade"}{"busy_lock"} or "never"
$self->{"busy_lock"}
$self->{"cascade"}{"busy_lock"}
MC/DC0%0/2
$trg_obj->expires // $trg_obj->expires($self->value_expires)
$trg_obj->expires
$trg_obj->expires($self->value_expires)
Truth table33%1/3
A or B
A= $self->{"busy_lock"}B= $self->{"cascade"}{"busy_lock"}
Truth table33%1/3
A // B
A= $trg_obj->expiresB= $trg_obj->expires($self->value_expires)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | $trg_obj->expires // $trg_obj->expires( $self->value_expires ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | sub ttl { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 20 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ttl: called CC=6 SCAR=33.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | return undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 20 | ▶ | unless exists $self->{ttl}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $self->{ttl_time} && return $self->{ttl_time}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( ref $self->{ttl} eq 'ARRAY' && @{ $self->{ttl} } == 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $self->{"ttl"} eq "ARRAY" and @{$self->{"ttl"};} == 2
MC/DC0%0/2
ref $self->{"ttl"} eq "ARRAY" and @{$self->{"ttl"};} == 2
ref $self->{"ttl"} eq "ARRAY"
@{$self->{"ttl"};} == 2
Truth table0%0/3
A and B
A= ref $self->{"ttl"} eq "ARRAY"B= @{$self->{"ttl"};} == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | return $self->{ttl_time} = rand( $self->{ttl}[1] - $self->{ttl}[0] ) + $self->{ttl}[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | elsif ( ref $self->{ttl} eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return $self->{ttl_time} = $self->{ttl}->( $self, $self->qr_params ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 115 | ▶ | sub target { shift->{matched_target} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
target: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub params { shift->{params} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
params: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub cascade { shift->{cascade} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cascade: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 5 | ▶ | sub dep_values { shift->{dep_values} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dep_values: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub stash { shift->{run_instance}{stash} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stash: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||