# # $Id: Input.pm,v 0.1 2001/03/31 10:54:02 ram Exp $ # # 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. # # HISTORY # $Log: Input.pm,v $ # Revision 0.1 2001/03/31 10:54:02 ram # Baseline for first Alpha release. # # $EndLog$ # use strict; package CGI::Test::Form::Widget::Input; # # This class models a FORM input field. # It factorizes the interface of our heirs: Text_Area and Text_Field # require CGI::Test::Form::Widget; use vars qw(@ISA); @ISA = qw(CGI::Test::Form::Widget); use Carp::Datum; use Log::Agent; # # ->_is_successful -- defined # # Is the enabled widget "successful", according to W3C's specs? # Any input is. # sub _is_successful { DFEATURE my $f_; my $self = shift; return DVAL 1; } # # Editing shortcuts # # The set_value() routine from the Widget class is protected against # disabled and read-only fields, so don't duplicate checks within these # shortcut routines. # # All are obvious, excepted filter perhaps, which runs a filtering subroutine # on the field's value, preset in $_: # # $i->filter(sub { s/this/that/ }); # # In the traditional Perl way... # sub prepend { $_[0]->set_value($_[1] . $_[0]->value) } sub append { $_[0]->set_value($_[0]->value . $_[1]) } sub replace { $_[0]->set_value($_[1]) } sub clear { $_[0]->set_value('') } sub filter { local $_ = $_[0]->value; &{$_[1]}; $_[0]->set_value($_) } # # Attribute access # sub is_read_only { $_[0]->{is_read_only} } # # High-level classification predicates # sub is_input { 1 } # # Predicates for the Input hierarchy # sub is_field { 0 } sub is_area { 0 } sub is_password { 0 } sub is_file { 0 } 1; =head1 NAME CGI::Test::Form::Widget::Input - Abstract representation of an input field =head1 SYNOPSIS # Inherits from CGI::Test::Form::Widget =head1 DESCRIPTION This class is the abstract representation of a text input field, i.e. a text field, a password field, a file upload field or a text area. To simulate user input in those fields, there are a set of routines to C, C, C, C or even run existing text through C. =head1 INTERFACE The interface is the same as the one described in L, with the following additions: =head2 Attribute Setting There are a number of convenience routines that are wrappers on C: =over 4 =item C I Appends the I text to the existing text. =item C Clears existing text. =item C I Runs existing text through the given I. The C<$_> variable is set to the whole text value, and is made available to the filter. Hence you may write: $input->filter(sub { s/this/that/g }); to replace all instances of C by C within the input text. =item C I Prepends the I text to the existing text. =item C I Replaces the existing text with I. =back =head2 Widget Classification Predicates There are additional predicates to distinguish between the various input fields: =over 4 =item C Returns I for a text area. =item C Returns I for a pure text field. =item C Returns I for a file upload field (text field with browser support for file selection). =item C Returns I for a password field (text field with input masked by GUI). =back =head1 AUTHOR Raphael Manfredi FRaphael_Manfredi@pobox.comE> =head1 SEE ALSO CGI::Test::Form::Widget(3), CGI::Test::Form::Widget::Input::File(3), CGI::Test::Form::Widget::Input::Password(3), CGI::Test::Form::Widget::Input::Text_Area(3), CGI::Test::Form::Widget::Input::Text_Field(3). =cut