line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Run::Base::PlugHelpers; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
11402
|
use strict; |
|
17
|
|
|
|
|
39
|
|
|
17
|
|
|
|
|
501
|
|
4
|
17
|
|
|
17
|
|
85
|
use warnings; |
|
17
|
|
|
|
|
29
|
|
|
17
|
|
|
|
|
539
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Test::Run::Base::PlugHelpers - base class for Test::Run's classes with |
9
|
|
|
|
|
|
|
pluggable helpers. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
17
|
|
|
17
|
|
87
|
use MRO::Compat; |
|
17
|
|
|
|
|
30
|
|
|
17
|
|
|
|
|
337
|
|
14
|
|
|
|
|
|
|
|
15
|
17
|
|
|
17
|
|
76
|
use Carp; |
|
17
|
|
|
|
|
34
|
|
|
17
|
|
|
|
|
1152
|
|
16
|
|
|
|
|
|
|
|
17
|
17
|
|
|
17
|
|
125
|
use Moose; |
|
17
|
|
|
|
|
35
|
|
|
17
|
|
|
|
|
150
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
extends('Test::Run::Base'); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
17
|
|
|
17
|
|
115916
|
use Test::Run::Base::Plugger; |
|
17
|
|
|
|
|
57
|
|
|
17
|
|
|
|
|
267
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has '_plug_helpers' => (is => "rw", isa => "HashRef", |
25
|
|
|
|
|
|
|
lazy => 1, default => sub { +{} }, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 $self->register_pluggable_helper( { %args } ) |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Registers a pluggable helper class (commonly done during initialisation). |
31
|
|
|
|
|
|
|
%args contain the following keys: |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over 4 |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item * 'id' |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The 'id' identifying this class type. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item * 'base' |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
The base class to use as the ultimate primary class of the plugin-based class. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item * 'collect_plugins_method' |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
The method from which to collect the plugins. It should be defined for every |
46
|
|
|
|
|
|
|
base class in the hierarchy of the main class (that instantiates the helpers) |
47
|
|
|
|
|
|
|
and is traversed there. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=back |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub register_pluggable_helper |
54
|
|
|
|
|
|
|
{ |
55
|
265
|
|
|
265
|
1
|
3912
|
my ($self, $args) = @_; |
56
|
|
|
|
|
|
|
|
57
|
265
|
|
|
|
|
403
|
my %plug_helper_struct; |
58
|
|
|
|
|
|
|
|
59
|
265
|
|
|
|
|
664
|
foreach my $key (qw(id base collect_plugins_method)) |
60
|
|
|
|
|
|
|
{ |
61
|
792
|
100
|
|
|
|
1964
|
my $value = $args->{$key} |
62
|
|
|
|
|
|
|
or confess "\"$key\" not specified for register_pluggable_helper"; |
63
|
|
|
|
|
|
|
|
64
|
789
|
|
|
|
|
1468
|
$plug_helper_struct{$key} = $value; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
262
|
|
|
|
|
7395
|
$self->_plug_helpers()->{$plug_helper_struct{'id'}} |
68
|
|
|
|
|
|
|
= \%plug_helper_struct; |
69
|
|
|
|
|
|
|
|
70
|
262
|
|
|
|
|
552
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 $self->calc_helpers_namespace($id) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Calc the namespace to put the helper with the ID C<$id> in. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub calc_helpers_namespace |
80
|
|
|
|
|
|
|
{ |
81
|
203
|
|
|
203
|
1
|
881
|
my ($self, $id) = @_; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return |
84
|
203
|
|
|
|
|
1312
|
$self->helpers_base_namespace() . "::Helpers::" . ucfirst($id) |
85
|
|
|
|
|
|
|
; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 $self->create_pluggable_helper_obj({ id => $id, args => $args }) |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Instantiates a new pluggable helper object of the ID $id and with $args |
91
|
|
|
|
|
|
|
passed to the constructor. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub create_pluggable_helper_obj |
96
|
|
|
|
|
|
|
{ |
97
|
203
|
|
|
203
|
1
|
789
|
my ($self, $args) = @_; |
98
|
|
|
|
|
|
|
|
99
|
203
|
|
|
|
|
796
|
my $id = $args->{id}; |
100
|
|
|
|
|
|
|
|
101
|
203
|
|
|
|
|
6924
|
my $plug_struct = $self->_plug_helpers()->{$id}; |
102
|
203
|
100
|
|
|
|
720
|
if (!defined($plug_struct)) |
103
|
|
|
|
|
|
|
{ |
104
|
1
|
|
|
|
|
129
|
confess "Unknown Pluggable Helper ID \"$id\"!"; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $plugger = Test::Run::Base::Plugger->new( |
108
|
|
|
|
|
|
|
{ |
109
|
|
|
|
|
|
|
base => $plug_struct->{base}, |
110
|
202
|
|
|
|
|
1185
|
into => $self->calc_helpers_namespace($id), |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$plugger->add_plugins( |
115
|
|
|
|
|
|
|
$self->accum_array( |
116
|
|
|
|
|
|
|
{ |
117
|
|
|
|
|
|
|
method => $plug_struct->{collect_plugins_method} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
) |
120
|
202
|
|
|
|
|
3755
|
); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
return |
123
|
|
|
|
|
|
|
$plugger->create_new( |
124
|
|
|
|
|
|
|
$args->{args}, |
125
|
202
|
|
|
|
|
967
|
); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 $self->helpers_base_namespace() |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
B<TO OVERRIDE>: this method determines the base namespace used as the |
131
|
|
|
|
|
|
|
base for the pluggable helpers classes. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SEE ALSO |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L<Test::Run::Base>, L<Test::Run::Obj>, L<Test::Run::Core> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 LICENSE |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This file is freely distributable under the MIT X11 license. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L<http://www.opensource.org/licenses/mit-license.php> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 AUTHOR |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Shlomi Fish, L<http://www.shlomifish.org/>. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
155
|
|
|
|
|
|
|
|