line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::Lite::Constraint::File; |
2
|
3
|
|
|
3
|
|
1403
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
99
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
71
|
|
4
|
3
|
|
|
3
|
|
13
|
use FormValidator::Lite::Constraint; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
19
|
|
5
|
3
|
|
|
3
|
|
11
|
use Carp (); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
369
|
|
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__ |