CGI-Lite-Request
view release on metacpan or search on metacpan
lib/CGI/Lite/Request.pm view on Meta::CPAN
%args = $req->args; # hash
$uri = $req->uri; # URI
$req->print(@out); # print to STDOUT
$req->headers; # HTTP::Headers instance
$req->send_http_header; # print the header
$req->content_type('text/html'); # set
$req->content_type; # get
$path = $req->path_info; # $ENV{PATH_INFO}
$cookie = $req->cookie('my_cookie'); # fetch or create a cookie
$req->cookie('SID')->value($sessid); # set a cookie
$upload = $req->upload('my_field'); # CGI::Lite::Upload instance
$uploads = $req->uploads; # hash ref of CGI::Lite::Upload objects
=head1 DESCRIPTION
This module extends L<CGI::Lite> to provide an interface which is compatible with the most commonly used
methods of L<Apache::Request> as a fat free alternative to L<CGI>.
All methods of L<CGI::Lite> are inherited as is, and the following are defined herein:
=head1 METHODS
lib/CGI/Lite/Request.pm view on Meta::CPAN
This can be used for accessing cookies where you don't want them
to be created automatically if they don't exists, or for simply
checking for their existence:
if (exists $req->cookies->{'SID'}) {
$sessid = $req->cookies->{'SID'}->value;
}
see L<CGI::Lite::Request::Cookie> for more details
=item upload
returns a named L<CGI::Lite::Upload> object keyed on the field name
with which it was associated when uploaded.
=item uploads
returns a hash reference of all the L<CGI::Lite::Request::Upload> objects
keyed on their names.
see L<CGI::Lite::Request::Upload> for details
=head1 AUTHOR
Richard Hundt <richard NO SPAM AT protea-systems.com>
lib/CGI/Lite/Request/Base.pm view on Meta::CPAN
undef( $self->{$_} ) for qw[
_args
_base
_secure
_headers
_cookies
_path_info
_header_sent
];
$self->{_uploads} = { };
$self->{_headers} = HTTP::Headers->new(
Status => '200 OK',
Content_Type => 'text/html',
Pragma => 'no-cache',
Cache_Control => 'no-cache',
Connection => 'close',
);
$self->{_cookies} = CGI::Lite::Request::Cookie->fetch;
lib/CGI/Lite/Request/Base.pm view on Meta::CPAN
Status: 302 Moved
Location: $location
Content-type: text/html
Set-Cookie: $cookies
\015\012
EOF
$self->{_header_sent}++;
}
sub upload {
my ($self, $fieldname) = @_;
return $self->uploads->{ $self->param($fieldname) };
}
sub uploads { $_[0]->{_uploads} }
sub _create_handles {
my ($self, $files) = @_;
my $ft = File::Type->new;
my ($upload, $name, $path);
while (($name, $path) = each %$files) {
$upload = CGI::Lite::Request::Upload->new;
$upload->tempname($path);
$upload->filename($name);
$upload->type($ft->mime_type($path));
$upload->size(-s $path);
$self->{_uploads}->{$name} = $upload;
}
}
sub extract_params {
my ($self, $string) = @_;
my @k_v_pairs = split /&/, $string;
my (%params, $k, $v);
foreach (@k_v_pairs) {
($k, $v) = map { url_decode($_ || '') } split /=/, $_, 2;
if (defined $params{$k}) {
lib/CGI/Lite/Request/Upload.pm view on Meta::CPAN
use File::Copy ();
use IO::File ();
=head1 NAME
CGI::Lite::Request::Upload - Upload objects for CGI::Lite
=head1 SYNOPSIS
$upload = CGI::Lite::Request::Upload->new;
# getters
$upload->filename;
$upload->tempname;
$upload->size;
$upload->type;
# copy and hard link
$upload->copy_to('/target/path');
$upload->link_to('/target/path');
$fh = $upload->fh;
$content = $upload->slurp;
=head1 DESCRIPTION
These objects are created automatically during the C<parse> of the incoming
request by L<CGI::Lite::Request>, and shouldn't be instantiated directly.
=head1 METHODS
=over
=item new
simple constructor
=cut
sub new { bless { }, $_[0] }
=item filename
returns the filename of the uploaded file
=item tempname
returns the name of the temporary file to which the content has been spooled
=cut
sub filename { $_[0]->{_filename} = $_[1] if $_[1]; $_[0]->{_filename} }
sub tempname { $_[0]->{_tempname} = $_[1] if $_[1]; $_[0]->{_tempname} }
=item size
returns the size of the uploaded file
=item type
returns the MIME type of the file (guessed with L<File::Type>)
=cut
sub size { $_[0]->{_size} = $_[1] if $_[1]; $_[0]->{_size} }
sub type { $_[0]->{_type} = $_[1] if $_[1]; $_[0]->{_type} }
lib/CGI/Lite/Request/Upload.pm view on Meta::CPAN
=cut
sub link_to {
my ($self, $target) = @_;
return CORE::link($self->tempname, $target);
}
=item slurp
reads and returns the contents of the uploaded file
=cut
sub slurp {
my ($self) = @_;
my $content;
my $handle = $self->fh;
binmode($handle);
( run in 0.938 second using v1.01-cache-2.11-cpan-b16cb0d3907 )