File Coverage

blib/lib/HTML/FormFu/QueryType/CGI.pm
Criterion Covered Total %
statement 31 31 100.0
branch 5 6 83.3
condition n/a
subroutine 6 6 100.0
pod 1 2 50.0
total 43 45 95.5


line stmt bran cond sub pod time code
1 8     8   58 use strict;
  8         18  
  8         470  
2              
3             package HTML::FormFu::QueryType::CGI;
4             $HTML::FormFu::QueryType::CGI::VERSION = '2.07';
5             # ABSTRACT: uploaded file
6              
7 8     8   45 use Moose;
  8         17  
  8         70  
8              
9             extends 'HTML::FormFu::Upload';
10              
11 8     8   57056 use HTTP::Headers;
  8         60587  
  8         288  
12 8     8   117 use Scalar::Util qw( blessed );
  8         15  
  8         2121  
13              
14             sub parse_uploads {
15 21     21 0 62 my ( $class, $form, $name ) = @_;
16              
17 21         521 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         52 local $CGI::LIST_CONTEXT_WARN = 0;
21              
22 21         109 my @params = $query->param($name);
23 21         509 my @new;
24              
25 21         52 for my $param (@params) {
26 26 100       125 if ( blessed $param ) {
27 18         38 my $filename = $param;
28              
29 18         882 $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         50 = HTTP::Headers->new( %{ $query->uploadInfo($filename) } );
  18         77  
42              
43 18         3393 $param->headers($headers);
44 18         66 $param->size( $headers->content_length );
45 18         67 $param->type( $headers->content_type );
46             }
47              
48 26         77 push @new, $param;
49             }
50              
51 21 50       71 return if !@new;
52              
53 21 100       110 return @new == 1 ? $new[0] : \@new;
54             }
55              
56             sub fh {
57 5     5 1 8 my ($self) = @_;
58              
59 5         13 return $self->_param;
60             }
61              
62             __PACKAGE__->meta->make_immutable;
63              
64             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.07
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