| 1 | package Sub::Throttler::algo; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | our @CARP_NOT = qw( Sub::Throttler ); | |||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | our $VERSION = 'v0.2.10'; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use List::Util qw( any ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use Sub::Throttler qw( throttle_add ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use constant DEFAULT_KEY => 'default'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 44 | ▶ | sub apply_to { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 44 | goto &throttle_add; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | sub apply_to_functions { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_to_functions: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | my ($self, @func) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | my %func = map { $_ => DEFAULT_KEY } | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | map {/::/ms ? $_ : caller().q{::}.$_} @func; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 11 | ▶ | $self->apply_to(sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 11 | my ($this, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | my $key | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | = $this ? undef | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 11 | ▶ | : @func ? $func{$name} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | : DEFAULT_KEY | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 11 | ▶ | return $key ? {$key=>1} : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | ▶ | sub apply_to_methods { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_to_methods: called CC=6 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 7 | my ($self, $class_or_obj, @func) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 7 | ▶ | croak 'require class or object' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $class_or_obj and not builtin::blessed($class_or_obj)
MC/DC0%0/2
ref $class_or_obj and not builtin::blessed($class_or_obj)
ref $class_or_obj
not builtin::blessed($class_or_obj)
Truth table66%2/3
A and not(B)
A= ref $class_or_objB= not builtin::blessed($class_or_obj)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | if ref $class_or_obj && !blessed($class_or_obj); | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 7 | ▶ | croak 'method must not contain ::' if any {/::/ms} @func; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 7 | my %func = map { $_ => DEFAULT_KEY } @func; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | ▶ | if (1 == @_) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $self->apply_to(sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ($this) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $key = $this ? DEFAULT_KEY : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return $key ? {$key=>1} : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } elsif (ref $class_or_obj) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | my $obj = $class_or_obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | $self->apply_to(sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=22.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | my ($this, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | my $key | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | = !$this || !ref $this || $this != $obj ? undef | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | : @func ? $func{$name} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
not $this && ref $this or $this != $obj
$this && ref $this
MC/DC0%0/3
not $this && ref $this or $this != $obj
$this
ref $this
$this != $obj
Truth table25%1/4
not(A && B) or C
A= $thisB= ref $thisC= $this != $obj
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | : DEFAULT_KEY | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | ▶ | return $key ? {$key=>1} : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | my $class = $class_or_obj; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 23 | ▶ | $self->apply_to(sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 23 | my ($this, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | my $key | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 23 | ▶ | = !eval {local $SIG{__DIE__}; $this->isa($class)} ? undef | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 23 | ▶ | : @func ? $func{$name} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | : DEFAULT_KEY | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 23 | ▶ | return $key ? {$key=>1} : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 8 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||