InputGetter.pm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. package Fcm::Interactive::InputGetter;
  9. use Carp qw{croak};
  10. ################################################################################
  11. # Constructor
  12. sub new {
  13. my ($class, $args_ref) = @_;
  14. return bless({%{$args_ref}}, $class);
  15. }
  16. ################################################################################
  17. # Methods: get_*
  18. for my $key (
  19. ############################################################################
  20. # Returns the title of the prompt
  21. 'title',
  22. ############################################################################
  23. # Returns the message of the prompt
  24. 'message',
  25. ############################################################################
  26. # Returns the of the prompt
  27. 'type',
  28. ############################################################################
  29. # Returns the default return value
  30. 'default',
  31. ) {
  32. no strict qw{refs};
  33. my $getter = "get_$key";
  34. *$getter = sub {
  35. my ($self) = @_;
  36. return $self->{$key};
  37. }
  38. }
  39. ################################################################################
  40. # Invokes the getter
  41. sub invoke {
  42. my ($self) = @_;
  43. croak("Fcm::Interactive::InputGetter->invoke() not implemented.");
  44. }
  45. 1;
  46. __END__
  47. =head1 NAME
  48. Fcm::Interactive::TxtInputGetter
  49. =head1 SYNOPSIS
  50. use Fcm::Interactive::TxtInputGetter;
  51. $answer = Fcm::Interactive::get_input(
  52. title => 'My title',
  53. message => 'Would you like to ...?',
  54. type => 'yn',
  55. default => 'n',
  56. );
  57. =head1 DESCRIPTION
  58. An object of this abstract class is used by
  59. L<Fcm::Interactive|Fcm::Interactive> to get a user reply.
  60. =head1 METHODS
  61. =over 4
  62. =item new($args_ref)
  63. Constructor, normally invoked via L<Fcm::Interactive|Fcm::Interactive>.
  64. Input options are: I<title>, for a short title of the prompt, I<message>, for
  65. the message prompt, I<type> for the prompt type, and I<default> for the default
  66. value of the return value.
  67. Prompt type can be YN (yes or no), YNA (yes, no or all) or input (for an input
  68. string).
  69. =item get_title()
  70. Returns the title of the prompt.
  71. =item get_message()
  72. Returns the message of the prompt.
  73. =item get_type()
  74. Returns the type of the prompt, can be YN (yes or no), YNA (yes, no or all) or
  75. input (for an input string).
  76. =item get_default()
  77. Returns the default return value of invoke().
  78. =item invoke()
  79. Gets an input string from the user, and returns it. Sub-classes must override
  80. this method.
  81. =back
  82. =head1 SEE ALSO
  83. L<Fcm::Interactive|Fcm::Interactive>,
  84. L<Fcm::Interactive::TxtInputGetter|Fcm::Interactive::TxtInputGetter>,
  85. L<Fcm::Interactive::GUIInputGetter|Fcm::Interactive::GUIInputGetter>
  86. =head1 COPYRIGHT
  87. E<169> Crown copyright Met Office. All rights reserved.
  88. =cut