Test/Form/Widget/Box/Radio.pm

filter: Statementstmt 88.0% 22 / 25 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 5 / 5 totaltotal 83.7% 36 / 43 CC 4 SCAR 8.1
CC
4
Cov
86%
set_is_checked
4.0
uncheck
2.0
uncheck_tagged
2.0
CRAP 2.3
« Test/Form/Widget.pm ↑ Summary Test/Page/Other.pm »
1 package CGI::Test::Form::Widget::Box::Radio;
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: 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 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 #
18 # This class models a FORM radio button.
19 #
20  
21 14 ▶use base qw(CGI::Test::Form::Widget::Box);
Subroutine BEGIN: called CC=1 SCAR=0.0
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 6 ▶{
Subroutine set_is_checked: called CC=4 SCAR=13.9
Pod documented
34 6 my $this = shift;
35 6 my ($checked) = @_;
36  
37 6 ▶ return if !$checked == !$this->is_checked(); # No change
Branch: 1 branch
BranchTrueFalseTotal
if !$checked == !$this->is_checked 0 6 6
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 $this->_frozen_set_is_checked($checked);
45 6 foreach my $radio ($this->group_list)
46 {
47 18 ▶ next if $radio == $this;
Branch: 1 branch
BranchTrueFalseTotal
if $radio == $this 6 12 18
48 12 $radio->_frozen_set_is_checked(0);
49 }
50  
51 6 return;
52 }
53  
54 sub uncheck
55 0 ▶{
Subroutine uncheck: not called CC=1 SCAR=6.9
Pod documented
56 0 carp "ignoring uncheck on radio button";
57 }
58  
59 sub uncheck_tagged
60 0 ▶{
Subroutine uncheck_tagged: not called CC=1 SCAR=6.9
Pod documented
61 0 carp "ignoring uncheck_tagged on radio button";
62 }
63  
64 #
65 # Attribute access
66 #
67  
68 sub gui_type
69 0 ▶{
Subroutine gui_type: not called CC=1 SCAR=6.9
Pod documented
70 0 return "radio button";
71 }
72  
73 #
74 # Defined predicates
75 #
76  
77 sub is_radio
78 16 ▶{
Subroutine is_radio: called CC=1 SCAR=0.0
Pod documented
79 16 return 1;
80 }
81  
82 14 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<CGI::Test> arbitrarily chooses
107 the first one listed and warns you via C<warn>.
108  
109 The interface is the same as the one described
110 in L<CGI::Test::Form::Widget::Box>.
111  
112 Any attempt to C<uncheck> a radio button will be ignored, and a warning
113 emitted via C<carp>, 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 F<E<lt>tokarev@cpan.orgE<gt>>.
122  
123 =head1 SEE ALSO
124  
125 CGI::Test::Form::Widget::Box(3), CGI::Test::Form::Widget::Box::Check(3).
126  
127 =cut
128  
« Test/Form/Widget.pm ↑ Summary Test/Page/Other.pm »