File Coverage

blib/lib/HTML/FormFu/Constraint/File.pm
Criterion Covered Total %
statement 12 12 100.0
branch 2 2 100.0
condition 4 6 66.6
subroutine 4 4 100.0
pod 0 1 0.0
total 22 25 88.0


line stmt bran cond sub pod time code
1 2     2   839 use strict;
  2         6  
  2         128  
2              
3             package HTML::FormFu::Constraint::File;
4             $HTML::FormFu::Constraint::File::VERSION = '2.07';
5             # ABSTRACT: File Upload Constraint
6              
7 2     2   14 use Moose;
  2         4  
  2         18  
8             extends 'HTML::FormFu::Constraint';
9              
10 2     2   14057 use Scalar::Util qw( blessed );
  2         6  
  2         322  
11              
12             sub constrain_value {
13 4     4 0 12 my ( $self, $value ) = @_;
14              
15 4 100 66     22 return 1 if !defined $value || $value eq '';
16              
17 3   66     23 return blessed($value) && $value->isa('HTML::FormFu::Upload');
18             }
19              
20             __PACKAGE__->meta->make_immutable;
21              
22             1;
23              
24             __END__
25              
26             =pod
27              
28             =encoding UTF-8
29              
30             =head1 NAME
31              
32             HTML::FormFu::Constraint::File - File Upload Constraint
33              
34             =head1 VERSION
35              
36             version 2.07
37              
38             =head1 DESCRIPTION
39              
40             Ensure the submitted value is a file upload.
41              
42             This Constraint is not needed if you use any of the C<File::*> Constraints,
43             as they all make the same check as this Constraint does.
44              
45             =head1 LIMITATIONS
46              
47             This can only verify that your CGI backend (CGI, Catalyst, CGI::Simple)
48             thinks it was a file upload. If the user submits a filename which doesn't
49             exist on their system, you will probably get a valid L<HTML::FormFu::Upload>
50             object, with a valid filehandle, but no Content-Length. This Constraint
51             would still see this as a valid uploaded file - if you want to ensure that
52             you get a file with content, instead use
53             L<HTML::FormFu::Constraint::File::Size> with
54             L<min|HTML::FormFu::Constraint::File::Size/min> set to C<1>.
55              
56             =head1 SEE ALSO
57              
58             Is a sub-class of, and inherits methods from L<HTML::FormFu::Constraint>
59              
60             L<HTML::FormFu>
61              
62             =head1 AUTHOR
63              
64             Carl Franks, C<cfranks@cpan.org>
65              
66             =head1 LICENSE
67              
68             This library is free software, you can redistribute it and/or modify it under
69             the same terms as Perl itself.
70              
71             =head1 AUTHOR
72              
73             Carl Franks <cpan@fireartist.com>
74              
75             =head1 COPYRIGHT AND LICENSE
76              
77             This software is copyright (c) 2018 by Carl Franks.
78              
79             This is free software; you can redistribute it and/or modify it under
80             the same terms as the Perl 5 programming language system itself.
81              
82             =cut