line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Run::Base; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24034
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
900
|
use MRO::Compat; |
|
1
|
|
|
|
|
6156
|
|
|
1
|
|
|
|
|
36
|
|
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
|
1
|
|
|
1
|
|
1765
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Text::Sprintf::Named; |
25
|
|
|
|
|
|
|
use Test::Run::Sprintf::Named::FromAccessors; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Test::Run::Class::Hierarchy (qw(hierarchy_of rev_hierarchy_of)); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use Carp (); |
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
|
|
|
|
|
|
|
my ($dest, $source, $fields) = @_; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
foreach my $f (@$fields) |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
$dest->$f($source->$f()); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _get_formatter |
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
my ($self, $fmt) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return |
64
|
|
|
|
|
|
|
Text::Sprintf::Named->new( |
65
|
|
|
|
|
|
|
{ fmt => $fmt, }, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _register_formatter |
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
my ($self, $name, $fmt) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$self->_formatters->{$name} = $self->_get_formatter($fmt); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _get_obj_formatter |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
my ($self, $fmt) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return |
83
|
|
|
|
|
|
|
Test::Run::Sprintf::Named::FromAccessors->new( |
84
|
|
|
|
|
|
|
{ fmt => $fmt, }, |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _register_obj_formatter |
89
|
|
|
|
|
|
|
{ |
90
|
|
|
|
|
|
|
my ($self, $args) = @_; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $name = $args->{name}; |
93
|
|
|
|
|
|
|
my $fmt = $args->{format}; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$self->_formatters->{$name} = $self->_get_obj_formatter($fmt); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _format |
101
|
|
|
|
|
|
|
{ |
102
|
|
|
|
|
|
|
my ($self, $format, $args) = @_; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
if (ref($format) eq "") |
105
|
|
|
|
|
|
|
{ |
106
|
|
|
|
|
|
|
return $self->_formatters->{$format}->format({ args => $args}); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
else |
109
|
|
|
|
|
|
|
{ |
110
|
|
|
|
|
|
|
return $self->_get_formatter(${$format})->format({ args => $args}); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _format_self |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
my ($self, $format, $args) = @_; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$args ||= {}; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
return $self->_format($format, { obj => $self, %{$args}}); |
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
|
|
|
|
|
|
|
my ($self, $args) = @_; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $method_name = $args->{method}; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# my $class = ((ref($self) eq "") ? $self : ref($self)); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my @results; |
141
|
|
|
|
|
|
|
foreach my $isa_class ( |
142
|
|
|
|
|
|
|
$self->meta->find_all_methods_by_name($method_name) |
143
|
|
|
|
|
|
|
) |
144
|
|
|
|
|
|
|
{ |
145
|
|
|
|
|
|
|
my $body = $isa_class->{code}->body(); |
146
|
|
|
|
|
|
|
push @results, @{ $self->$body() }; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
return \@results; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub _list_pluralize |
153
|
|
|
|
|
|
|
{ |
154
|
|
|
|
|
|
|
my ($self, $noun, $list) = @_; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
return $self->_pluralize($noun, scalar(@$list)); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub _pluralize |
160
|
|
|
|
|
|
|
{ |
161
|
|
|
|
|
|
|
my ($self, $noun, $count) = @_; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my $self = shift; |
180
|
|
|
|
|
|
|
my $params = shift || []; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
my $sub = (caller(1))[3]; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
$sub =~ s{::_?([^:]+)$}{}; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
my $calc_cbs_sub = "_calc__${1}__callbacks"; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
return |
189
|
|
|
|
|
|
|
[ |
190
|
|
|
|
|
|
|
map { my $cb = $_; $self->$cb(@$params); } |
191
|
|
|
|
|
|
|
@{$self->$calc_cbs_sub(@$params)} |
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
|
|
|
|
|
|
|
|