[1980] | 1 | # ------------------------------------------------------------------------------ |
---|
| 2 | # (C) Crown copyright Met Office. All rights reserved. |
---|
| 3 | # For further details please refer to the file COPYRIGHT.txt |
---|
| 4 | # which you should have received as part of this distribution. |
---|
| 5 | # ------------------------------------------------------------------------------ |
---|
| 6 | use strict; |
---|
| 7 | use warnings; |
---|
| 8 | |
---|
| 9 | package Fcm::Interactive::InputGetter; |
---|
| 10 | |
---|
| 11 | use Carp qw{croak}; |
---|
| 12 | |
---|
| 13 | ################################################################################ |
---|
| 14 | # Constructor |
---|
| 15 | sub new { |
---|
| 16 | my ($class, $args_ref) = @_; |
---|
| 17 | return bless({%{$args_ref}}, $class); |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | ################################################################################ |
---|
| 21 | # Methods: get_* |
---|
| 22 | for my $key ( |
---|
| 23 | ############################################################################ |
---|
| 24 | # Returns the title of the prompt |
---|
| 25 | 'title', |
---|
| 26 | ############################################################################ |
---|
| 27 | # Returns the message of the prompt |
---|
| 28 | 'message', |
---|
| 29 | ############################################################################ |
---|
| 30 | # Returns the of the prompt |
---|
| 31 | 'type', |
---|
| 32 | ############################################################################ |
---|
| 33 | # Returns the default return value |
---|
| 34 | 'default', |
---|
| 35 | ) { |
---|
| 36 | no strict qw{refs}; |
---|
| 37 | my $getter = "get_$key"; |
---|
| 38 | *$getter = sub { |
---|
| 39 | my ($self) = @_; |
---|
| 40 | return $self->{$key}; |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | ################################################################################ |
---|
| 45 | # Invokes the getter |
---|
| 46 | sub invoke { |
---|
| 47 | my ($self) = @_; |
---|
| 48 | croak("Fcm::Interactive::InputGetter->invoke() not implemented."); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | 1; |
---|
| 52 | __END__ |
---|
| 53 | |
---|
| 54 | =head1 NAME |
---|
| 55 | |
---|
| 56 | Fcm::Interactive::TxtInputGetter |
---|
| 57 | |
---|
| 58 | =head1 SYNOPSIS |
---|
| 59 | |
---|
| 60 | use Fcm::Interactive::TxtInputGetter; |
---|
| 61 | $answer = Fcm::Interactive::get_input( |
---|
| 62 | title => 'My title', |
---|
| 63 | message => 'Would you like to ...?', |
---|
| 64 | type => 'yn', |
---|
| 65 | default => 'n', |
---|
| 66 | ); |
---|
| 67 | |
---|
| 68 | =head1 DESCRIPTION |
---|
| 69 | |
---|
| 70 | An object of this abstract class is used by |
---|
| 71 | L<Fcm::Interactive|Fcm::Interactive> to get a user reply. |
---|
| 72 | |
---|
| 73 | =head1 METHODS |
---|
| 74 | |
---|
| 75 | =over 4 |
---|
| 76 | |
---|
| 77 | =item new($args_ref) |
---|
| 78 | |
---|
| 79 | Constructor, normally invoked via L<Fcm::Interactive|Fcm::Interactive>. |
---|
| 80 | |
---|
| 81 | Input options are: I<title>, for a short title of the prompt, I<message>, for |
---|
| 82 | the message prompt, I<type> for the prompt type, and I<default> for the default |
---|
| 83 | value of the return value. |
---|
| 84 | |
---|
| 85 | Prompt type can be YN (yes or no), YNA (yes, no or all) or input (for an input |
---|
| 86 | string). |
---|
| 87 | |
---|
| 88 | =item get_title() |
---|
| 89 | |
---|
| 90 | Returns the title of the prompt. |
---|
| 91 | |
---|
| 92 | =item get_message() |
---|
| 93 | |
---|
| 94 | Returns the message of the prompt. |
---|
| 95 | |
---|
| 96 | =item get_type() |
---|
| 97 | |
---|
| 98 | Returns the type of the prompt, can be YN (yes or no), YNA (yes, no or all) or |
---|
| 99 | input (for an input string). |
---|
| 100 | |
---|
| 101 | =item get_default() |
---|
| 102 | |
---|
| 103 | Returns the default return value of invoke(). |
---|
| 104 | |
---|
| 105 | =item invoke() |
---|
| 106 | |
---|
| 107 | Gets an input string from the user, and returns it. Sub-classes must override |
---|
| 108 | this method. |
---|
| 109 | |
---|
| 110 | =back |
---|
| 111 | |
---|
| 112 | =head1 SEE ALSO |
---|
| 113 | |
---|
| 114 | L<Fcm::Interactive|Fcm::Interactive>, |
---|
| 115 | L<Fcm::Interactive::TxtInputGetter|Fcm::Interactive::TxtInputGetter>, |
---|
| 116 | L<Fcm::Interactive::GUIInputGetter|Fcm::Interactive::GUIInputGetter> |
---|
| 117 | |
---|
| 118 | =head1 COPYRIGHT |
---|
| 119 | |
---|
| 120 | E<169> Crown copyright Met Office. All rights reserved. |
---|
| 121 | |
---|
| 122 | =cut |
---|