| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package UI::Various::PoorTerm::Radio; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # Author, Copyright and License: see end of file | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =head1 NAME | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | UI::Various::PoorTerm::Radio - concrete implementation of L | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | # This module should never be used directly! | 
| 12 |  |  |  |  |  |  | # It is used indirectly via the following: | 
| 13 |  |  |  |  |  |  | use UI::Various::Radio; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 ABSTRACT | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | This module is the specific minimal fallback implementation of | 
| 18 |  |  |  |  |  |  | L.  It manages and hides everything specific to the last | 
| 19 |  |  |  |  |  |  | resort UI. | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | The documentation of this module is only intended for developers of the | 
| 24 |  |  |  |  |  |  | package itself. | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =cut | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | ######################################################################### | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 2 |  |  | 2 |  | 17 | use v5.14; | 
|  | 2 |  |  |  |  | 5 |  | 
| 31 | 2 |  |  | 2 |  | 9 | use strictures; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 8 |  | 
| 32 | 2 |  |  | 2 |  | 244 | no indirect 'fatal'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 7 |  | 
| 33 | 2 |  |  | 2 |  | 89 | no multidimensional; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 7 |  | 
| 34 | 2 |  |  | 2 |  | 55 | use warnings 'once'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 84 |  | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | our $VERSION = '0.23'; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 2 |  |  | 2 |  | 10 | use UI::Various::core; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 15 |  | 
| 39 | 2 |  |  | 2 |  | 10 | use UI::Various::Radio; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 58 |  | 
| 40 | 2 |  |  | 2 |  | 295 | use UI::Various::PoorTerm::base; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 1273 |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | require Exporter; | 
| 43 |  |  |  |  |  |  | our @ISA = qw(UI::Various::Radio UI::Various::PoorTerm::base); | 
| 44 |  |  |  |  |  |  | our @EXPORT_OK = qw(); | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | ######################################################################### | 
| 47 |  |  |  |  |  |  | ######################################################################### | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =head1 METHODS | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =cut | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | ######################################################################### | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =head2 B<_show> - print UI element | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | $ui_element->_show($prefix); | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head3 example: | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | $_->_show('(1) '); | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =head3 parameters: | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | $prefix             text in front of first line | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =head3 description: | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | Show (print) the UI element.  I | 
| 70 |  |  |  |  |  |  | UI::Various::PoorTerm container elements!> | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =cut | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | sub _show($$) | 
| 77 |  |  |  |  |  |  | { | 
| 78 | 5 |  |  | 5 |  | 6336 | my ($self, $prefix) = @_; | 
| 79 | 5 |  |  |  |  | 24 | my $blank = ' ' x length($prefix); | 
| 80 | 5 |  |  |  |  | 17 | my $var = $self->var; | 
| 81 | 5 | 100 |  |  |  | 16 | defined $var  or  $var = '$ ^ }!\\"{]}[%]'; # magic invalid string | 
| 82 | 5 |  |  |  |  | 9 | foreach my $i (0..$#{$self->{_button_keys}}) | 
|  | 5 |  |  |  |  | 15 |  | 
| 83 |  |  |  |  |  |  | { | 
| 84 | 29 | 100 |  |  |  | 95 | local $_ = ($i == 0 ? $prefix : $blank) . '('; | 
| 85 |  |  |  |  |  |  | # Note that the accessors automatically dereference the SCALARs here: | 
| 86 | 29 | 100 |  |  |  | 71 | $_ .= ($var  eq  $self->{_button_keys}[$i] ? 'o' : ' ') . ') '; | 
| 87 | 29 |  |  |  |  | 93 | print $self->_wrap($_, $self->{_button_values}[$i]), "\n"; | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | ######################################################################### | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | =head2 B<_process> - handle action of UI element | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | $ui_element->_process; | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =head3 description: | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | Handle the action of the UI element (aka select one of the radio buttons). | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =cut | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | sub _process($) | 
| 106 |  |  |  |  |  |  | { | 
| 107 | 3 |  |  | 3 |  | 5844 | my ($self) = @_; | 
| 108 |  |  |  |  |  |  |  | 
| 109 | 3 |  |  |  |  | 7 | my $max = @{$self->{_button_keys}}; | 
|  | 3 |  |  |  |  | 11 |  | 
| 110 | 3 |  |  |  |  | 11 | my $prefix = '<%' . length($max) . 'd> '; | 
| 111 | 3 |  |  |  |  | 5 | my $prompt = ''; | 
| 112 | 3 |  |  |  |  | 4 | foreach my $i (0..$#{$self->{_button_keys}}) | 
|  | 3 |  |  |  |  | 11 |  | 
| 113 |  |  |  |  |  |  | { | 
| 114 |  |  |  |  |  |  | $prompt .= $self->_wrap(sprintf($prefix, $i + 1), | 
| 115 | 16 |  |  |  |  | 59 | $self->{_button_values}[$i]); | 
| 116 | 16 |  |  |  |  | 25 | $prompt .= "\n"; | 
| 117 |  |  |  |  |  |  | } | 
| 118 | 3 |  |  |  |  | 14 | $prompt .= $self->_wrap('', | 
| 119 |  |  |  |  |  |  | msg('enter_selection') . | 
| 120 |  |  |  |  |  |  | ' (' . sprintf(msg('_1_to_cancel'), 0) . '): '); | 
| 121 |  |  |  |  |  |  |  | 
| 122 | 3 |  |  |  |  | 6 | local $_ = -1; | 
| 123 | 3 |  |  |  |  | 10 | while ($_ < 0) | 
| 124 |  |  |  |  |  |  | { | 
| 125 | 5 |  |  |  |  | 124 | print $prompt; | 
| 126 | 5 |  |  |  |  | 18 | $_ = ; | 
| 127 | 5 |  |  |  |  | 36 | print $_; | 
| 128 | 5 |  |  |  |  | 34 | s/\r?\n$//; | 
| 129 | 5 | 100 | 100 |  |  | 32 | unless (m/^\d+$/  and  $_ <= $max) | 
| 130 | 2 |  |  |  |  | 10 | {   error('invalid_selection');   $_ = -1;   next;   } | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 4 |  | 
| 131 | 3 | 100 |  |  |  | 13 | 0 < $_  and  ${$self->{var}} = $self->{_button_keys}[$_ - 1]; | 
|  | 2 |  |  |  |  | 10 |  | 
| 132 |  |  |  |  |  |  | } | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | 1; | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | ######################################################################### | 
| 138 |  |  |  |  |  |  | ######################################################################### | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | L, L | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | =head1 LICENSE | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | Copyright (C) Thomas Dorner. | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify it | 
| 149 |  |  |  |  |  |  | under the same terms as Perl itself.  See LICENSE file for more details. | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =head1 AUTHOR | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | Thomas Dorner Edorner (at) cpan (dot) orgE | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | =cut |