line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sub::Throttler::algo; |
2
|
8
|
|
|
8
|
|
3450
|
use 5.010001; |
|
8
|
|
|
|
|
22
|
|
3
|
8
|
|
|
8
|
|
30
|
use warnings; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
173
|
|
4
|
8
|
|
|
8
|
|
27
|
use strict; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
126
|
|
5
|
8
|
|
|
8
|
|
62
|
use utf8; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
38
|
|
6
|
8
|
|
|
8
|
|
135
|
use Carp; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
677
|
|
7
|
|
|
|
|
|
|
our @CARP_NOT = qw( Sub::Throttler ); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 'v0.2.10'; |
10
|
|
|
|
|
|
|
|
11
|
8
|
|
|
8
|
|
33
|
use Scalar::Util qw( blessed ); |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
1087
|
|
12
|
8
|
|
|
8
|
|
34
|
use List::Util qw( any ); |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
500
|
|
13
|
8
|
|
|
8
|
|
2290
|
use Sub::Throttler qw( throttle_add ); |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
43
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
8
|
|
|
8
|
|
8603
|
use constant DEFAULT_KEY => 'default'; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
3708
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub apply_to { |
20
|
44
|
|
|
44
|
1
|
10098
|
goto &throttle_add; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub apply_to_functions { |
24
|
3
|
|
|
3
|
1
|
31
|
my ($self, @func) = @_; |
25
|
2
|
|
|
|
|
52
|
my %func = map { $_ => DEFAULT_KEY } |
26
|
3
|
50
|
|
|
|
12
|
map {/::/ms ? $_ : caller().q{::}.$_} @func; |
|
2
|
|
|
|
|
18
|
|
27
|
|
|
|
|
|
|
$self->apply_to(sub { |
28
|
11
|
|
|
11
|
|
15
|
my ($this, $name) = @_; |
29
|
|
|
|
|
|
|
my $key |
30
|
|
|
|
|
|
|
= $this ? undef |
31
|
11
|
100
|
|
|
|
50
|
: @func ? $func{$name} |
|
|
100
|
|
|
|
|
|
32
|
|
|
|
|
|
|
: DEFAULT_KEY |
33
|
|
|
|
|
|
|
; |
34
|
11
|
100
|
|
|
|
41
|
return $key ? {$key=>1} : undef; |
35
|
3
|
|
|
|
|
32
|
}); |
36
|
3
|
|
|
|
|
22
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub apply_to_methods { |
40
|
7
|
|
|
7
|
1
|
14
|
my ($self, $class_or_obj, @func) = @_; |
41
|
7
|
50
|
66
|
|
|
41
|
croak 'require class or object' |
42
|
|
|
|
|
|
|
if ref $class_or_obj && !blessed($class_or_obj); |
43
|
7
|
50
|
|
6
|
|
81
|
croak 'method must not contain ::' if any {/::/ms} @func; |
|
6
|
|
|
|
|
53
|
|
44
|
7
|
|
|
|
|
24
|
my %func = map { $_ => DEFAULT_KEY } @func; |
|
6
|
|
|
|
|
24
|
|
45
|
7
|
50
|
|
|
|
35
|
if (1 == @_) { |
|
|
100
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->apply_to(sub { |
47
|
0
|
|
|
0
|
|
0
|
my ($this) = @_; |
48
|
0
|
0
|
|
|
|
0
|
my $key = $this ? DEFAULT_KEY : undef; |
49
|
0
|
0
|
|
|
|
0
|
return $key ? {$key=>1} : undef; |
50
|
0
|
|
|
|
|
0
|
}); |
51
|
|
|
|
|
|
|
} elsif (ref $class_or_obj) { |
52
|
4
|
|
|
|
|
3
|
my $obj = $class_or_obj; |
53
|
|
|
|
|
|
|
$self->apply_to(sub { |
54
|
4
|
|
|
4
|
|
6
|
my ($this, $name) = @_; |
55
|
|
|
|
|
|
|
my $key |
56
|
|
|
|
|
|
|
= !$this || !ref $this || $this != $obj ? undef |
57
|
4
|
50
|
33
|
|
|
48
|
: @func ? $func{$name} |
|
|
50
|
|
|
|
|
|
58
|
|
|
|
|
|
|
: DEFAULT_KEY |
59
|
|
|
|
|
|
|
; |
60
|
4
|
50
|
|
|
|
17
|
return $key ? {$key=>1} : undef; |
61
|
4
|
|
|
|
|
16
|
}); |
62
|
|
|
|
|
|
|
} else { |
63
|
3
|
|
|
|
|
8
|
my $class = $class_or_obj; |
64
|
|
|
|
|
|
|
$self->apply_to(sub { |
65
|
23
|
|
|
23
|
|
41
|
my ($this, $name) = @_; |
66
|
|
|
|
|
|
|
my $key |
67
|
23
|
|
|
|
|
98
|
= !eval {local $SIG{__DIE__}; $this->isa($class)} ? undef |
|
23
|
|
|
|
|
208
|
|
68
|
23
|
100
|
|
|
|
38
|
: @func ? $func{$name} |
|
|
100
|
|
|
|
|
|
69
|
|
|
|
|
|
|
: DEFAULT_KEY |
70
|
|
|
|
|
|
|
; |
71
|
23
|
100
|
|
|
|
105
|
return $key ? {$key=>1} : undef; |
72
|
3
|
|
|
|
|
29
|
}); |
73
|
|
|
|
|
|
|
} |
74
|
7
|
|
|
|
|
19
|
return $self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
79
|
|
|
|
|
|
|
__END__ |