line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UI::Various::PoorTerm::Box; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Author, Copyright and License: see end of file |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
UI::Various::PoorTerm::Box - 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::Box; |
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
|
|
18
|
use v5.14; |
|
2
|
|
|
|
|
5
|
|
31
|
2
|
|
|
2
|
|
8
|
use strictures; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
32
|
2
|
|
|
2
|
|
252
|
no indirect 'fatal'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
33
|
2
|
|
|
2
|
|
90
|
no multidimensional; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
34
|
2
|
|
|
2
|
|
61
|
use warnings 'once'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
86
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '0.23'; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
2
|
|
10
|
use UI::Various::core; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
14
|
|
39
|
2
|
|
|
2
|
|
10
|
use UI::Various::Box; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
59
|
|
40
|
2
|
|
|
2
|
|
605
|
use UI::Various::PoorTerm::container; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1839
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
require Exporter; |
43
|
|
|
|
|
|
|
our @ISA = qw(UI::Various::Box UI::Various::PoorTerm::container); |
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 the complete box by printing a separator (blank line unless the border |
70
|
|
|
|
|
|
|
should be visible) and its indented content. If the box is not indented, |
71
|
|
|
|
|
|
|
its active elements are numbered to allow later interaction with them. |
72
|
|
|
|
|
|
|
I
|
73
|
|
|
|
|
|
|
action of UI element>> or a I::Various::PoorTerm container element!> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _show($$) |
80
|
|
|
|
|
|
|
{ |
81
|
39
|
|
|
39
|
|
8282
|
my ($self, $prefix) = @_; |
82
|
39
|
100
|
|
|
|
90
|
defined $prefix or $prefix = ''; |
83
|
39
|
|
|
|
|
82
|
my $blank = ' ' x length($prefix); |
84
|
39
|
|
|
|
|
46
|
local $_; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# The number of '_show' parents' calls is the indention level: |
87
|
39
|
|
|
|
|
46
|
my $level = 0; |
88
|
39
|
|
|
|
|
103
|
$level++ while (caller($level + 1))[3] =~ m/::_show$/; |
89
|
39
|
100
|
|
|
|
1237
|
my $indent = $level <= 1 ? '' : ' '; |
90
|
39
|
100
|
|
|
|
121
|
my $border = $self->border ? '----------' : ''; |
91
|
|
|
|
|
|
|
|
92
|
39
|
100
|
|
|
|
575
|
$prefix ne '' and print $indent, $prefix, $border, "\n"; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# 1st gather active children and get width of prefix: |
95
|
39
|
|
|
|
|
119
|
$self->{_active} = []; |
96
|
39
|
|
|
|
|
184
|
while ($_ = $self->child) |
97
|
|
|
|
|
|
|
{ |
98
|
86
|
100
|
|
|
|
252
|
$_->can('_process') and push @{$self->{_active}}, $_; |
|
61
|
|
|
|
|
140
|
|
99
|
|
|
|
|
|
|
} |
100
|
39
|
|
|
|
|
52
|
my $active = @{$self->{_active}}; |
|
39
|
|
|
|
|
53
|
|
101
|
39
|
|
|
|
|
58
|
$_ = length($active); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# print children: |
104
|
39
|
|
|
|
|
70
|
my $pre_active = '<%' . $_ . 'd> '; |
105
|
39
|
|
|
|
|
74
|
my $pre_passive = ' ' x ($_ + 3); |
106
|
39
|
|
|
|
|
52
|
my $i = 1; |
107
|
39
|
|
|
|
|
86
|
foreach my $row (0..($self->rows - 1)) |
108
|
|
|
|
|
|
|
{ |
109
|
58
|
|
|
|
|
163
|
foreach my $column (0..($self->columns - 1)) |
110
|
|
|
|
|
|
|
{ |
111
|
102
|
|
|
|
|
242
|
$_ = $self->field($row, $column); |
112
|
102
|
100
|
|
|
|
167
|
next unless defined $_; |
113
|
86
|
|
|
|
|
121
|
my $pre_child = $indent; |
114
|
86
|
100
|
|
|
|
222
|
if ($prefix =~ m/[^ ]/) |
|
|
100
|
|
|
|
|
|
115
|
|
|
|
|
|
|
{ |
116
|
32
|
100
|
100
|
|
|
106
|
if ($active == 1 and $_->can('_process')) |
117
|
9
|
|
|
|
|
16
|
{ $pre_child .= '<*> '; } |
118
|
|
|
|
|
|
|
else |
119
|
23
|
|
|
|
|
35
|
{ $pre_child .= $blank; } |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
elsif ($prefix eq '') |
122
|
|
|
|
|
|
|
{ |
123
|
42
|
100
|
|
|
|
178
|
$pre_child .= $_->can('_process') |
124
|
|
|
|
|
|
|
? sprintf($pre_active, $i++) : $pre_passive; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
else |
127
|
12
|
|
|
|
|
17
|
{ $pre_child .= $blank; } |
128
|
86
|
|
|
|
|
220
|
$_->_show($pre_child); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# finish as child or master of selection: |
133
|
39
|
100
|
|
|
|
140
|
if ($prefix ne '') |
134
|
|
|
|
|
|
|
{ |
135
|
22
|
|
|
|
|
245
|
print $indent, $blank, $border, "\n"; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else |
138
|
|
|
|
|
|
|
{ |
139
|
|
|
|
|
|
|
# print standard selection strings: |
140
|
17
|
|
|
|
|
90
|
print $self->_wrap(sprintf($pre_active, 0), msg('leave_box')), "\n\n"; |
141
|
17
|
|
|
|
|
68
|
print $self->_wrap('----- ', |
142
|
|
|
|
|
|
|
msg('enter_number_to_choose_next_step')), ': '; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
######################################################################### |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 B<_process> - handle action of UI element |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$ui_element->_process; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head3 description: |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Handle the action of the UI element. For a C's box this means: If |
155
|
|
|
|
|
|
|
the box has no active element, just return. If it has exactly one active |
156
|
|
|
|
|
|
|
element, the active element is processed directly. Otherwise the method |
157
|
|
|
|
|
|
|
iterates through a loop of printing the box's elements and allowing to |
158
|
|
|
|
|
|
|
select one of the active ones for processing until the box is exited. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _process($) |
165
|
|
|
|
|
|
|
{ |
166
|
5
|
|
|
5
|
|
4181
|
debug(3, __PACKAGE__, '::_process'); |
167
|
5
|
|
|
|
|
11
|
my ($self) = @_; |
168
|
|
|
|
|
|
|
|
169
|
5
|
|
|
|
|
9
|
my $active = @{$self->{_active}}; |
|
5
|
|
|
|
|
13
|
|
170
|
5
|
100
|
|
|
|
20
|
$active == 1 and $self->{_active}->[0]->_process; |
171
|
5
|
100
|
|
|
|
61
|
$active <= 1 and return 0; |
172
|
|
|
|
|
|
|
|
173
|
3
|
|
|
|
|
6
|
while (1) |
174
|
|
|
|
|
|
|
{ |
175
|
11
|
|
|
|
|
80
|
$self->_show; |
176
|
11
|
|
|
|
|
51
|
local $_ = ; |
177
|
11
|
|
|
|
|
75
|
print $_; |
178
|
11
|
|
|
|
|
70
|
s/\r?\n$//; |
179
|
11
|
100
|
|
|
|
40
|
return $_ if m/^0$/; |
180
|
8
|
100
|
100
|
|
|
31
|
unless ($_ =~ m/^\d+$/ and $_ <= @{$self->{_active}}) |
|
7
|
|
|
|
|
28
|
|
181
|
2
|
|
|
|
|
9
|
{ error('invalid_selection'); next; } |
|
2
|
|
|
|
|
4
|
|
182
|
6
|
|
|
|
|
29
|
$self->{_active}->[$_-1]->_process; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
######################################################################### |
189
|
|
|
|
|
|
|
######################################################################### |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 SEE ALSO |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
L, L |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 LICENSE |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Copyright (C) Thomas Dorner. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
200
|
|
|
|
|
|
|
under the same terms as Perl itself. See LICENSE file for more details. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 AUTHOR |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Thomas Dorner Edorner (at) cpan (dot) orgE |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |