lib/HTML/FormFu/QueryType/CGI/Simple.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 41 SCAR 30.0
CC
4
Cov
0%
parse_uploads
20.0
fh
2.0
BEGIN
2.0
CRAP 20.0
1 use strict;
2  
3 package HTML::FormFu::QueryType::CGI::Simple;
4 $HTML::FormFu::QueryType::CGI::Simple::VERSION = '2.06';
5 # ABSTRACT: uploaded file
6  
7 use Moose;
8  
9 extends 'HTML::FormFu::QueryType::CGI';
10  
11 sub parse_uploads {
12 my ( $class, $form, $name ) = @_;
13  
14 my $query = $form->query;
15 my @params = $query->param($name);
16 my @new;
17  
18 for my $param (@params) {
19 if ( my $file = $query->upload($param) ) {
20 my $filename = $param;
21  
22 $param = $class->new(
23 { _param => $file,
24 filename => $filename,
25 parent => $form,
26 } );
27  
28 my $headers = HTTP::Headers->new(
29 'Content-Type' => $query->upload_info( $filename, 'mime' ),
30 'Content-Length' => $query->upload_info( $filename, 'size' ),
31 );
32  
33 $param->headers($headers);
34 $param->size( $headers->content_length );
35 $param->type( $headers->content_type );
36 }
37 push @new, $param;
38 }
39  
40 return if !@new;
41  
42 return @new == 1 ? $new[0] : \@new;
43 }
44  
45 sub fh {
46 my ($self) = @_;
47  
48 return $self->form->query->upload( $self->filename );
49 }
50  
51 __PACKAGE__->meta->make_immutable;
52  
53 1;
54  
55 __END__
56  
57 =pod
58  
59 =encoding UTF-8
60  
61 =head1 NAME
62  
63 HTML::FormFu::QueryType::CGI::Simple - uploaded file
64  
65 =head1 VERSION
66  
67 version 2.06
68  
69 =head1 METHODS
70  
71 =head2 headers
72  
73 Inherited, see L<HTML::FormFu::QueryType::CGI/headers> for details.
74  
75 =head2 filename
76  
77 Inherited, see L<HTML::FormFu::QueryType::CGI/filename> for details.
78  
79 =head2 fh
80  
81 Returns a read-only filehandle.
82  
83 =head2 slurp
84  
85 Inherited, see L<HTML::FormFu::QueryType::CGI/slurp> for details.
86  
87 =head2 size
88  
89 Inherited, see L<HTML::FormFu::QueryType::CGI/size> for details.
90  
91 =head2 type
92  
93 Inherited, see L<HTML::FormFu::QueryType::CGI/type> for details.
94  
95 =head1 SEE ALSO
96  
97 Is a sub-class of, and inherits methods from
98 L<HTML::FormFu::QueryType::CGI>, L<HTML::FormFu::Upload>
99  
100 L<HTML::FormFu>, L<HTML::FormFu::Element::File>
101  
102 =head1 AUTHOR
103  
104 Carl Franks, C<cfranks@cpan.org>
105  
106 =head1 LICENSE
107  
108 This library is free software, you can redistribute it and/or modify it under
109 the same terms as Perl itself.
110  
111 =head1 AUTHOR
112  
113 Carl Franks <cpan@fireartist.com>
114  
115 =head1 COPYRIGHT AND LICENSE
116  
117 This software is copyright (c) 2018 by Carl Franks.
118  
119 This is free software; you can redistribute it and/or modify it under
120 the same terms as the Perl 5 programming language system itself.
121  
122 =cut