HTML::FormFu::QueryType::CGI - HTML::FormFu::QueryType::CGI documentation


HTML-FormFu documentation Contained in the HTML-FormFu distribution.

Index


Code Index:

NAME

Top

HTML::FormFu::QueryType::CGI

METHODS

Top

headers

As of HTML::FormFu version 0.02004, returns a HTTP::Headers object. - Previously returned a hashref of values.

filename

Returns the browser-submitted filename of the local file.

fh

Returns a read-only filehandle.

slurp

Returns the contents of the uploaded file.

size

A shortcut for $upload->headers->content_length.

Returns the size of the uploaded file in bytes.

type

A shortcut for $upload->headers->content_type.

Returns the browser-submitted Content-Type of the uploaded file.

SEE ALSO

Top

Is a sub-class of, and inherits methods from HTML::FormFu::Upload

HTML::FormFu, HTML::FormFu::Element::File

AUTHOR

Top

Carl Franks, cfranks@cpan.org

LICENSE

Top

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


HTML-FormFu documentation Contained in the HTML-FormFu distribution.

package HTML::FormFu::QueryType::CGI;
use Moose;

extends 'HTML::FormFu::Upload';

use HTTP::Headers;
use Scalar::Util qw( blessed );

sub parse_uploads {
    my ( $class, $form, $name ) = @_;

    my $query  = $form->query;
    my @params = $query->param($name);
    my @new;

    for my $param (@params) {
        if ( blessed $param ) {
            my $filename = $param;

            $param = $class->new( {
                    _param   => $param,
                    filename => sprintf( "%s", $filename ),
                    parent   => $form,

                   # TODO: for now, parent points to the form
                   # pointing to a field will require handling multiple
                   # fields of the same name
                   # if fixed, other QueryTypes and MultiForm will need updating
                } );

            my $headers
                = HTTP::Headers->new( %{ $query->uploadInfo($filename) } );

            $param->headers($headers);
            $param->size( $headers->content_length );
            $param->type( $headers->content_type );
        }

        push @new, $param;
    }

    return if !@new;

    return @new == 1 ? $new[0] : \@new;
}

sub fh {
    my ($self) = @_;

    return $self->_param;
}

__PACKAGE__->meta->make_immutable;

1;

__END__