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