lib/HTML/FormFu/QueryType/Catalyst.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 60 SCAR 34.0
CC
5
Cov
0%
parse_uploads
20.0
fh
6.0
BEGIN
2.0
CRAP 30.0
1 use strict;
2  
3 package HTML::FormFu::QueryType::Catalyst;
4 $HTML::FormFu::QueryType::Catalyst::VERSION = '2.06';
5 # ABSTRACT: uploaded file
6  
7 use Moose;
8 use MooseX::Attribute::Chained;
9  
10 extends 'HTML::FormFu::Upload';
11  
12 use IO::File ();
13 use Scalar::Util qw( weaken );
14  
15 has basename => ( is => 'rw', traits => ['Chained'] );
16 has tempname => ( is => 'rw', traits => ['Chained'] );
17  
18 sub parse_uploads {
19 my ( $class, $form, $name ) = @_;
20  
21 my @params = $form->query->param($name);
22 my @uploads = $form->query->upload($name);
23 my @new;
24  
25 # if all params aren't files,
26 # the files will be at the end of @params
27 my $non_file_count = scalar @params - scalar @uploads;
28  
29 if ( $non_file_count > 0 ) {
30 splice @params, $non_file_count;
31  
32 push @new, @params;
33 }
34  
35 for my $upload (@uploads) {
36 my $param = $class->new(
37 { parent => $form,
38 basename => $upload->basename,
39 headers => $upload->headers,
40 filename => $upload->filename,
41 tempname => $upload->tempname,
42 size => $upload->size,
43 type => $upload->type
44 } );
45  
46 push @new, $param;
47 }
48  
49 return if !@new;
50  
51 return @new == 1 ? $new[0] : \@new;
52 }
53  
54 # copied from Catalyst 5.7x series - before it was Moosified
55 sub fh {
56 my $self = shift;
57  
58 my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY );
59  
60 unless ( defined $fh ) {
61  
62 my $filename = $self->tempname;
63  
64 Catalyst::Exception->throw(
65 message => qq/Can't open '$filename': '$!'/ );
66 }
67  
68 return $fh;
69 }
70  
71 __PACKAGE__->meta->make_immutable;
72  
73 1;
74  
75 __END__
76  
77 =pod
78  
79 =encoding UTF-8
80  
81 =head1 NAME
82  
83 HTML::FormFu::QueryType::Catalyst - uploaded file
84  
85 =head1 VERSION
86  
87 version 2.06
88  
89 =head1 DESCRIPTION
90  
91 If you use L<Catalyst::Controller::HTML::FormFu>, it will automatically set
92 L<HTML::FormFu/query_type> to C<Catalyst>.
93  
94 =head1 METHODS
95  
96 =head2 headers
97  
98 =head2 filename
99  
100 =head2 fh
101  
102 =head2 slurp
103  
104 =head2 basename
105  
106 =head2 size
107  
108 =head2 tempname
109  
110 =head2 type
111  
112 =head1 REMOVED METHODS
113  
114 =head2 catalyst_upload
115  
116 We no longer keep a reference to the
117 L<Catalyst::Request::Upload|Catalyst::Request::Upload> object, as it
118 was causing issues under L<HTML::FormFu::MultiForm|HTML::FormFu::MultiForm>
119 after the L<Catalyst|Catalyst> 5.8 move to L<Moose|Moose>.
120  
121 =head2 copy_to
122  
123 Because L</catalyst_upload> has been removed, we can no-longer call this
124 L<Catalyst::Request::Upload|Catalyst::Request::Upload> method.
125  
126 =head2 link_to
127  
128 Because L</catalyst_upload> has been removed, we can no-longer call this
129 L<Catalyst::Request::Upload|Catalyst::Request::Upload> method.
130  
131 =head1 SEE ALSO
132  
133 Is a sub-class of, and inherits methods from
134 L<HTML::FormFu::Upload>
135  
136 L<HTML::FormFu>, L<HTML::FormFu::Element::File>
137  
138 =head1 AUTHOR
139  
140 Carl Franks, C<cfranks@cpan.org>
141  
142 =head1 LICENSE
143  
144 This library is free software, you can redistribute it and/or modify it under
145 the same terms as Perl itself.
146  
147 =head1 AUTHOR
148  
149 Carl Franks <cpan@fireartist.com>
150  
151 =head1 COPYRIGHT AND LICENSE
152  
153 This software is copyright (c) 2018 by Carl Franks.
154  
155 This is free software; you can redistribute it and/or modify it under
156 the same terms as the Perl 5 programming language system itself.
157  
158 =cut