Apache-AuthCookie

 view release on metacpan or  search on metacpan

lib/Apache/AuthCookie/Params/CGI.pm  view on Meta::CPAN

package Apache::AuthCookie::Params::CGI;
$Apache::AuthCookie::Params::CGI::VERSION = '3.32';
# ABSTRACT: Internal CGI Params Subclass

use strict;
use warnings;
use Carp ();
use WWW::Form::UrlEncoded qw(parse_urlencoded);
use Hash::MultiValue;
use HTTP::Body;
use Encode ();


sub new {
    my ($class, $r) = @_;

    $class = ref $class || $class;

    return bless {
        _request => $r
    }, $class;
}


sub request {
    my $self = shift;

    return $self->{_request};
}


sub param {
    my ($self, $name, @vals) = @_;

    # no param name given, return list of all parameter names.
    unless (defined $name) {
        return $self->params->keys;
    }

    # set values
    if (@vals) {
        $self->params->remove($name);
        $self->params->add($name => @vals);
    }

    # return values
    return $self->params->get_all($name);
}


sub params {
    my $self = shift;

    $self->{_params} ||= Hash::MultiValue->new(
        map $_->flatten, $self->query_params, $self->body_params
    );
}


sub query_params {
    my $self = shift;

lib/Apache/AuthCookie/Params/CGI.pm  view on Meta::CPAN

        my $bytes_read = length $buffer;

        $length -= $bytes_read;
        $body->add($buffer);

        # guard against a signal interrupting read()
        if ($bytes_read == 0 && $spin++ > 2000) {
            Carp::croak "Bad Content-Length: maybe client disconnect? ($length bytes remaining)";
        }
    }

    return $body;
}

# utility method to fetch a pnote, or set it to a computed value if it has not
# already been set.
sub _compute_pnote {
    my ($self, $key, $code) = @_;

    my $r = $self->request;

    unless (defined $r->pnotes($key)) {
        $r->pnotes($key, $code->());
    }

    return $r->pnotes($key);
}

sub _decode {
    my ($self, $hash) = @_;

    my $r = $self->request;
    my $auth_name = $r->auth_name;

    if (my $encoding = $r->dir_config("${auth_name}Encoding")) {
        my $decoded = Hash::MultiValue->new;

        $hash->each(sub {
            my @dec = map { Encode::decode($encoding, $_) } @_;

            $decoded->add(@dec);
        });

        return $decoded;
    }
    else {
        return $hash;
    }
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Apache::AuthCookie::Params::CGI - Internal CGI Params Subclass

=head1 VERSION

version 3.32

=head1 SYNOPSIS

 Internal Use Only!

=head1 DESCRIPTION

This is a pure perl implementation of HTTP/CGI parameter processing for Apache::AuthCookie.

=head1 METHODS

=head2 new($r)

Constructor

=head2 request(): scalar

Get the apache request object

=head2 param()

Get or set parameters. This manipulates the enderlying L<params()> object.  When called with no parameters returns the list of CGI parameter names.  Return value depends on the arguments passed:

=over 4

=item *

param()

Return the list of CGI parameter names

=item *

param($field)

Return the value of the given CGI field.  If the field has multiple values they will all be returned as a list.

=item *

param($field, @values)

Set the given CGI field value to the given values.  Existing values will be replaced.
=end

=back

=head2 params(): Hash::MultiValue

Get the underlying CGI parameters.  This is a merged version of
L<query_params()> and L<body_params()>.

=head2 query_params(): Hash::MultiValue

Get the request query parameters.

=head2 body_params(): Hash::MultiValue

Get the request body parameters.

=head2 content_length(): int

Get the values of the C<Content-Length> header.  Returns C<0> if the header is not present or empty.

=head2 content_type(): string

Get the value of the C<Content-Type> header.  Returns an empty string if the
header is not present.



( run in 1.636 second using v1.01-cache-2.11-cpan-99c4e6809bf )