CGI-Test
view release on metacpan or search on metacpan
lib/CGI/Test/Form/Widget.pm view on Meta::CPAN
=item C<is_box>
Returns true for radio buttons and checkboxes.
=item C<is_button>
Returns true for all buttons that are not boxes.
=item C<is_file>
Returns true for a I<file upload> widget, which allows file selection.
=item C<is_hidden>
Returns true for hidden fields, which have no graphical representation
by definition.
=item C<is_input>
Returns true for all input fields, where the user can type text.
lib/CGI/Test/Form/Widget/Input.pm view on Meta::CPAN
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<prepend()>, C<append()>, C<replace()>, C<clear()> or even run existing text
through C<filter()>.
=head1 INTERFACE
The interface is the same as the one described in L<CGI::Test::Form::Widget>,
with the following additions:
lib/CGI/Test/Form/Widget/Input.pm view on Meta::CPAN
=item C<is_area>
Returns I<true> for a text area.
=item C<is_field>
Returns I<true> for a pure text field.
=item C<is_file>
Returns I<true> for a file upload field (text field with browser support for
file selection).
=item C<is_password>
Returns I<true> for a password field (text field with input masked by GUI).
=back
=head1 AUTHORS
lib/CGI/Test/Form/Widget/Input/File.pm view on Meta::CPAN
#
# 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 file input for uploading.
#
# It inherits from Text_Field, since the only distinction between a text field
# and a file upload field is the presence of the "browse" button displayed by
# the browser to select a file.
#
use base qw(CGI::Test::Form::Widget::Input::Text_Field);
#
# Attribute access
#
sub gui_type
{
return "file upload";
}
#
# Redefined predicates
#
sub is_field
{
return 0;
} # not a pure text field
sub is_file
{
return 1;
}
1;
=head1 NAME
CGI::Test::Form::Widget::Input::File - A file upload control
=head1 SYNOPSIS
# Inherits from CGI::Test::Form::Widget::Input
# $form is a CGI::Test::Form
my $upload = $form->input_by_name("upload");
$upload->replace("/tmp/file");
=head1 DESCRIPTION
This class models a file upload control, which is a text field to enter
a file name, with a little "browse" control button nearby that allows
the user to select a file via a GUI...
The interface is the same as the one described in
L<CGI::Test::Form::Widget::Input::Text_Field>.
=head1 AUTHORS
The original author is Raphael Manfredi.
lib/CGI/Test/Input.pm view on Meta::CPAN
push @{$this->_fields}, [ $name, $value ];
$this->{stale} = 1;
return;
}
############################################################
#
# ->add_file
#
# Add a new upload-file information to the input data.
# The actual reading of the file is deferred up to the moment where we
# need to build the input data.
#
# This routine is meant for manual input data building.
#
############################################################
sub add_file
{
my $this = shift;
my ($name, $value) = @_;
lib/CGI/Test/Input.pm view on Meta::CPAN
push @{$this->_files}, [ $name, $value ];
$this->{stale} = 1;
return;
}
############################################################
#
# ->add_file_now
#
# Add a new upload-file information to the input data.
# The file is read immediately, and can be disposed of once we return.
#
# This routine is meant for manual input data building.
#
############################################################
sub add_file_now
{
my $this = shift;
my ($name, $value) = @_;
lib/CGI/Test/Input.pm view on Meta::CPAN
=head1 DESCRIPTION
The C<CGI::Test::Input> class is deferred. It is an abstract representation
of HTTP POST request input, as expected by the C<POST> routine of C<CGI::Test>.
Unless you wish to issue a C<POST> request manually to provide carefully
crafted input, you do not need to learn the interface of this hierarchy,
nor even bother knowing about it.
Otherwise, you need to decide which MIME encoding you want, and create an
object of the appropriate type. Note that file uploading requires the use
of the C<multipart/form-data> encoding:
MIME Encoding Type to Create
--------------------------------- ---------------------------
application/x-www-form-urlencoded CGI::Test::Input::URL
multipart/form-data CGI::Test::Input::Multipart
Once the object is created, you will be able to add name/value tuples
corresponding to the CGI parameters to submit.
lib/CGI/Test/Input.pm view on Meta::CPAN
=head1 INTERFACE
=head2 Creation Routine
It is called C<new> as usual. All subclasses have
the same creation routine signature, which takes no parameter.
=head2 Adding Parameters
CGI parameter are name/value tuples. In case of file uploads, they can have
a content as well, the value being the file path on the client machine.
=over 4
=item C<add_field> I<name>, I<value>
Adds the CGI parameter I<name>, whose value is I<value>.
=item add_file I<name>, I<path>
Adds the file upload parameter I<name>, located at I<path>.
The file is not read immediately, so it must remain available until
the I<data> routine is called, at least. It is not an error if the file
cannot be read at that time.
When not using the C<multipart/form-data> encoding, only the name/path
tuple will be transmitted to the script.
=item add_file_now I<name>, I<path>
lib/CGI/Test/Input/URL.pm view on Meta::CPAN
#
# ->_build_data
#
# Rebuild data buffer from input fields.
#
sub _build_data
{
my $this = shift;
#
# Note that file uploading fields get handled as any other field, meaning
# only the file path will be transmitted.
#
my $data = '';
# XXX field name encoding of special chars is the same as data?
foreach my $tuple (@{$this->_fields()}, @{$this->_files()})
{
my ($name, $value) = @$tuple;
( run in 1.658 second using v1.01-cache-2.11-cpan-b16cb0d3907 )