CGI-Simple

 view release on metacpan or  search on metacpan

lib/CGI/Simple/Standard.pm  view on Meta::CPAN


    # write the required sub to the callers symbol table
    *{"${package}::$sub"} = sub { $q->$sub( @_ ) };

 # now we have inserted the sub let's call it and return the results :-)
    return &{"${package}::$sub"};
  }
}

1;

=head1 NAME

CGI::Simple::Standard - a wrapper module for CGI::Simple that provides a
function style interface

=head1 SYNOPSIS

    use CGI::Simple::Standard qw( -autoload );
    use CGI::Simple::Standard qw( :core :cookie :header :misc );
    use CGI::Simple::Standard qw( param upload );

    $CGI::Simple::Standard::POST_MAX = 1024;       # max upload via post 1kB
    $CGI::Simple::Standard::DISABLE_UPLOADS = 0;   # enable uploads

    @params = param();        # return all param names as a list
    $value =  param('foo');   # return the first value supplied for 'foo'
    @values = param('foo');   # return all values supplied for foo

    %fields   = Vars();       # returns untied key value pair hash
    $hash_ref = Vars();       # or as a hash ref
    %fields   = Vars("|");    # packs multiple values with "|" rather than "\0";

    @keywords = keywords();   # return all keywords as a list

    param( 'foo', 'some', 'new', 'values' );        # set new 'foo' values
    param( -name=>'foo', -value=>'bar' );
    param( -name=>'foo', -value=>['bar','baz'] );

    append( -name=>'foo', -value=>'bar' );          # append values to 'foo'
    append( -name=>'foo', -value=>['some', 'new', 'values'] );

    Delete('foo');   # delete param 'foo' and all its values
    Delete_all();    # delete everything

    <INPUT TYPE="file" NAME="upload_file" SIZE="42">

    $files    = upload()                   # number of files uploaded
    @files    = upload();                  # names of all uploaded files
    $filename = param('upload_file')       # filename of 'upload_file' field
    $mime     = upload_info($filename,'mime'); # MIME type of uploaded file
    $size     = upload_info($filename,'size'); # size of uploaded file

    my $fh = $q->upload($filename);     # open filehandle to read from
    while ( read( $fh, $buffer, 1024 ) ) { ... }

    # short and sweet upload
    $ok = upload( param('upload_file'), '/path/to/write/file.name' );
    print "Uploaded ".param('upload_file')." and wrote it OK!" if $ok;

    $decoded    = url_decode($encoded);
    $encoded    = url_encode($unencoded);
    $escaped    = escapeHTML('<>"&');
    $unescaped  = unescapeHTML('&lt;&gt;&quot;&amp;');

    $qs = query_string();   # get all data in $q as a query string OK for GET

    no_cache(1);            # set Pragma: no-cache + expires
    print header();         # print a simple header
    # get a complex header
    $header = header(   -type       => 'image/gif'
                        -nph        => 1,
                        -status     => '402 Payment required',
                        -expires    =>'+24h',
                        -cookie     => $cookie,
                        -charset    => 'utf-7',
                        -attachment => 'foo.gif',
                        -Cost       => '$2.00');

    @cookies = cookie();        # get names of all available cookies
    $value   = cookie('foo')    # get first value of cookie 'foo'
    @value   = cookie('foo')    # get all values of cookie 'foo'
    # get a cookie formatted for header() method
    $cookie  = cookie(  -name    => 'Password',
                        -values  => ['superuser','god','my dog woofie'],
                        -expires => '+3d',
                        -domain  => '.nowhere.com',
                        -path    => '/cgi-bin/database',
                        -secure  => 1 );
    print header( -cookie=>$cookie );       # set cookie

    print redirect('http://go.away.now');   # print a redirect header

    dienice( cgi_error() ) if cgi_error();

=head1 DESCRIPTION

This module is a wrapper for the completely object oriented CGI::Simple
module and provides a simple functional style interface. It provides two
different methods to import function names into your namespace.

=head2 Autoloading

If you specify the '-autoload' pragma like this:

    use CGI::Simple::Standard qw( -autoload );

Then it will use AUTOLOAD and a symbol table trick to export only those subs
you actually call into your namespace. When you specify the '-autoload' pragma
this module exports a single AUTOLOAD subroutine into you namespace. This will
clash with any AUTOLOAD sub that exists in the calling namespace so if you are
using AUTOLOAD for something else don't use this pragma.

Anyway, when you call a subroutine that is not defined in your script this
AUTOLOAD sub will be called. The first time this happens it
will initialize a CGI::Simple object and then apply the requested method
(if it exists) to it. A fatal exception will be thrown if you try to use an
undefined method (function).

=head2 Specified Export



( run in 1.504 second using v1.01-cache-2.11-cpan-437f7b0c052 )