line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Run::Base; |
2
|
|
|
|
|
|
|
|
3
|
23
|
|
|
23
|
|
35352
|
use strict; |
|
23
|
|
|
|
|
49
|
|
|
23
|
|
|
|
|
614
|
|
4
|
23
|
|
|
23
|
|
117
|
use warnings; |
|
23
|
|
|
|
|
49
|
|
|
23
|
|
|
|
|
692
|
|
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
831
|
use MRO::Compat; |
|
23
|
|
|
|
|
3375
|
|
|
23
|
|
|
|
|
542
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Test::Run::Base - base class for all of Test::Run. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This is the base class for all Test::Run classes. It inherits from |
16
|
|
|
|
|
|
|
L<Class::Accessor> and provides some goodies of its own. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 METHODS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
23
|
|
|
23
|
|
937
|
use Moose; |
|
23
|
|
|
|
|
473370
|
|
|
23
|
|
|
|
|
128
|
|
23
|
|
|
|
|
|
|
|
24
|
23
|
|
|
23
|
|
158678
|
use Text::Sprintf::Named; |
|
23
|
|
|
|
|
20558
|
|
|
23
|
|
|
|
|
1156
|
|
25
|
23
|
|
|
23
|
|
14075
|
use Test::Run::Sprintf::Named::FromAccessors; |
|
23
|
|
|
|
|
84
|
|
|
23
|
|
|
|
|
1384
|
|
26
|
|
|
|
|
|
|
|
27
|
23
|
|
|
23
|
|
14414
|
use Test::Run::Class::Hierarchy (qw(hierarchy_of rev_hierarchy_of)); |
|
23
|
|
|
|
|
72
|
|
|
23
|
|
|
|
|
1678
|
|
28
|
|
|
|
|
|
|
|
29
|
23
|
|
|
23
|
|
141
|
use Carp (); |
|
23
|
|
|
|
|
49
|
|
|
23
|
|
|
|
|
18021
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has '_formatters' => (is => "rw", isa => "HashRef", default => sub { +{} },); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 $package->new({%args}) |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
The default constructor. Do not over-ride it. Instead, define a |
36
|
|
|
|
|
|
|
L<BUILD()> method. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 $dest->copy_from($source, [@fields]) |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Assigns the fields C<@fields> using their accessors based on their values |
43
|
|
|
|
|
|
|
in C<$source>. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub copy_from |
48
|
|
|
|
|
|
|
{ |
49
|
57
|
|
|
57
|
1
|
135
|
my ($dest, $source, $fields) = @_; |
50
|
|
|
|
|
|
|
|
51
|
57
|
|
|
|
|
224
|
foreach my $f (@$fields) |
52
|
|
|
|
|
|
|
{ |
53
|
228
|
|
|
|
|
8248
|
$dest->$f($source->$f()); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
57
|
|
|
|
|
165
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _get_formatter |
60
|
|
|
|
|
|
|
{ |
61
|
476
|
|
|
476
|
|
709
|
my ($self, $fmt) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return |
64
|
476
|
|
|
|
|
2072
|
Text::Sprintf::Named->new( |
65
|
|
|
|
|
|
|
{ fmt => $fmt, }, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _register_formatter |
70
|
|
|
|
|
|
|
{ |
71
|
468
|
|
|
468
|
|
801
|
my ($self, $name, $fmt) = @_; |
72
|
|
|
|
|
|
|
|
73
|
468
|
|
|
|
|
1152
|
$self->_formatters->{$name} = $self->_get_formatter($fmt); |
74
|
|
|
|
|
|
|
|
75
|
468
|
|
|
|
|
2566
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _get_obj_formatter |
79
|
|
|
|
|
|
|
{ |
80
|
685
|
|
|
685
|
|
1132
|
my ($self, $fmt) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return |
83
|
685
|
|
|
|
|
4296
|
Test::Run::Sprintf::Named::FromAccessors->new( |
84
|
|
|
|
|
|
|
{ fmt => $fmt, }, |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _register_obj_formatter |
89
|
|
|
|
|
|
|
{ |
90
|
671
|
|
|
671
|
|
1219
|
my ($self, $args) = @_; |
91
|
|
|
|
|
|
|
|
92
|
671
|
|
|
|
|
1211
|
my $name = $args->{name}; |
93
|
671
|
|
|
|
|
1103
|
my $fmt = $args->{format}; |
94
|
|
|
|
|
|
|
|
95
|
671
|
|
|
|
|
5673
|
$self->_formatters->{$name} = $self->_get_obj_formatter($fmt); |
96
|
|
|
|
|
|
|
|
97
|
671
|
|
|
|
|
2745
|
return; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _format |
101
|
|
|
|
|
|
|
{ |
102
|
121
|
|
|
121
|
|
297
|
my ($self, $format, $args) = @_; |
103
|
|
|
|
|
|
|
|
104
|
121
|
100
|
|
|
|
344
|
if (ref($format) eq "") |
105
|
|
|
|
|
|
|
{ |
106
|
113
|
|
|
|
|
3900
|
return $self->_formatters->{$format}->format({ args => $args}); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
else |
109
|
|
|
|
|
|
|
{ |
110
|
8
|
|
|
|
|
18
|
return $self->_get_formatter(${$format})->format({ args => $args}); |
|
8
|
|
|
|
|
60
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _format_self |
115
|
|
|
|
|
|
|
{ |
116
|
43
|
|
|
43
|
|
663
|
my ($self, $format, $args) = @_; |
117
|
|
|
|
|
|
|
|
118
|
43
|
|
100
|
|
|
255
|
$args ||= {}; |
119
|
|
|
|
|
|
|
|
120
|
43
|
|
|
|
|
82
|
return $self->_format($format, { obj => $self, %{$args}}); |
|
43
|
|
|
|
|
272
|
|
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 $self->accum_array({ method => $method_name }) |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This is a more simplistic version of the :CUMULATIVE functionality |
126
|
|
|
|
|
|
|
in Class::Std. It was done to make sure that one can collect all the |
127
|
|
|
|
|
|
|
members of array refs out of methods defined in each class into one big |
128
|
|
|
|
|
|
|
array ref, that can later be used. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub accum_array |
133
|
|
|
|
|
|
|
{ |
134
|
204
|
|
|
204
|
1
|
1750
|
my ($self, $args) = @_; |
135
|
|
|
|
|
|
|
|
136
|
204
|
|
|
|
|
500
|
my $method_name = $args->{method}; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# my $class = ((ref($self) eq "") ? $self : ref($self)); |
139
|
|
|
|
|
|
|
|
140
|
204
|
|
|
|
|
393
|
my @results; |
141
|
204
|
|
|
|
|
1320
|
foreach my $isa_class ( |
142
|
|
|
|
|
|
|
$self->meta->find_all_methods_by_name($method_name) |
143
|
|
|
|
|
|
|
) |
144
|
|
|
|
|
|
|
{ |
145
|
7
|
|
|
|
|
1110
|
my $body = $isa_class->{code}->body(); |
146
|
7
|
|
|
|
|
10
|
push @results, @{ $self->$body() }; |
|
7
|
|
|
|
|
19
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
204
|
|
|
|
|
57456
|
return \@results; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub _list_pluralize |
153
|
|
|
|
|
|
|
{ |
154
|
12
|
|
|
12
|
|
53
|
my ($self, $noun, $list) = @_; |
155
|
|
|
|
|
|
|
|
156
|
12
|
|
|
|
|
79
|
return $self->_pluralize($noun, scalar(@$list)); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub _pluralize |
160
|
|
|
|
|
|
|
{ |
161
|
21
|
|
|
21
|
|
53
|
my ($self, $noun, $count) = @_; |
162
|
|
|
|
|
|
|
|
163
|
21
|
100
|
|
|
|
245
|
return sprintf("%s%s", |
164
|
|
|
|
|
|
|
$noun, |
165
|
|
|
|
|
|
|
(($count > 1) ? "s" : "") |
166
|
|
|
|
|
|
|
); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 $self->_run_sequence(\@params) |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Runs the sequence of commands specified using |
172
|
|
|
|
|
|
|
C<_calc__${calling_sub}__callbacks> while passing @params to |
173
|
|
|
|
|
|
|
each one. Generates a list of all the callbacks return values. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub _run_sequence |
178
|
|
|
|
|
|
|
{ |
179
|
543
|
|
|
543
|
|
1171
|
my $self = shift; |
180
|
543
|
|
100
|
|
|
3244
|
my $params = shift || []; |
181
|
|
|
|
|
|
|
|
182
|
543
|
|
|
|
|
5553
|
my $sub = (caller(1))[3]; |
183
|
|
|
|
|
|
|
|
184
|
543
|
|
|
|
|
5461
|
$sub =~ s{::_?([^:]+)$}{}; |
185
|
|
|
|
|
|
|
|
186
|
543
|
|
|
|
|
2255
|
my $calc_cbs_sub = "_calc__${1}__callbacks"; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
return |
189
|
|
|
|
|
|
|
[ |
190
|
1740
|
|
|
|
|
3857
|
map { my $cb = $_; $self->$cb(@$params); } |
|
1740
|
|
|
|
|
10680
|
|
191
|
543
|
|
|
|
|
959
|
@{$self->$calc_cbs_sub(@$params)} |
|
543
|
|
|
|
|
3334
|
|
192
|
|
|
|
|
|
|
]; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
__END__ |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 LICENSE |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This file is licensed under the MIT X11 License: |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
http://www.opensource.org/licenses/mit-license.php |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |
206
|
|
|
|
|
|
|
|