| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# -*- perl -*- |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Module::TestConfig::Question - question interface |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Module::TestConfig::Question; |
|
6
|
|
|
|
|
|
|
{ |
|
7
|
|
|
|
|
|
|
$Module::TestConfig::Question::VERSION = '0.06_01'; |
|
8
|
|
|
|
|
|
|
} |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require 5.005_62; |
|
11
|
8
|
|
|
8
|
|
25797
|
use strict; |
|
|
8
|
|
|
|
|
17
|
|
|
|
8
|
|
|
|
|
313
|
|
|
12
|
8
|
|
|
8
|
|
41
|
use Carp; |
|
|
8
|
|
|
|
|
16
|
|
|
|
8
|
|
|
|
|
6962
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#------------------------------------------------------------ |
|
15
|
|
|
|
|
|
|
# Methods |
|
16
|
|
|
|
|
|
|
#------------------------------------------------------------ |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
|
19
|
27
|
|
|
27
|
1
|
52
|
my $proto = shift; |
|
20
|
27
|
|
33
|
|
|
814
|
my $class = ref $proto || $proto; |
|
21
|
27
|
|
|
|
|
98
|
my $self = bless {}, $class; |
|
22
|
27
|
|
|
|
|
79
|
$self->init( @_ ); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub init { |
|
27
|
27
|
|
|
27
|
1
|
40
|
my $self = shift; |
|
28
|
|
|
|
|
|
|
|
|
29
|
27
|
100
|
|
|
|
70
|
if ( ref $_[0] eq "ARRAY" ) { |
|
30
|
24
|
|
|
|
|
30
|
my @q = @{+shift}; |
|
|
24
|
|
|
|
|
56
|
|
|
31
|
24
|
50
|
|
|
|
99
|
$self->msg( shift @q ) if @q; |
|
32
|
24
|
50
|
|
|
|
88
|
$self->name( shift @q ) if @q; |
|
33
|
24
|
100
|
|
|
|
77
|
$self->def( shift @q ) if @q; |
|
34
|
24
|
100
|
|
|
|
71
|
$self->opts( shift @q ) if @q; |
|
35
|
|
|
|
|
|
|
} else { |
|
36
|
3
|
100
|
|
|
|
11
|
my %args = ref $_[0] eq "HASH" ? %{$_[0]} : @_; |
|
|
2
|
|
|
|
|
10
|
|
|
37
|
3
|
|
|
|
|
13
|
while ( my ( $method, $args ) = each %args ) { |
|
38
|
11
|
50
|
|
|
|
36
|
if ( $self->can( $method ) ) { |
|
39
|
11
|
|
|
|
|
23
|
$self->$method( $args ); |
|
40
|
|
|
|
|
|
|
} else { |
|
41
|
0
|
|
|
|
|
0
|
croak "Can't handle arg: '$method'. Aborting"; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
27
|
|
|
|
|
132
|
return $self; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub msg { |
|
50
|
115
|
|
|
115
|
1
|
139
|
my $self = shift; |
|
51
|
115
|
100
|
|
|
|
1375
|
$self->{msg} = shift if @_; |
|
52
|
115
|
|
|
|
|
3269
|
return $self->{msg}; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub name { |
|
56
|
198
|
|
|
198
|
1
|
255
|
my $self = shift; |
|
57
|
198
|
100
|
|
|
|
380
|
$self->{name} = shift if @_; |
|
58
|
198
|
|
|
|
|
803
|
$self->{name}; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub def { |
|
62
|
64
|
|
|
64
|
1
|
87
|
my $self = shift; |
|
63
|
64
|
100
|
|
|
|
174
|
$self->{default} = shift if @_; |
|
64
|
64
|
|
|
|
|
155
|
$self->{default}; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub opts { |
|
68
|
9
|
|
|
9
|
1
|
14
|
my $self = shift; |
|
69
|
|
|
|
|
|
|
|
|
70
|
9
|
50
|
|
|
|
27
|
if ( @_ ) { |
|
71
|
9
|
100
|
|
|
|
24
|
my %args = ref $_[0] eq "HASH" ? %{ $_[0] } : @_; |
|
|
8
|
|
|
|
|
32
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
9
|
|
|
|
|
35
|
while ( my ( $method, $args ) = each %args ) { |
|
74
|
17
|
50
|
|
|
|
68
|
if ( $self->can( $method ) ) { |
|
75
|
17
|
|
|
|
|
50
|
$self->$method( $args ); |
|
76
|
|
|
|
|
|
|
} else { |
|
77
|
0
|
|
|
|
|
0
|
croak "Can't handle opts arg: '$method'. Aborting"; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return wantarray |
|
83
|
9
|
50
|
|
|
|
97
|
? ( skip => $self->{skip}, |
|
84
|
|
|
|
|
|
|
validate => $self->{validate}, |
|
85
|
|
|
|
|
|
|
noecho => $self->{noecho}, |
|
86
|
|
|
|
|
|
|
) |
|
87
|
|
|
|
|
|
|
: { skip => $self->{skip}, |
|
88
|
|
|
|
|
|
|
validate => $self->{validate}, |
|
89
|
|
|
|
|
|
|
noecho => $self->{noecho}, |
|
90
|
|
|
|
|
|
|
}; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub skip { |
|
94
|
27
|
|
|
27
|
1
|
38
|
my $self = shift; |
|
95
|
27
|
100
|
|
|
|
71
|
$self->{skip} = shift if @_; |
|
96
|
27
|
|
|
|
|
91
|
return $self->{skip}; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub validate { |
|
100
|
102
|
|
|
102
|
1
|
144
|
my $self = shift; |
|
101
|
102
|
100
|
|
|
|
217
|
$self->{validate} = shift if @_; |
|
102
|
102
|
|
|
|
|
898
|
return $self->{validate}; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub noecho { |
|
106
|
34
|
|
|
34
|
1
|
58
|
my $self = shift; |
|
107
|
34
|
100
|
|
|
|
295
|
$self->{noecho} = shift if @_; |
|
108
|
34
|
|
|
|
|
138
|
return $self->{noecho}; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Aliases |
|
112
|
|
|
|
|
|
|
*default = \&def; |
|
113
|
|
|
|
|
|
|
*question = \&msg; |
|
114
|
|
|
|
|
|
|
*options = \&opts; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 NAME |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Module::TestConfig::Question - question interface |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 VERSION |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
version 0.06_01 |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
use Module::TestConfig::Question; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $question = Module::TestConfig::Question->new( |
|
131
|
|
|
|
|
|
|
name => 'toes', |
|
132
|
|
|
|
|
|
|
msg => 'How many toes do you have?', |
|
133
|
|
|
|
|
|
|
def => 10, |
|
134
|
|
|
|
|
|
|
opts => { |
|
135
|
|
|
|
|
|
|
noecho => 0, |
|
136
|
|
|
|
|
|
|
validate => { ... }, |
|
137
|
|
|
|
|
|
|
skip => sub { ... }, |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
); |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 PUBLIC METHODS |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 2 |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item new() |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Args: See L<"SYNOPSIS"> |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Returns: an object |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item init() |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Args: accepts a list, arrayref, or hashref of arguments; see L<"SYNOPSIS"> |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item msg() |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item question() |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Required. The question we ask of a user. A string. Tends |
|
160
|
|
|
|
|
|
|
to look best when there's a '?' or a ':' on the end. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Args: a question to ask the user |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Returns: that question |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item name() |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
The name an answer is saved as. Basically a hash key. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Args: the question's name |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Returns: that name |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item def() |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item default() |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
A question's default answer. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Args: a default |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Returns: that default |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item opts() |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item options() |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
See L<"skip()">, L<"validate()"> and L<"noecho()">. |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Args: A hash or hashref of options. |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Returns: the hashref in scalar context, a hash in list context. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item skip() |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Criteria used to skip the current question. Either a scalar or |
|
197
|
|
|
|
|
|
|
a coderef. If either evalutes to true, the current question |
|
198
|
|
|
|
|
|
|
ought to be skipped. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Args: a scalar or coderef |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Returns: the current scalar or coderef |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item validate() |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Args to be passed directly to Params::Validate::validate() or another |
|
207
|
|
|
|
|
|
|
validation subroutine. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Args: a hashref by default |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Returns: the current hashref |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item noecho() |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Do we echo the user's typing? |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Args: 1 or 0 |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Returns: the current value |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=back |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 AUTHOR |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Joshua Keroes Ejoshua@cpan.orgE |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Copyright 2003-2013 by Joshua Keroes Ejoshua@cpan.orgE |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
232
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
L |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |