File Coverage

blib/lib/CGI/Test/Form/Widget/Box/Radio.pm
Criterion Covered Total %
statement 21 24 87.5
branch 3 4 75.0
condition n/a
subroutine 6 9 66.6
pod 5 5 100.0
total 35 42 83.3


line stmt bran cond sub pod time code
1             package CGI::Test::Form::Widget::Box::Radio;
2 14     14   42 use strict;
  14         14  
  14         279  
3 14     14   42 use warnings;
  14         9  
  14         248  
4             ##################################################################
5             # $Id: Radio.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     14   37 use Carp;
  14         14  
  14         620  
16              
17             #
18             # This class models a FORM radio button.
19             #
20              
21 14     14   42 use base qw(CGI::Test::Form::Widget::Box);
  14         15  
  14         5091  
22              
23             #
24             # ->set_is_checked -- redefined
25             #
26             # Change checked state.
27             #
28             # A radio button can only be "clicked on", i.e. it is not otherwise
29             # un-checkable. Therefore, $checked must always be true. Furthermore,
30             # all related radio buttons must be cleared.
31             #
32             sub set_is_checked
33             {
34 6     6 1 8 my $this = shift;
35 6         10 my ($checked) = @_;
36              
37 6 50       20 return if !$checked == !$this->is_checked(); # No change
38              
39             #
40             # We're checking a radio button that was cleared previously.
41             # All the other radio buttons in the group are going to be cleared.
42             #
43              
44 6         42 $this->_frozen_set_is_checked($checked);
45 6         16 foreach my $radio ($this->group_list)
46             {
47 18 100       56 next if $radio == $this;
48 12         26 $radio->_frozen_set_is_checked(0);
49             }
50              
51 6         12 return;
52             }
53              
54             sub uncheck
55             {
56 0     0 1 0 carp "ignoring uncheck on radio button";
57             }
58              
59             sub uncheck_tagged
60             {
61 0     0 1 0 carp "ignoring uncheck_tagged on radio button";
62             }
63              
64             #
65             # Attribute access
66             #
67              
68             sub gui_type
69             {
70 0     0 1 0 return "radio button";
71             }
72              
73             #
74             # Defined predicates
75             #
76              
77             sub is_radio
78             {
79 16     16 1 56 return 1;
80             }
81              
82             1;
83              
84             =head1 NAME
85              
86             CGI::Test::Form::Widget::Box::Radio - A radio button widget
87              
88             =head1 SYNOPSIS
89              
90             # Inherits from CGI::Test::Form::Widget::Box
91             # $form is a CGI::Test::Form
92              
93             my @title = $form->radios_named("title");
94             my ($mister) = grep { $_->value eq "Mr" } @title;
95             $mister->check if defined $mister;
96              
97             my $title = $form->radio_by_name("title");
98             $title->check_tagged("Mr");
99              
100             =head1 DESCRIPTION
101              
102             This class represents a radio button widget, which may be checked at
103             will by users. All other radio buttons of the same group are automatically
104             unchecked.
105              
106             If no radio button is checked initially, C arbitrarily chooses
107             the first one listed and warns you via C.
108              
109             The interface is the same as the one described
110             in L.
111              
112             Any attempt to C a radio button will be ignored, and a warning
113             emitted via C, to help you identify the caller.
114              
115             =head1 AUTHORS
116              
117             The original author is Raphael Manfredi.
118              
119             Steven Hilton was long time maintainer of this module.
120              
121             Current maintainer is Alexander Tokarev Ftokarev@cpan.orgE>.
122              
123             =head1 SEE ALSO
124              
125             CGI::Test::Form::Widget::Box(3), CGI::Test::Form::Widget::Box::Check(3).
126              
127             =cut
128