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