CGI-Easy
view release on metacpan or search on metacpan
lib/CGI/Easy.pm view on Meta::CPAN
package CGI::Easy;
use 5.010001;
use warnings;
use strict;
use utf8;
use Carp;
our $VERSION = 'v2.0.1';
1; # Magic true value required at end of module
__END__
=encoding utf8
=head1 NAME
CGI::Easy - simple and straightforward helpers to make CGI easy
=head1 VERSION
This document describes CGI::Easy version v2.0.1
=head1 SYNOPSIS
use CGI::Easy::Request;
use CGI::Easy::Headers;
use CGI::Easy::Session;
my $r = CGI::Easy::Request->new();
my $h = CGI::Easy::Headers->new();
my $sess = CGI::Easy::Session->new($r, $h);
# -- access basic GET request details
my $url = "$r->{scheme}://$r->{host}:$r->{port}$r->{path}";
my $param_name = $r->{GET}{name};
my @param_color = @{ $r->{GET}{'color[]'} };
my $cookie_some = $r->{cookie}{some};
# -- file upload
my $avatar_image = $r->{POST}{avatar};
my $avatar_filename = $r->{filename}{avatar};
my $avatar_mimetype = $r->{mimetype}{avatar};
# -- easy way to identify visitors and get data stored in cookies
my $session_id = $sess->{id};
my $tempcookie_x= $sess->{temp}{x};
my $permcookie_y= $sess->{perm}{y};
# -- set custom HTTP headers and cookies
$h->{Expires} = 'Sat, 01 Jan 2000 00:00:00 GMT';
$h->add_cookie({
name => 'some',
value => 'custom cookie',
domain => '.example.com',
expires => time+86400,
});
# -- easy way to store data in cookies
$sess->{temp}{x} = 'available until browser closes';
$sess->{perm}{y} = 'available for 1 year';
$sess->save();
# -- output all HTTP headers and html page
print $h->compose();
print "<html>...</html>";
# -- output redirect
$h->redirect('http://example.com/');
print $h->compose();
# -- output custom reply
$h->{Status} = '500 Internal Server Error';
$h->{'Content-Type'} = 'text/plain; charset=utf-8';
print $h->compose(), "Please try again later\n";
=head1 DESCRIPTION
This documentation is an overview of CGI::Easy::* modules. For detailed
information about corner cases and available features you should consult
corresponding module documentation: L<CGI::Easy::Request>,
L<CGI::Easy::Headers>, L<CGI::Easy::Session>. If you wanna work with
CGI/HTTP on lower level, you can look at L<CGI::Easy::Util>. There also
some other useful modules available separately: L<CGI::Easy::URLconf>,
L<CGI::Easy::SendFile>.
CGI::Easy designed to help you do what you want with CGI/HTTP without
forcing you to learn I<one more> huge and complex API specific to some
module, or limiting you to do your tasks I<only in way> provided by this
module. With CGI::Easy you got all you need in B<simple hashes>, and
you're free to B<do anything you like> with this data, because it's
B<your data>.
CGI::Easy consist of three main parts:
=over
=item CGI::Easy::Request object
( run in 0.670 second using v1.01-cache-2.11-cpan-b16cb0d3907 )