| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Stub::Generator; |
|
2
|
12
|
|
|
12
|
|
352161
|
use 5.008005; |
|
|
12
|
|
|
|
|
52
|
|
|
|
12
|
|
|
|
|
528
|
|
|
3
|
12
|
|
|
12
|
|
70
|
use strict; |
|
|
12
|
|
|
|
|
19
|
|
|
|
12
|
|
|
|
|
464
|
|
|
4
|
12
|
|
|
12
|
|
74
|
use warnings; |
|
|
12
|
|
|
|
|
21
|
|
|
|
12
|
|
|
|
|
387
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
12
|
|
|
12
|
|
58
|
use Test::More; |
|
|
12
|
|
|
|
|
24
|
|
|
|
12
|
|
|
|
|
80
|
|
|
7
|
12
|
|
|
12
|
|
15179
|
use Test::Deep; |
|
|
12
|
|
|
|
|
140292
|
|
|
|
12
|
|
|
|
|
3113
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
12
|
|
|
12
|
|
105
|
use Exporter qw(import); |
|
|
12
|
|
|
|
|
29
|
|
|
|
12
|
|
|
|
|
429
|
|
|
10
|
12
|
|
|
12
|
|
68
|
use Carp qw(croak); |
|
|
12
|
|
|
|
|
21
|
|
|
|
12
|
|
|
|
|
599
|
|
|
11
|
12
|
|
|
12
|
|
11157
|
use Class::Monadic; |
|
|
12
|
|
|
|
|
291295
|
|
|
|
12
|
|
|
|
|
1010
|
|
|
12
|
12
|
|
|
12
|
|
113
|
use Data::Util qw(is_array_ref is_code_ref); |
|
|
12
|
|
|
|
|
30
|
|
|
|
12
|
|
|
|
|
9983
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
|
15
|
|
|
|
|
|
|
our @EXPORT = qw(make_subroutine make_method); |
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
|
17
|
|
|
|
|
|
|
make_subroutine_utils |
|
18
|
|
|
|
|
|
|
make_method_utils |
|
19
|
|
|
|
|
|
|
make_repeat_subroutine |
|
20
|
|
|
|
|
|
|
make_repeat_method |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub make_subroutine { |
|
24
|
8
|
|
|
8
|
1
|
525224
|
my (@args) = @_; |
|
25
|
8
|
|
|
|
|
50
|
return _convert_build( [@args], is_object => 0 ); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub make_subroutine_utils { |
|
29
|
0
|
|
|
0
|
0
|
0
|
my (@args) = @_; |
|
30
|
0
|
|
|
|
|
0
|
return _convert_build( [@args], is_object => 0, want_utils => 1 ); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub make_repeat_subroutine { |
|
34
|
1
|
|
|
1
|
0
|
2054
|
my (@args) = @_; |
|
35
|
1
|
|
|
|
|
7
|
return _convert_build( [@args], is_object => 0, is_repeat => 1 ); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub make_method { |
|
39
|
2
|
|
|
2
|
1
|
7980
|
my (@args) = @_; |
|
40
|
2
|
|
|
|
|
11
|
return _convert_build( [@args], is_object => 1 ); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub make_method_utils { |
|
44
|
4
|
|
|
4
|
0
|
38
|
my (@args) = @_; |
|
45
|
4
|
|
|
|
|
19
|
return _convert_build( [@args], is_object => 1, want_utils => 1 ); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub make_repeat_method { |
|
49
|
0
|
|
|
0
|
0
|
0
|
my (@args) = @_; |
|
50
|
0
|
|
|
|
|
0
|
return _convert_build( [@args], is_object => 1, is_repeat => 1 ); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _convert_build { |
|
54
|
15
|
|
|
15
|
|
60
|
my ($args, %inner_opts) = @_; |
|
55
|
15
|
|
|
|
|
35
|
my ($exp_ret_list, $opts) = @$args; |
|
56
|
15
|
100
|
|
|
|
433
|
$exp_ret_list = [$exp_ret_list] unless is_array_ref $exp_ret_list; |
|
57
|
15
|
|
100
|
|
|
105
|
$opts ||= {}; |
|
58
|
15
|
|
|
|
|
33
|
return _build( $exp_ret_list, { %{ $opts }, %inner_opts } ); |
|
|
15
|
|
|
|
|
115
|
|
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _build { |
|
62
|
15
|
|
|
15
|
|
36
|
my ($exp_ret_list, $opts) = @_; |
|
63
|
|
|
|
|
|
|
|
|
64
|
15
|
|
50
|
|
|
142
|
my $message = $opts->{message} || "[stub] arguments are as You expected"; |
|
65
|
15
|
|
100
|
|
|
81
|
my $is_object = $opts->{is_object} || 0; |
|
66
|
15
|
|
100
|
|
|
632634
|
my $is_repeat = $opts->{is_repeat} || 0; |
|
67
|
15
|
|
100
|
|
|
83
|
my $want_utils = $opts->{want_utils} || 0; |
|
68
|
15
|
|
|
|
|
25
|
my $call_count = 0; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $method = sub { |
|
71
|
35
|
|
|
35
|
|
6409
|
my $input = [@_]; |
|
72
|
35
|
100
|
|
|
|
118
|
shift @$input if $is_object; |
|
73
|
35
|
|
|
|
|
70
|
$call_count++; |
|
74
|
|
|
|
|
|
|
|
|
75
|
35
|
100
|
|
|
|
119
|
my $element = $is_repeat ? $exp_ret_list->[0] : shift @$exp_ret_list; |
|
76
|
35
|
50
|
|
|
|
104
|
unless ( defined $element ) { |
|
77
|
0
|
|
|
|
|
0
|
fail 'expects and return are already empty.'; |
|
78
|
0
|
|
|
|
|
0
|
return undef; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
35
|
|
|
|
|
73
|
my $expects = $element->{expects}; |
|
82
|
35
|
|
|
|
|
135
|
my $return = $element->{return}; |
|
83
|
|
|
|
|
|
|
|
|
84
|
35
|
100
|
|
|
|
140
|
cmp_deeply($input, $expects, $message) |
|
85
|
|
|
|
|
|
|
or note explain +{ input => $input, expects => $expects }; |
|
86
|
|
|
|
|
|
|
|
|
87
|
35
|
100
|
|
|
|
383778
|
return is_code_ref($return) ? $return->() : $return; |
|
88
|
15
|
|
|
|
|
127
|
}; |
|
89
|
|
|
|
|
|
|
|
|
90
|
15
|
100
|
|
|
|
58
|
unless ($want_utils) { |
|
91
|
11
|
|
|
|
|
76
|
return $method; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
4
|
|
|
|
|
49
|
my $utils = bless( {}, 'Test::Stub::Generator::Util' ); |
|
95
|
|
|
|
|
|
|
Class::Monadic->initialize($utils)->add_methods( |
|
96
|
|
|
|
|
|
|
has_next => sub { |
|
97
|
2
|
100
|
|
2
|
|
35
|
return @$exp_ret_list ? 1 : 0; |
|
98
|
|
|
|
|
|
|
}, |
|
99
|
|
|
|
|
|
|
is_repeat => sub { |
|
100
|
2
|
|
|
2
|
|
91
|
return $is_repeat; |
|
101
|
|
|
|
|
|
|
}, |
|
102
|
|
|
|
|
|
|
called_count => sub { |
|
103
|
4
|
|
|
4
|
|
37
|
return $call_count; |
|
104
|
|
|
|
|
|
|
}, |
|
105
|
4
|
|
|
|
|
47
|
); |
|
106
|
|
|
|
|
|
|
|
|
107
|
4
|
|
|
|
|
466
|
return ($method, $utils); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
|
111
|
|
|
|
|
|
|
__END__ |