New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
InputGetter.pm in vendors/lib/FCM1/Interactive – NEMO

source: vendors/lib/FCM1/Interactive/InputGetter.pm @ 10669

Last change on this file since 10669 was 10669, checked in by nicolasmartin, 5 years ago

Import latest FCM release from Github into the repository for testing

File size: 3.6 KB
Line 
1# ------------------------------------------------------------------------------
2# (C) British Crown Copyright 2006-17 Met Office.
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# ------------------------------------------------------------------------------
19use strict;
20use warnings;
21
22package FCM1::Interactive::InputGetter;
23
24use Carp qw{croak};
25
26################################################################################
27# Constructor
28sub new {
29    my ($class, $args_ref) = @_;
30    return bless({%{$args_ref}}, $class);
31}
32
33################################################################################
34# Methods: get_*
35for 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
59sub invoke {
60    my ($self) = @_;
61    croak("FCM1::Interactive::InputGetter->invoke() not implemented.");
62}
63
641;
65__END__
66
67=head1 NAME
68
69FCM1::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
83An object of this abstract class is used by
84L<FCM1::Interactive|FCM1::Interactive> to get a user reply.
85
86=head1 METHODS
87
88=over 4
89
90=item new($args_ref)
91
92Constructor, normally invoked via L<FCM1::Interactive|FCM1::Interactive>.
93
94Input options are: I<title>, for a short title of the prompt, I<message>, for
95the message prompt, I<type> for the prompt type, and I<default> for the default
96value of the return value.
97
98Prompt type can be YN (yes or no), YNA (yes, no or all) or input (for an input
99string).
100
101=item get_title()
102
103Returns the title of the prompt.
104
105=item get_message()
106
107Returns the message of the prompt.
108
109=item get_type()
110
111Returns the type of the prompt, can be YN (yes or no), YNA (yes, no or all) or
112input (for an input string).
113
114=item get_default()
115
116Returns the default return value of invoke().
117
118=item invoke()
119
120Gets an input string from the user, and returns it. Sub-classes must override
121this method.
122
123=back
124
125=head1 SEE ALSO
126
127L<FCM1::Interactive|FCM1::Interactive>,
128L<FCM1::Interactive::TxtInputGetter|FCM1::Interactive::TxtInputGetter>,
129L<FCM1::Interactive::GUIInputGetter|FCM1::Interactive::GUIInputGetter>
130
131=head1 COPYRIGHT
132
133E<169> Crown copyright Met Office. All rights reserved.
134
135=cut
Note: See TracBrowser for help on using the repository browser.