line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormFu::Constraint::File::Size; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
1376
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
157
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
17
|
use Moose; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
21
|
|
7
|
4
|
|
|
4
|
|
16373
|
use MooseX::Attribute::FormFuChained; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
86
|
|
8
|
4
|
|
|
4
|
|
13
|
use MooseX::Aliases; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
23
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends 'HTML::FormFu::Constraint'; |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
9902
|
use Carp qw( croak ); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
201
|
|
13
|
4
|
|
|
4
|
|
20
|
use Scalar::Util qw( blessed ); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1605
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has minimum => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
alias => 'min', |
18
|
|
|
|
|
|
|
traits => ['FormFuChained'], |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has maximum => ( |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
alias => 'max', |
24
|
|
|
|
|
|
|
traits => ['FormFuChained'], |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
*min_kilobyte = \&minimum_kilobyte; |
28
|
|
|
|
|
|
|
*max_kilobyte = \&maximum_kilobyte; |
29
|
|
|
|
|
|
|
*min_megabyte = \&minimum_megabyte; |
30
|
|
|
|
|
|
|
*max_megabyte = \&maximum_megabyte; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub constrain_value { |
33
|
8
|
|
|
8
|
0
|
8
|
my ( $self, $value ) = @_; |
34
|
|
|
|
|
|
|
|
35
|
8
|
100
|
66
|
|
|
34
|
return 1 if !defined $value || $value eq ''; |
36
|
|
|
|
|
|
|
|
37
|
7
|
100
|
66
|
|
|
44
|
return if !blessed($value) || !$value->isa('HTML::FormFu::Upload'); |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
109
|
my $min = $self->minimum; |
40
|
4
|
|
|
|
|
111
|
my $max = $self->maximum; |
41
|
|
|
|
|
|
|
|
42
|
4
|
|
100
|
|
|
82
|
my $size = $value->size || 0; |
43
|
|
|
|
|
|
|
|
44
|
4
|
100
|
|
|
|
13
|
if ( defined $min ) { |
45
|
3
|
100
|
|
|
|
12
|
return 0 if $size < $min; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
3
|
100
|
|
|
|
9
|
if ( defined $max ) { |
49
|
2
|
50
|
|
|
|
6
|
return 0 if $size > $max; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
8
|
return 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _localize_args { |
56
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $self->min, $self->max; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub minimum_kilobyte { |
62
|
0
|
|
|
0
|
1
|
|
my ( $self, $kb ) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
croak "minimum_kilobyte() cannot be used as a getter" |
65
|
|
|
|
|
|
|
if @_ != 2; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $self->minimum( $kb * 1024 ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub minimum_megabyte { |
71
|
0
|
|
|
0
|
1
|
|
my ( $self, $kb ) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
croak "minimum_megabyte() cannot be used as a getter" |
74
|
|
|
|
|
|
|
if @_ != 2; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $self->minimum( $kb * 1_048_576 ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub maximum_kilobyte { |
80
|
0
|
|
|
0
|
1
|
|
my ( $self, $kb ) = @_; |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
croak "maximum_kilobyte() cannot be used as a getter" |
83
|
|
|
|
|
|
|
if @_ != 2; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $self->maximum( $kb * 1024 ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub maximum_megabyte { |
89
|
0
|
|
|
0
|
1
|
|
my ( $self, $kb ) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
croak "maximum_megabyte() cannot be used as a getter" |
92
|
|
|
|
|
|
|
if @_ != 2; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $self->maximum( $kb * 1_048_576 ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 NAME |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
HTML::FormFu::Constraint::File::Size - File Size Constraint |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 VERSION |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
version 2.05 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 DESCRIPTION |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Ensure that an uploaded file meets minimum or maximum size constraints. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 METHODS |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 minimum |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 min |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Optional. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
The minimum file size in bytes. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L</min> is an alias for L</minimum>. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 maximum |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 max |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Optional. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
The maximum file size in bytes. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
L</max> is an alias for L</maximum>. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 minimum_kilobyte |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 min_kilobyte |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Shortcut for C<< $constraint->minimum( $value * 1024 ) >>. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L</min_kilobyte> is an alias for L</minimum_kilobyte>. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 maximum_kilobyte |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 max_kilobyte |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Shortcut for C<< $constraint->maximum( $value * 1024 ) >>. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
L</max_kilobyte> is an alias for L</maximum_kilobyte>. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 minimum_megabyte |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 min_megabyte |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Shortcut for C<< $constraint->minimum( $value * 1_048_576 ) >>. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
L</min_megabyte> is an alias for L</minimum_megabyte>. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 maximum_megabyte |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 max_megabyte |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Shortcut for C<< $constraint->maximum( $value * 1_048_576 ) >>. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L</max_megabyte> is an alias for L</maximum_megabyte>. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 SEE ALSO |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from L<HTML::FormFu::Constraint> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
L<HTML::FormFu> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 AUTHOR |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Carl Franks, C<cfranks@cpan.org> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 LICENSE |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
182
|
|
|
|
|
|
|
the same terms as Perl itself. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |