CGI-Lite-Request

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
inc/Module/Install/Fetch.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
lib/CGI/Lite/Request.pm
lib/CGI/Lite/Request/Apache.pm
lib/CGI/Lite/Request/Base.pm
lib/CGI/Lite/Request/Cookie.pm
lib/CGI/Lite/Request/Upload.pm
Makefile.PL
MANIFEST			This list of files

lib/CGI/Lite/Request.pm  view on Meta::CPAN

print to respond to the request. This is normally done after
C<send_http_header> to print the body of data which should be
sent back the the user agent

=item send_http_header

combines the response headers and sends these to the user agent

=item cookie

returnes a named L<CGI::Lite::Cookie> object. If one doesn't
exist by the passed name, then creates a new one and returns
it. Typical semantics would be:

    $sessid = $req->cookie('SID')->value;
    $req->cookie('SID')->value($sessid);

both of these methods will create a new L<CGI::Lite::Request::Cookie>
object if one named 'SID' doesn't already exist. If you don't
want this behaviour, see C<cookies> method

=item cookies

returns a hash reference of L<CGI::Lite::Request::Cookie> objects keyed on their names.
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.

lib/CGI/Lite/Request.pm  view on Meta::CPAN


Richard Hundt <richard NO SPAM AT protea-systems.com>

=head1 ACKNOWLEDGEMENTS

Thanks to Sebastian Riedel for the code shamelessly stolen
from L<Catalyst::Request> and L<Catalyst::Request::Upload>

=head1 SEE ALSO

L<CGI::Lite>, L<CGI::Lite::Cookie>, L<CGI::Lite::Upload>

=head1 LICENCE

This library is free software and may be used under the same terms as Perl itself

=cut

lib/CGI/Lite/Request/Apache.pm  view on Meta::CPAN


sub content_type { shift->apache->content_type(@_) }

sub send_http_header {
    my $self = shift;
    my $content_type = shift;
    $content_type ||= 'text/html';

    if ($self->cookies) {
        $self->headers->push_header(
            Set_Cookie => $_->as_string
        ) foreach values %{$self->cookies};
    }

    $self->headers->scan(sub {
        $self->apache->headers_out->add(@_);
    });

    $self->content_type($content_type);
    if ($mod_perl::VERSION < 1.99) {
        $self->apache->send_http_header();

lib/CGI/Lite/Request/Apache.pm  view on Meta::CPAN

sub redirect {
    my ($self, $location) = @_;

    my $cookies;
    $cookies += $_->as_string foreach values %{$self->cookies};

    $self->apache->send_cgi_header(<<"EOT");
Status: 302 Moved
Location: $location
Content-type: text/html
Set-Cookie: $cookies
\015\012
EOT

    $self->{_header_sent}++;

}

1;

__END__

lib/CGI/Lite/Request/Base.pm  view on Meta::CPAN

package CGI::Lite::Request::Base;

use URI;
use File::Type    ();
use HTTP::Headers ();

use CGI::Lite::Request::Cookie;
use CGI::Lite::Request::Upload;

use base qw(CGI::Lite);

our %_instances = ();

sub instance { $_instances{$$} ? $_instances{$$} : $_[0]->new }

sub new {
    my $class = shift;

lib/CGI/Lite/Request/Base.pm  view on Meta::CPAN

    $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;
    $self->set_file_type('handle');
    $self->parse_new_form_data(@_);
}

sub parse_form_data {
    my ($self, $user_request) = @_;
    my $request_method = $user_request || $ENV{REQUEST_METHOD} || '';
    my $content_type   = $ENV{CONTENT_TYPE};

    if ($request_method =~ /post/i and $content_type =~ /xml/) {

lib/CGI/Lite/Request/Base.pm  view on Meta::CPAN

    my $self = shift;
    if (my $content_type = shift) {
        $self->content_type($content_type);
    }
    unless ($self->content_type) {
        $self->content_type('text/html');
    }

    if ($self->cookies) {
        $self->headers->push_header(
            Set_Cookie => $_->as_string
        ) foreach values %{$self->cookies};
    }

    $self->print($self->headers->as_string, "\015\012" x 2);
    $self->{_header_sent}++;
}

sub header_sent { $_[0]->{_header_sent} }

sub cookie {
    my ($self, $name) = @_;
    $self->{_cookies}->{$name} ||= CGI::Lite::Request::Cookie->new(
        -name  => $name,
        -value => '',
    );
    return $self->{_cookies}->{$name};
}

sub cookies { $_[0]->{_cookies} }

sub redirect {
    my ($self, $location) = @_;
    my $cookies;
    $cookies += $_->as_string foreach values %{$self->cookies};
    $self->print(<<"EOF");
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) };
}

lib/CGI/Lite/Request/Cookie.pm  view on Meta::CPAN

package CGI::Lite::Request::Cookie;

use CGI::Lite qw(url_encode url_decode);

=head1 NAME

CGI::Lite::Request::Cookie - Cookie objects for CGI::Lite::Request

=head1 SYNOPSIS

  %cookies = CGI::Lite::Cookie->fetch           # fetch all cookies
  $cookies = CGI::Lite::Cookie->fetch           # same but hash ref
   
  $cookie->name;                                # get
  $cookie->name('my_cookie');                   # set
   
  @value = $cookie->value;                      # for multiple values
  $value = $cookie->value;                      # array ref or simple scalar
  $cookie->value($simple_scalar);
  $cookie->value([ "one", "2", "III" ]);
   
  # mutators (simple get and set)
  $cookie->expires;
  $cookie->path;
  $cookie->domain;
  $cookie->secure;
  
  $cookie->as_string;                           # returns the cookie formatted
                                                # for use in an HTTP header

=head1 DESCRIPTION

This class is almost identical to the original L<CGI::Cookie>, except
in that it doesn't require the Cursed Gateway Interface (CGI.pm) to
function, instead it uses only methods provided by L<CGI::Lite> - a
module which lives up to its name.

=cut

sub fetch {
    my $class = shift;
    my $raw_cookie = $ENV{HTTP_COOKIE} || $ENV{COOKIE};
    return () unless $raw_cookie;

lib/CGI/Lite/Request/Cookie.pm  view on Meta::CPAN


1;


=head1 AUTHOR

Richard Hundt <richard NO SPAM AT protea-systems.com>

=head1 ACKNOWLEDGEMENTS

Dr. Lincoln Stein and anybody who contributed to L<CGI::Cookie>
from which most of this code was stolen.

=head1 SEE ALSO

L<CGI::Lite>, L<CGI::Lite::Request>, L<CGI::Cookie>

=head1 LICENCE

This library is free software and may be used under the same terms as Perl itself

=cut



( run in 0.832 second using v1.01-cache-2.11-cpan-e9199f4ba4c )