[UP] Events
|
The representation of events in Perl Events are represented as arrays whose components contain the properties of the events.
Note that the first component is always the type of the event and that the second component is always the name of the event (if any). This constraint will even hold if the list of possible events will be extended in the future. Handling events The handle method of the current dialog object is called when the event has been triggered. The method event can be used to find out the last event, e.g. sub handle { my ($self) = shift; my @e = $self->event; my $e_name = $e[1]; # the second component is the name if ($e_name eq 'this_button') { ... } elsif ($e_name eq 'that_button') { ... } elsif ($e_name eq 'clicked_icon') { my $x = $e[2]; my $y = $e[3]; ... } else { # It is recommended to do nothing as default case }; return undef; # Important! }The value returned by the handle method determines the action performed after the event has been processed. An undefined value means to display the same page again. Note that you must include a return undef statement as last statement of the method; otherwise the value that happens to be at the top of the value stack is returned. Alternatively, another page can be set by returning the name of the page as string (return 'other_page'). Last but not least it is also possible to change completely to a different dialog instance by returning the reference to the dialog. Example: sub handle { my ($self) = shift; my @e = $self->event; my $e_name = $e[1]; # the second component is the name if ($e_name eq 'this_button') { $self->set_string_variable("xy", "wow"); return undef; } elsif ($e_name eq 'that_button') { $self->set_string_variable("xy", "boo"); return "another_page"; } elsif ($e_name eq 'clicked_icon') { my $next_dlg = UI::Universe::create("other_dialog"); return $next_dlg; } else { # It is recommended to do nothing as default case }; return undef; # Important! } |