Blosxom-Plugin

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

        * Rename cookies() to cookie()
        * Add base(), is_secure(), header()
  - [Request::Upload]
        * fh() returns an IO::File object
  - [Util] Add encode_html()

0.00005  Jul 14th, 2012
  - Add Blosxom::Plugin::Request::Upload

0.00004  Jul 14th, 2012
  - [Request] Add user(), server_protocol() and uploads()
  - [Response] body() become mutable
  - tests requires Data::Section::Simple

0.00002  Jul 11th, 2012
  - Add load_plugin(), load_plugins() and add_method().
    load_plugin() calls begin() method of each plugin
  - Add Blosxom::Plugin::Response, Request and Util.
    Blosxom::Plugin loads them when loaded
  - A namespace Blosxom::Plugin::* will be open to those who want to
    register Blosxom metaplugins, though I'm not sure about

MANIFEST  view on Meta::CPAN

t/add_method.t
t/attibutes.t
t/compile.t
t/conflict.t
t/data_section.t
t/import.t
t/load_components.t
t/load_components_recursively.t
t/plugins/data_section
t/request.t
t/upload.t
t/upload_post_text.txt
t/web.t
xt/pod.t

lib/Blosxom/Plugin/Web/Request.pm  view on Meta::CPAN

    return $self->{query}->cookie( shift ) if @_;
    $self->{query}->cookie;
}

sub param {
    my $self = shift;
    return $self->{query}->param( shift ) if @_;
    $self->{query}->param;
}

sub upload {
    my ( $self, $field ) = @_;

    $self->{upload} ||= do { 
        require Blosxom::Plugin::Web::Request::Upload;
        my $query = $self->{query};

        my %upload;
        for my $field ( $query->param ) {
            my @uploads;
            for my $fh ( $query->upload($field) ) {
                my $upload = Blosxom::Plugin::Web::Request::Upload->new(
                    fh     => $fh,
                    path   => $query->tmpFileName( $fh ),
                    header => $query->uploadInfo( $fh ),
                );

                push @uploads, $upload;
            }

            $upload{ $field } = \@uploads if @uploads;
        }

        \%upload;
    };

    if ( $field ) {
        if ( my $uploads = $self->{upload}{$field} ) {
            return wantarray ? @{ $uploads } : $uploads->[0];
        }
    }
    else {
        return keys %{ $self->{upload} };
    }

    return;
}

sub DESTROY { CGI::initialize_globals() }

1;

__END__

lib/Blosxom/Plugin/Web/Request.pm  view on Meta::CPAN


=item $request->user

Returns the authorization/verification name for user verification,
if this script is protected (C<REMOTE_USER>).

=item $request->protocol

Returns the protocol (HTTP/1.0 or HTTP/1.1) used for the current request.

=item $request->upload

Returns L<Blosxom::Plugin::Web::Request::Upload> objects.

  my $upload = $request->upload( 'field' );
  my @uploads = $request->upload( 'field' );
  my @fields = $request->upload;

=item $request->is_secure

Returns a Boolean value telling whether connection is secure.

=item $request->header

Returns the value of the specified header.

  my $requested_language = $request->header( 'Accept-Language' );

lib/Blosxom/Plugin/Web/Request/Upload.pm  view on Meta::CPAN

    require IO::File;
    IO::File->new_from_fd( fileno $_[0], '<' );
}

1;

__END__

=head1 NAME

Blosxom::Plugin::Request::Upload - Handles file upload requests

=head1 SYNOPSIS

  # $request is Blosxom::Plugin::Request
  my $upload = $request->upload( 'field' );

  $upload->size;
  $upload->path;
  $upload->content_type:
  $upload->fh;
  $upload->basename;

=head1 DESCRIPTION

Handles file upload requests.

=head2 METHODS

=over 4

=item $upload->size

Returns the size of uploaded file in bytes.

=item $upload->fh

Returns a read-only file handle on the temporary file.

  my $fh = $upload->fh;

  # Upgrade to IO::Handle
  my $handle = $fh->handle;

  # Upgrade to IO::File handle
  my $file = $fh->file;

=item $upload->path

Returns the path to the temporary file where uploaded file is saved.

=item $upload->content_type

Returns the content type of the uploaded file.

=item $upload->filename

Returns the original filename in the client.

=item $upload->basename

Returns basename for C<filename>.

=item $upload->header

=back

=head1 SEE ALSO

L<Blosxom::Plugin::Request>, L<Plack::Request::Upload>

=head1 AUTHOR

Ryo Anazawa

t/request.t  view on Meta::CPAN

local $ENV{REQUEST_METHOD}  = 'GET';
local $ENV{CONTENT_TYPE}    = 'utf-8';
local $ENV{HTTP_REFERER}    = 'http://www.blosxom.com/';
local $ENV{HTTP_USER_AGENT} = 'Chrome';

my $plugin = 'Blosxom::Plugin::Web::Request';
my $request = $plugin->new;
isa_ok $request, $plugin;
can_ok $request, qw(
    method cookie content_type referer user_agent address
    remote_host param path_info protocol user upload base
    is_secure header
);

is $request->method,       'GET';
is $request->content_type, 'utf-8';
is $request->referer,      'http://www.blosxom.com/';
is $request->user_agent,   'Chrome';
is $request->address,      '127.0.0.1';
is $request->remote_host,  'localhost';
is $request->protocol,     'HTTP/1.0';

t/upload.t  view on Meta::CPAN

    SERVER_PROTOCOL   => 'HTTP/1.1',
    PATH              => '/usr/local/bin:/usr/bin:/bin',
    REQUEST_URI       => '/test.cgi',
    GATEWAY_INTERFACE => 'CGI/1.1',
    SERVER_ADDR       => '127.0.0.1',
    DOCUMENT_ROOT     => '/home/develop',
    HTTP_HOST         => 'www.perl.org',
);

local *STDIN;
open STDIN, "< $FindBin::Bin/upload_post_text.txt"
    or die 'missing test file t/upload_post_text.txt';
binmode STDIN;

my $request = Blosxom::Plugin::Web::Request->new;

my @got = sort $request->upload;
my @expected = qw(
    100;100_gif        300x300_gif
    does_not_exist_gif hello_world
);
is_deeply \@got, \@expected;

my $file = $request->upload( '300x300_gif' );
is $file->content_type, 'image/gif';
is $file->size, 1656;
is $file->filename, '300x300.gif';
is $file->basename, '300x300.gif';
isa_ok $file->fh, 'Fh'; # See CGI.pm
isa_ok $file->fh->handle, 'IO::Handle';
isa_ok $file->fh->file, 'IO::File';

my @hello_names = $request->upload( 'hello_world' );
is $hello_names[0]->filename, 'goodbye_world.txt';
is $hello_names[1]->filename, 'hello_world.txt';



( run in 1.993 second using v1.01-cache-2.11-cpan-b16cb0d3907 )