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