line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::Lite::Constraint::File; |
2
|
3
|
|
|
3
|
|
1448
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
63
|
|
3
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
54
|
|
4
|
3
|
|
|
3
|
|
10
|
use FormValidator::Lite::Constraint; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
22
|
|
5
|
3
|
|
|
3
|
|
11
|
use Carp (); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
380
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
file_rule 'FILE_MIME' => sub { |
8
|
|
|
|
|
|
|
Carp::croak('missing args. usage: ["FILE_MIME", "text/plain"]') unless @_; |
9
|
|
|
|
|
|
|
my $expected = $_[0]; |
10
|
|
|
|
|
|
|
return $_->type =~ /^$expected$/; |
11
|
|
|
|
|
|
|
}; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
file_rule 'FILE_SIZE' => sub { |
14
|
|
|
|
|
|
|
Carp::croak('missing args. usage: ["FILE_SIZE", 1_000_000, 100]') unless @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $size = $_->size; |
17
|
|
|
|
|
|
|
my $max = shift; |
18
|
|
|
|
|
|
|
my $min = shift; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
return 0 if $max < $size; |
21
|
|
|
|
|
|
|
return 0 if defined($min) && $min > $size; |
22
|
|
|
|
|
|
|
return 1; |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
__END__ |