line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
525
|
use strict; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
24
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
3
|
|
|
|
|
|
|
package Test::Ratchet; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
441
|
use Exporter::Easy ( EXPORT => [ qw/ratchet/ ] ); |
|
1
|
|
|
|
|
1316
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
515
|
use Data::Munge qw(rec); |
|
1
|
|
|
|
|
1366
|
|
|
1
|
|
|
|
|
202
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Mocking helper that swaps out implementations automatically |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub ratchet { |
14
|
1
|
|
|
1
|
1
|
76
|
my @subrefs = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $ratchet = rec { |
17
|
18
|
|
|
18
|
|
9813
|
my $recurse = shift; |
18
|
18
|
50
|
|
|
|
41
|
if (! @subrefs) { |
19
|
0
|
|
|
|
|
0
|
die "Tried to run a ratchet but there was nothing left to do!"; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
18
|
|
|
|
|
24
|
my $now = $subrefs[0]; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# simple scalar should be a number. Run the next item as a subref if |
25
|
|
|
|
|
|
|
# that number is not 0. If it's reached 0, shift them both off and redo. |
26
|
|
|
|
|
|
|
# Or it's an asterisk, in which case do the next subref forever. |
27
|
18
|
100
|
|
|
|
34
|
if (not ref $now) { |
28
|
16
|
100
|
|
|
|
29
|
if ($now eq '*') { |
29
|
12
|
|
|
|
|
23
|
return $subrefs[1]->(@_); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
4
|
100
|
|
|
|
8
|
if ($now > 0) { |
33
|
3
|
|
|
|
|
6
|
$now = $subrefs[1]; |
34
|
3
|
|
|
|
|
3
|
$subrefs[0]--; |
35
|
3
|
|
|
|
|
7
|
return $now->(@_); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
1
|
|
|
|
|
2
|
shift @subrefs; shift @subrefs; |
|
1
|
|
|
|
|
2
|
|
39
|
|
|
|
|
|
|
# redo |
40
|
1
|
|
|
|
|
5
|
return $recurse->(@_); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
else { |
45
|
2
|
|
|
|
|
2
|
shift @subrefs; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
5
|
$now->(@_); |
49
|
1
|
|
|
|
|
6
|
}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |