| 1 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | |||||||||||
| 3 | package HTML::FormFu::QueryType::CGI; | ||||||||||
| 4 | 8 | $HTML::FormFu::QueryType::CGI::VERSION = '2.06'; | |||||||||
| 5 | # ABSTRACT: uploaded file | ||||||||||
| 6 | |||||||||||
| 7 | 8 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 8 | extends 'HTML::FormFu::Upload'; | |||||||||
| 10 | |||||||||||
| 11 | 8 | ▶ | use HTTP::Headers; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 8 | ▶ | use Scalar::Util qw( blessed ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | sub parse_uploads { | ||||||||||
| 15 | 21 | ▶ | my ( $class, $form, $name ) = @_; | ||||||||
|
Subroutine
parse_uploads: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 16 | |||||||||||
| 17 | 21 | my $query = $form->query; | |||||||||
| 18 | ## CGI wants you to use $query->multi_param($foo). | ||||||||||
| 19 | ## doing so breaks CGI::Simple. So shoosh it up for now. | ||||||||||
| 20 | 21 | local $CGI::LIST_CONTEXT_WARN = 0; | |||||||||
| 21 | |||||||||||
| 22 | 21 | my @params = $query->param($name); | |||||||||
| 23 | 21 | my @new; | |||||||||
| 24 | |||||||||||
| 25 | 21 | for my $param (@params) { | |||||||||
| 26 | 26 | ▶ | if ( blessed $param ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 18 | my $filename = $param; | |||||||||
| 28 | |||||||||||
| 29 | 18 | $param = $class->new( | |||||||||
| 30 | { _param => $param, | ||||||||||
| 31 | filename => sprintf( "%s", $filename ), | ||||||||||
| 32 | parent => $form, | ||||||||||
| 33 | |||||||||||
| 34 | # TODO: for now, parent points to the form | ||||||||||
| 35 | # pointing to a field will require handling multiple | ||||||||||
| 36 | # fields of the same name | ||||||||||
| 37 | # if fixed, other QueryTypes and MultiForm will need updating | ||||||||||
| 38 | } ); | ||||||||||
| 39 | |||||||||||
| 40 | my $headers | ||||||||||
| 41 | 18 | = HTTP::Headers->new( %{ $query->uploadInfo($filename) } ); | |||||||||
| 42 | |||||||||||
| 43 | 18 | $param->headers($headers); | |||||||||
| 44 | 18 | $param->size( $headers->content_length ); | |||||||||
| 45 | 18 | $param->type( $headers->content_type ); | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 26 | push @new, $param; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 21 | ▶ | return if !@new; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | 21 | ▶ | return @new == 1 ? $new[0] : \@new; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | sub fh { | ||||||||||
| 57 | 5 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
fh: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 58 | |||||||||||
| 59 | 5 | return $self->_param; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 8 | __PACKAGE__->meta->make_immutable; | |||||||||
| 63 | |||||||||||
| 64 | 8 | 1; | |||||||||
| 65 | |||||||||||
| 66 | __END__ | ||||||||||
| 67 | |||||||||||
| 68 | =pod | ||||||||||
| 69 | |||||||||||
| 70 | =encoding UTF-8 | ||||||||||
| 71 | |||||||||||
| 72 | =head1 NAME | ||||||||||
| 73 | |||||||||||
| 74 | HTML::FormFu::QueryType::CGI - uploaded file | ||||||||||
| 75 | |||||||||||
| 76 | =head1 VERSION | ||||||||||
| 77 | |||||||||||
| 78 | version 2.06 | ||||||||||
| 79 | |||||||||||
| 80 | =head1 METHODS | ||||||||||
| 81 | |||||||||||
| 82 | =head2 headers | ||||||||||
| 83 | |||||||||||
| 84 | As of L<HTML::FormFu> version C<0.02004>, returns a L<HTTP::Headers> object. | ||||||||||
| 85 | - Previously returned a hashref of values. | ||||||||||
| 86 | |||||||||||
| 87 | =head2 filename | ||||||||||
| 88 | |||||||||||
| 89 | Returns the browser-submitted filename of the local file. | ||||||||||
| 90 | |||||||||||
| 91 | =head2 fh | ||||||||||
| 92 | |||||||||||
| 93 | Returns a read-only filehandle. | ||||||||||
| 94 | |||||||||||
| 95 | =head2 slurp | ||||||||||
| 96 | |||||||||||
| 97 | Returns the contents of the uploaded file. | ||||||||||
| 98 | |||||||||||
| 99 | =head2 size | ||||||||||
| 100 | |||||||||||
| 101 | A shortcut for C<< $upload->headers->content_length >>. | ||||||||||
| 102 | |||||||||||
| 103 | Returns the size of the uploaded file in bytes. | ||||||||||
| 104 | |||||||||||
| 105 | =head2 type | ||||||||||
| 106 | |||||||||||
| 107 | A shortcut for C<< $upload->headers->content_type >>. | ||||||||||
| 108 | |||||||||||
| 109 | Returns the browser-submitted Content-Type of the uploaded file. | ||||||||||
| 110 | |||||||||||
| 111 | =head1 SEE ALSO | ||||||||||
| 112 | |||||||||||
| 113 | Is a sub-class of, and inherits methods from | ||||||||||
| 114 | L<HTML::FormFu::Upload> | ||||||||||
| 115 | |||||||||||
| 116 | L<HTML::FormFu>, L<HTML::FormFu::Element::File> | ||||||||||
| 117 | |||||||||||
| 118 | =head1 AUTHOR | ||||||||||
| 119 | |||||||||||
| 120 | Carl Franks, C<cfranks@cpan.org> | ||||||||||
| 121 | |||||||||||
| 122 | =head1 LICENSE | ||||||||||
| 123 | |||||||||||
| 124 | This library is free software, you can redistribute it and/or modify it under | ||||||||||
| 125 | the same terms as Perl itself. | ||||||||||
| 126 | |||||||||||
| 127 | =head1 AUTHOR | ||||||||||
| 128 | |||||||||||
| 129 | Carl Franks <cpan@fireartist.com> | ||||||||||
| 130 | |||||||||||
| 131 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 132 | |||||||||||
| 133 | This software is copyright (c) 2018 by Carl Franks. | ||||||||||
| 134 | |||||||||||
| 135 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 136 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 137 | |||||||||||
| 138 | =cut | ||||||||||