line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
614
|
use strict; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
28
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
3
|
|
|
|
|
|
|
package Test::Ratchet; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
838
|
use Exporter::Easy ( OK => [ qw/ratchet clank/ ] ); |
|
1
|
|
|
|
|
1522
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
644
|
use Data::Munge qw(rec); |
|
1
|
|
|
|
|
1604
|
|
|
1
|
|
|
|
|
72
|
|
7
|
1
|
|
|
1
|
|
7
|
use Scalar::Util qw(refaddr); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
430
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: Mocking helper that swaps out implementations automatically |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub ratchet { |
15
|
1
|
|
|
1
|
1
|
104
|
my @subrefs = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $ratchet = rec { |
18
|
11
|
|
|
11
|
|
8557
|
my $recurse = shift; |
19
|
11
|
50
|
|
|
|
32
|
if (! @subrefs) { |
20
|
0
|
|
|
|
|
0
|
die "Tried to run a ratchet but there was nothing left to do!"; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
11
|
|
|
|
|
18
|
my $now = $subrefs[0]; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# simple scalar should be a number. Run the next item as a subref if |
26
|
|
|
|
|
|
|
# that number is not 0. If it's reached 0, shift them both off and redo. |
27
|
|
|
|
|
|
|
# Or it's an asterisk, in which case do the next subref forever. |
28
|
11
|
100
|
|
|
|
27
|
if (not ref $now) { |
29
|
9
|
100
|
|
|
|
23
|
if ($now eq '*') { |
30
|
5
|
|
|
|
|
19
|
return $subrefs[1]->(@_); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
4
|
100
|
|
|
|
11
|
if ($now > 0) { |
34
|
3
|
|
|
|
|
6
|
$now = $subrefs[1]; |
35
|
3
|
|
|
|
|
4
|
$subrefs[0]--; |
36
|
3
|
|
|
|
|
17
|
return $now->(@_); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
1
|
|
|
|
|
3
|
shift @subrefs; shift @subrefs; |
|
1
|
|
|
|
|
2
|
|
40
|
|
|
|
|
|
|
# redo |
41
|
1
|
|
|
|
|
5
|
return $recurse->(@_); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
else { |
46
|
2
|
|
|
|
|
3
|
shift @subrefs; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
12
|
$now->(@_); |
50
|
1
|
|
|
|
|
11
|
}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub clank($) { |
55
|
0
|
|
|
0
|
1
|
|
my $subref = shift; |
56
|
0
|
|
|
0
|
|
|
my $clank = rec { my $rec = shift; $Test::Ratchet::Clank::CLANK{ refaddr $rec } = 1; &$subref }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
bless $clank, "Test::Ratchet::Clank"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
package Test::Ratchet::Clank; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
1
|
|
7
|
use Scalar::Util qw(refaddr); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
120
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
our %CLANK; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub DESTROY { |
67
|
0
|
|
|
0
|
|
|
my $self = shift; |
68
|
0
|
|
|
|
|
|
require Test::More; |
69
|
0
|
0
|
|
|
|
|
Test::More::fail("A Clank was never run!") unless $CLANK{ refaddr $self }; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |