Perform/Forms.pm untested

filter: Statementstmt 0.0% 0 / 73 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 108 CC 13 SCAR 49.4
CC
13
Cov
0%
execute
182.0
BEGIN
2.0
BEGIN
2.0
CRAP 139.6
1  
2 package DBIx::Perform::Forms;
3  
4 use strict;
5  
6 use base qw(Curses::Forms);
7  
8 use Curses; # for KEY_STAB
9 use Carp;
10  
11 # Altered version of execute to let us move backward.
12 sub execute {
13 my $self = shift;
14 my $mwh = shift;
15 my $conf = $self->{CONF};
16 my @taborder = @{$$conf{TABORDER}};
17 my $widgets = $self->{WIDGETS};
18 my $subforms = $self->{SUBFORMS};
19 my $focused = $$conf{FOCUSED} || $taborder[0] || undef;
20 my %taborder = map {($taborder[$_], $_)} (0..$#taborder); # name look-up
21 my ($i, $obj, $key, $oderived, $dwh, $cwh);
22  
23 # Create the window if this is not a derived window
24 unless ($$conf{DERIVED}) {
25 $mwh = $self->_formwin;
26 $self->{LEVEL} = 1;
27  
28 # Save the old value of DESTORY and temporarily set it to false
29 $oderived = $$conf{DERIVED};
30 $$conf{DERIVED} = 1;
31  
32 # Call ourself again
33 $key = $self->execute($mwh);
34 $self->_relwin();
35  
36 # Restore the DERIVED value and exit
37 $$conf{DERIVED} = $oderived;
38 $self->{LEVEL} = 0;
39 return $key;
40 }
41  
42 # Take an early exit if there's nothing listed in the tab order
43 unless ($#taborder > -1) {
44 carp ref($self), ": Must have a widget to give focus to!";
45 return 0;
46 }
47  
48 # Set the EXIT flag to false
49 $$conf{EXIT} = 0;
50  
51 # Find the index of the focused widget
52 # $i = 0;
53 # until ($i > $#taborder || $focused eq $taborder[$i]) {
54 # ++$i;
55 # }
56 # $i = 0 if $i > $#taborder;
57 $i = $taborder{$focused};
58  
59 $self->{MWH} = $mwh;
60 $dwh = $self->_canvas($mwh, $self->_geometry);
61 $self->_init($dwh);
62 $cwh = $self->_canvas($dwh, $self->_cgeometry);
63 $cwh->keypad(1);
64 Curses::define_key("\c[[Z", KEY_STAB); # for some reason not recognized.
65 Curses::timeout(250); # quarter-second wait for ESC sequence.
66 Curses::raw(); # catch ctrl-C
67  
68 $self->draw($mwh, 1); # draw form at beginning of execute.
69  
70 # Start the loop
71 while (1) {
72  
73 $obj = exists $$widgets{$taborder[$i]} ? $$widgets{$taborder[$i]} :
74 $$subforms{$taborder[$i]};
75 $focused = $$conf{FOCUSED} = $taborder[$i];
76  
77 unless (defined $obj) {
78 carp ref($self), ": No such form or widget to focus!";
79 return 0;
80 }
81  
82 # Draw the form (not)
83 #$self->draw($mwh, 1);
84  
85 # Call the OnEnter routine if present
86 &{$obj->{OnEnter}}($self) if defined $obj->{OnEnter};
87  
88 # Execute
89 $key = $obj->execute($cwh);
90 # $self->draw($mwh);
91  
92 # Call the OnExit routine if present
93 &{$obj->{OnExit}}($self, $key) if defined $obj->{OnExit};
94 $obj->draw($cwh); # un-cursor it.
95  
96 # Exit if specified
97 last if $$conf{EXIT};
98  
99 my $newfocus = $$conf{FOCUSED};
100 if ($newfocus ne $focused) {
101 # Whoa! Focus warp.
102 $i = $taborder{$newfocus};
103 $focused = $newfocus;
104 }
105 # Otherwise, move the focus where appropriate
106 elsif (!$$conf{DONTSWITCH}) {
107 $i += $key eq KEY_STAB ? -1 : 1;
108 }
109 $$conf{DONTSWITCH} = 0;
110 $i = 0 if $i > $#taborder;
111 $i = $#taborder if $i < 0;
112  
113 # Exit if this is the last widget on a subform
114 # NOT IN PERFORM, WE DON'T.
115 # last if ($$conf{SUBFORM} && $focused eq $taborder[$#taborder]);
116 }
117  
118 $cwh->delwin;
119 $dwh->delwin;
120  
121 # Reset the EXIT and DESTROY flags
122 $$conf{EXIT} = 0;
123 $$conf{FOCUSED} = $taborder[$i];
124  
125 return $key;
126 }
127  
128 # sub drawField
129 # {
130 # my $self = shift;
131 # my $fieldname = shift;
132 # my $draw_cursor = shift;
133 # $draw_cursor = 1 unless defined($draw_cursor);
134  
135 # my $widg = $self->getWidget($fieldname);
136 # my $dwh = $self->_canvas($mwh, $self->_geometry);
137
138 # my $cwh = $self->_canvas($dwh, $self->_cgeometry);
139  
140 # }
141 1;