Throttler/algo.pm

filter: Statementstmt 93.6% 59 / 63 Branchbran 65.6% 21 / 32 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 94.1% 16 / 17 Podpod 100% 3 / 3 totaltotal 79.8% 103 / 129 CC 20 SCAR 16.4
CC
20
Cov
81%
__ANON__
12.0
__ANON__
9.7
apply_to_methods
7.3
CRAP 5.1
« Throttler/Periodic/EV.pm ↑ Summary Throttler/Limit.pm »
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
BranchTrueFalseTotal
/::/ms ? : 0 2 2
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
BranchTrueFalseTotal
$this ? : 4 7 11
@func ? : 4 3 7
32 : DEFAULT_KEY
33 ;
34 11 ▶ return $key ? {$key=>1} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$key ? : 7 4 11
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
BranchTrueFalseTotal
if ref $class_or_obj and not builtin::blessed($class_or_obj) 0 7 7
Condition66%2/3
ref $class_or_obj and not builtin::blessed($class_or_obj)
!ll&&!rl&&r
340
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)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if &any(sub { /::/ms; } , @func) 0 7 7
44 7 my %func = map { $_ => DEFAULT_KEY } @func;
45 7 ▶ if (1 == @_) {
Branch: 2 branches
BranchTrueFalseTotal
if (1 == @_) { } 0 7 7
elsif (ref $class_or_obj) { } 4 3 7
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
BranchTrueFalseTotal
$this ? : 0 0 0
49 0 ▶ return $key ? {$key=>1} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$key ? : 0 0 0
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
BranchTrueFalseTotal
!($this && ref $this) || $this != $obj ? : 0 4 4
@func ? : 4 0 4
Condition33%2/6
not $this && ref $this or $this != $obj
l!l&&r!l&&!r
004
$this && ref $this
!ll&&!rl&&r
004
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
ABCresult
0XX1
10X1
1111
1100
58 : DEFAULT_KEY
59 ;
60 4 ▶ return $key ? {$key=>1} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$key ? : 4 0 4
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
BranchTrueFalseTotal
@func ? : 4 16 20
68 23 ▶ : @func ? $func{$name}
Branch: 1 branch
BranchTrueFalseTotal
!eval { do { local $SIG{'__DIE__'}; $this->isa($class) } } ? : 3 20 23
69 : DEFAULT_KEY
70 ;
71 23 ▶ return $key ? {$key=>1} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$key ? : 20 3 23
72 3 });
73 }
74 7 return $self;
75 }
76  
77  
78 8 1; # Magic true value required at end of module
79 __END__
« Throttler/Periodic/EV.pm ↑ Summary Throttler/Limit.pm »