1 | # ------------------------------------------------------------------------------ |
---|
2 | # Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
3 | # |
---|
4 | # This file is part of FCM, tools for managing and building source code. |
---|
5 | # |
---|
6 | # FCM is free software: you can redistribute it and/or modify |
---|
7 | # it under the terms of the GNU General Public License as published by |
---|
8 | # the Free Software Foundation, either version 3 of the License, or |
---|
9 | # (at your option) any later version. |
---|
10 | # |
---|
11 | # FCM is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | # ------------------------------------------------------------------------------ |
---|
19 | use strict; |
---|
20 | use warnings; |
---|
21 | |
---|
22 | package FCM1::Interactive::InputGetter; |
---|
23 | |
---|
24 | use Carp qw{croak}; |
---|
25 | |
---|
26 | ################################################################################ |
---|
27 | # Constructor |
---|
28 | sub new { |
---|
29 | my ($class, $args_ref) = @_; |
---|
30 | return bless({%{$args_ref}}, $class); |
---|
31 | } |
---|
32 | |
---|
33 | ################################################################################ |
---|
34 | # Methods: get_* |
---|
35 | for my $key ( |
---|
36 | ############################################################################ |
---|
37 | # Returns the title of the prompt |
---|
38 | 'title', |
---|
39 | ############################################################################ |
---|
40 | # Returns the message of the prompt |
---|
41 | 'message', |
---|
42 | ############################################################################ |
---|
43 | # Returns the of the prompt |
---|
44 | 'type', |
---|
45 | ############################################################################ |
---|
46 | # Returns the default return value |
---|
47 | 'default', |
---|
48 | ) { |
---|
49 | no strict qw{refs}; |
---|
50 | my $getter = "get_$key"; |
---|
51 | *$getter = sub { |
---|
52 | my ($self) = @_; |
---|
53 | return $self->{$key}; |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | ################################################################################ |
---|
58 | # Invokes the getter |
---|
59 | sub invoke { |
---|
60 | my ($self) = @_; |
---|
61 | croak("FCM1::Interactive::InputGetter->invoke() not implemented."); |
---|
62 | } |
---|
63 | |
---|
64 | 1; |
---|
65 | __END__ |
---|
66 | |
---|
67 | =head1 NAME |
---|
68 | |
---|
69 | FCM1::Interactive::TxtInputGetter |
---|
70 | |
---|
71 | =head1 SYNOPSIS |
---|
72 | |
---|
73 | use FCM1::Interactive::TxtInputGetter; |
---|
74 | $answer = FCM1::Interactive::get_input( |
---|
75 | title => 'My title', |
---|
76 | message => 'Would you like to ...?', |
---|
77 | type => 'yn', |
---|
78 | default => 'n', |
---|
79 | ); |
---|
80 | |
---|
81 | =head1 DESCRIPTION |
---|
82 | |
---|
83 | An object of this abstract class is used by |
---|
84 | L<FCM1::Interactive|FCM1::Interactive> to get a user reply. |
---|
85 | |
---|
86 | =head1 METHODS |
---|
87 | |
---|
88 | =over 4 |
---|
89 | |
---|
90 | =item new($args_ref) |
---|
91 | |
---|
92 | Constructor, normally invoked via L<FCM1::Interactive|FCM1::Interactive>. |
---|
93 | |
---|
94 | Input options are: I<title>, for a short title of the prompt, I<message>, for |
---|
95 | the message prompt, I<type> for the prompt type, and I<default> for the default |
---|
96 | value of the return value. |
---|
97 | |
---|
98 | Prompt type can be YN (yes or no), YNA (yes, no or all) or input (for an input |
---|
99 | string). |
---|
100 | |
---|
101 | =item get_title() |
---|
102 | |
---|
103 | Returns the title of the prompt. |
---|
104 | |
---|
105 | =item get_message() |
---|
106 | |
---|
107 | Returns the message of the prompt. |
---|
108 | |
---|
109 | =item get_type() |
---|
110 | |
---|
111 | Returns the type of the prompt, can be YN (yes or no), YNA (yes, no or all) or |
---|
112 | input (for an input string). |
---|
113 | |
---|
114 | =item get_default() |
---|
115 | |
---|
116 | Returns the default return value of invoke(). |
---|
117 | |
---|
118 | =item invoke() |
---|
119 | |
---|
120 | Gets an input string from the user, and returns it. Sub-classes must override |
---|
121 | this method. |
---|
122 | |
---|
123 | =back |
---|
124 | |
---|
125 | =head1 SEE ALSO |
---|
126 | |
---|
127 | L<FCM1::Interactive|FCM1::Interactive>, |
---|
128 | L<FCM1::Interactive::TxtInputGetter|FCM1::Interactive::TxtInputGetter>, |
---|
129 | L<FCM1::Interactive::GUIInputGetter|FCM1::Interactive::GUIInputGetter> |
---|
130 | |
---|
131 | =head1 COPYRIGHT |
---|
132 | |
---|
133 | Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
134 | |
---|
135 | =cut |
---|