/usr/share/perl5/CGI/Test/Form/Widget/Box.pm is in libcgi-test-perl 1.111-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | package CGI::Test::Form::Widget::Box;
use strict;
use warnings;
##################################################################
# $Id: Box.pm 411 2011-09-26 11:19:30Z nohuhu@nohuhu.org $
# $Name: cgi-test_0-104_t1 $
##################################################################
# Copyright (c) 2001, Raphael Manfredi
#
# You may redistribute only under the terms of the Artistic License,
# as specified in the README file that comes with the distribution.
#
use Carp;
#
# This class models a FORM box, either a radio button or a checkbox.
#
use base qw(CGI::Test::Form::Widget);
############################################################
#
# %attr
#
# Defines which HTML attributes we should look at within the node, and how
# to translate that into class attributes.
#
############################################################
my %attr = ('name' => 'name',
'value' => 'value',
'checked' => 'is_checked',
'disabled' => 'is_disabled',
);
############################################################
#
# ->_init
#
# Per-widget initialization routine.
# Parse HTML node to determine our specific parameters.
#
############################################################
sub _init
{
my $this = shift;
my ($node) = shift;
$this->_parse_attr($node, \%attr);
return;
}
############################################################
#
# ->_is_successful -- defined
#
# Is the enabled widget "successful", according to W3C's specs?
# Any ticked checkbox and radio button is.
#
############################################################
sub _is_successful
{
my $this = shift;
return $this->is_checked();
}
############################################################
#
# ->group_list
#
# Returns list of widgets belonging to the same group as we do.
#
############################################################
sub group_list
{
my $this = shift;
return $this->group->widgets_in($this->name);
}
#
# Local attribute access
#
############################################################
sub group
{
my $this = shift;
return $this->{group};
}
############################################################
sub is_checked
{
my $this = shift;
return $this->{is_checked};
}
############################################################
sub old_is_checked
{
my $this = shift;
$this->{old_is_checked};
}
#
# Checking shortcuts
#
############################################################
sub check
{
my $this = shift;
$this->set_is_checked(1);
}
############################################################
sub uncheck
{
my $this = shift;
$this->set_is_checked(0);
}
############################################################
sub check_tagged
{
my $this = shift;
my $tag = shift;
$this->_mark_by_tag($tag, 1);
}
############################################################
sub uncheck_tagged
{
my $this = shift;
my $tag = shift;
$this->_mark_by_tag($tag, 0);
}
#
# Attribute setting
#
############################################################
sub set_group
{
my $this = shift;
my $group = shift;
$this->{group} = $group;
}
############################################################
#
# ->set_is_checked
#
# Select or unselect box.
#
############################################################
sub set_is_checked
{
my $this = shift;
my ($checked) = @_;
return if !$checked == !$this->is_checked(); # No change
#
# To ease redefinition, let this call _frozen_set_is_checked, which is
# not redefinable and performs the common operation.
#
$this->_frozen_set_is_checked($checked);
return;
}
############################################################
#
# ->reset_state -- redefined
#
# Called when a "Reset" button is pressed to restore the value the widget
# had upon form entry.
#
############################################################
sub reset_state
{
my $this = shift;
$this->{is_checked} = delete $this->{old_is_checked}
if exists $this->{old_is_checked};
return;
}
#
# Global widget predicates
#
############################################################
sub is_read_only
{
return 1;
}
#
# High-level classification predicates
#
############################################################
sub is_box
{
return 1;
}
#
# Predicates for the Box hierarchy
#
############################################################
sub is_radio
{
confess "deferred";
}
############################################################
sub is_standalone
{
my $this = shift;
1 == $this->group->widget_count($this->name());
}
#
# ->delete
#
# Break circular refs.
#
sub delete
{
my $this = shift;
delete $this->{group};
$this->SUPER::delete;
return;
}
#
# ->_frozen_set_is_checked
#
# Frozen implementation of set_is_checked().
#
sub _frozen_set_is_checked
{
my $this = shift;
my ($checked) = @_;
#
# The first time we do this, save current status in `old_is_checked'.
#
$this->{old_is_checked} = $this->{is_checked}
unless exists $this->{old_is_checked};
$this->{is_checked} = $checked;
return;
}
############################################################
#
# ->_mark_by_tag
#
# Lookup the box in the group whose name is the given tag, and mark it
# as specified.
#
############################################################
sub _mark_by_tag
{
my $this = shift;
my ($tag, $checked) = @_;
my @boxes = grep {$_->value eq $tag} $this->group_list();
if (@boxes == 0)
{
carp "no %s within the group '%s' bears the tag \"$tag\"",
$this->gui_type(), $this->name();
}
else
{
carp "found %d %ss within the group '%s' bearing the tag \"$tag\"",
scalar(@boxes), $this->gui_type(), $this->name()
if @boxes > 1;
$boxes[ 0 ]->set_is_checked($checked);
}
return;
}
1;
=head1 NAME
CGI::Test::Form::Widget::Box - Abstract representation of a tickable box
=head1 SYNOPSIS
# Inherits from CGI::Test::Form::Widget
=head1 DESCRIPTION
This class is the abstract representation of a tickable box, i.e. a radio
button or a checkbox.
To simulate user checking or un-checking on a box,
use the C<check()> and C<uncheck()> routines, as described below.
=head1 INTERFACE
The interface is the same as the one described in L<CGI::Test::Form::Widget>,
with the following additions:
=head2 Attributes
=over 4
=item C<group>
The C<CGI::Test::Form::Group> object which holds all the groups of the same
widget type.
=item C<group_list>
The list of widgets belonging to the same group as we do.
=item C<is_checked>
True when the box is checked, i.e. marked with a tick.
=back
=head2 Attribute Setting
=over 4
=item C<check>
Check the box, by ticking it.
=item C<check_tagged> I<tag>
This may be called on any box, and it will locate the box whose value
attribute is I<tag> within the C<group_list>, and then check it.
If the specified I<tag> is not found, the caller will get a warning
via C<carp>.
=item C<uncheck>
Uncheck the box, by removing its ticking mark.
It is not possible to do this on a radio button: you must I<check> another
radio button of the same group instead.
=item C<uncheck_tagged> I<tag>
This may be called on any box, and it will locate the box whose value
attribute is I<tag> within the C<group_list>, and then remove its ticking mark.
It is not possible to do this on a radio button, as explained in C<uncheck>
above.
If the specified I<tag> is not found, the caller will get a warning
via C<carp>.
=back
=head2 Widget Classification Predicates
There is an additional predicate to distinguish between a checkbox and
a radio button:
=over 4
=item C<is_radio>
Returns I<true> for a radio button.
=item C<is_standalone>
Returns I<true> if the box is the sole member of its group.
Normally only useful for checkboxes: a standalone radio button,
although perfectly legal, would always remain in the checked state, and
therefore not be especially interesting...
=back
=head2 Miscellaneous Features
Although documented, those features are more targetted for
internal use...
=over 4
=item C<set_is_checked> I<flag>
Change the checked status. Radio buttons can only be checked, i.e. the
I<flag> must be true: all other radio buttons in the same group are
immediately unchecked.
You should use the C<check> and C<uncheck> convenience routines instead
of calling this feature.
=back
=head1 AUTHORS
The original author is Raphael Manfredi.
Steven Hilton was long time maintainer of this module.
Current maintainer is Alexander Tokarev F<E<lt>tokarev@cpan.orgE<gt>>.
=head1 SEE ALSO
CGI::Test::Form::Widget(3),
CGI::Test::Form::Widget::Box::Radio(3),
CGI::Test::Form::Widget::Box::Check(3).
=cut
|