| 1 | package CGI::Test::Form::Widget::Menu::Popup; | ||||||||||
| 2 | 14 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 14 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | ################################################################## | ||||||||||
| 5 | # $Id: Popup.pm 411 2011-09-26 11:19:30Z nohuhu@nohuhu.org $ | ||||||||||
| 6 | # $Name: cgi-test_0-104_t1 $ | ||||||||||
| 7 | ################################################################## | ||||||||||
| 8 | # | ||||||||||
| 9 | # Copyright (c) 2001, Raphael Manfredi | ||||||||||
| 10 | # | ||||||||||
| 11 | # You may redistribute only under the terms of the Artistic License, | ||||||||||
| 12 | # as specified in the README file that comes with the distribution. | ||||||||||
| 13 | # | ||||||||||
| 14 | |||||||||||
| 15 | 14 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | # | ||||||||||
| 18 | # This class models a FORM popup menu. | ||||||||||
| 19 | # | ||||||||||
| 20 | |||||||||||
| 21 | 14 | ▶ | use base qw(CGI::Test::Form::Widget::Menu); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | # | ||||||||||
| 24 | # %attr | ||||||||||
| 25 | # | ||||||||||
| 26 | # Defines which HTML attributes we should look at within the node, and how | ||||||||||
| 27 | # to translate that into class attributes. | ||||||||||
| 28 | # | ||||||||||
| 29 | |||||||||||
| 30 | 14 | my %attr = ('name' => 'name', | |||||||||
| 31 | 'disabled' => 'is_disabled',); | ||||||||||
| 32 | |||||||||||
| 33 | # | ||||||||||
| 34 | # ->_init | ||||||||||
| 35 | # | ||||||||||
| 36 | # Per-widget initialization routine. | ||||||||||
| 37 | # Parse HTML node to determine our specific parameters. | ||||||||||
| 38 | # | ||||||||||
| 39 | sub _init | ||||||||||
| 40 | 16 | ▶ | { | ||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 16 | my $this = shift; | |||||||||
| 42 | 16 | my ($node) = shift; | |||||||||
| 43 | 16 | $this->_parse_attr($node, \%attr); | |||||||||
| 44 | 16 | $this->_parse_options($node); | |||||||||
| 45 | 16 | return; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | # | ||||||||||
| 49 | # ->set_selected -- redefined | ||||||||||
| 50 | # | ||||||||||
| 51 | # Change "selected" status for a menu value. | ||||||||||
| 52 | # We can only "select" values from a popup, never unselect one. | ||||||||||
| 53 | # | ||||||||||
| 54 | sub set_selected | ||||||||||
| 55 | 6 | ▶ | { | ||||||||
|
Subroutine
set_selected: called CC=2 SCAR=7.9
Pod
documented
| |||||||||||
| 56 | 6 | my $this = shift; | |||||||||
| 57 | 6 | my ($value, $state) = @_; | |||||||||
| 58 | |||||||||||
| 59 | 6 | ▶ | unless ($state) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | { | ||||||||||
| 61 | 0 | carp "cannot unselect value \"%s\" from popup $this", $value; | |||||||||
| 62 | 0 | return; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 6 | return $this->SUPER::set_selected($value, $state); | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | # | ||||||||||
| 69 | # Attribute access | ||||||||||
| 70 | # | ||||||||||
| 71 | |||||||||||
| 72 | sub gui_type | ||||||||||
| 73 | 0 | ▶ | { | ||||||||
|
Subroutine
gui_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 74 | 0 | return "popup menu"; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | # | ||||||||||
| 78 | # Defined predicates | ||||||||||
| 79 | # | ||||||||||
| 80 | |||||||||||
| 81 | sub is_popup | ||||||||||
| 82 | 1 | ▶ | { | ||||||||
|
Subroutine
is_popup: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 83 | 1 | return 1; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 14 | 1; | |||||||||
| 87 | |||||||||||
| 88 | =head1 NAME | ||||||||||
| 89 | |||||||||||
| 90 | CGI::Test::Form::Widget::Menu::Popup - A popup menu | ||||||||||
| 91 | |||||||||||
| 92 | =head1 SYNOPSIS | ||||||||||
| 93 | |||||||||||
| 94 | # Inherits from CGI::Test::Form::Widget::Menu | ||||||||||
| 95 | # $form is a CGI::Test::Form | ||||||||||
| 96 | |||||||||||
| 97 | my $action = $form->menu_by_name("action"); | ||||||||||
| 98 | $action->select("reboot"); | ||||||||||
| 99 | |||||||||||
| 100 | =head1 DESCRIPTION | ||||||||||
| 101 | |||||||||||
| 102 | This class models a popup menu, from which one item at most may be selected, | ||||||||||
| 103 | and for which there is at least one item selected, i.e. where exactly one | ||||||||||
| 104 | item is chosen. | ||||||||||
| 105 | |||||||||||
| 106 | If no item was explicitely selected, C<CGI::Test> arbitrarily chooses the | ||||||||||
| 107 | first item in the popup (if not empty) and warns you via C<warn>. | ||||||||||
| 108 | |||||||||||
| 109 | =head1 INTERFACE | ||||||||||
| 110 | |||||||||||
| 111 | The interface is the same as the one described in | ||||||||||
| 112 | L<CGI::Test::Form::Widget::Menu>. | ||||||||||
| 113 | |||||||||||
| 114 | =head1 AUTHORS | ||||||||||
| 115 | |||||||||||
| 116 | The original author is Raphael Manfredi. | ||||||||||
| 117 | |||||||||||
| 118 | Steven Hilton was long time maintainer of this module. | ||||||||||
| 119 | |||||||||||
| 120 | Current maintainer is Alexander Tokarev F<E<lt>tokarev@cpan.orgE<gt>>. | ||||||||||
| 121 | |||||||||||
| 122 | =head1 SEE ALSO | ||||||||||
| 123 | |||||||||||
| 124 | CGI::Test::Form::Widget::Menu(3). | ||||||||||
| 125 | |||||||||||
| 126 | =cut | ||||||||||
| 127 | |||||||||||