line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Widget::Constraint::Length; |
2
|
|
|
|
|
|
|
|
3
|
88
|
|
|
88
|
|
91515
|
use warnings; |
|
88
|
|
|
|
|
299
|
|
|
88
|
|
|
|
|
2756
|
|
4
|
88
|
|
|
88
|
|
495
|
use strict; |
|
88
|
|
|
|
|
196
|
|
|
88
|
|
|
|
|
2661
|
|
5
|
88
|
|
|
88
|
|
474
|
use base 'HTML::Widget::Constraint'; |
|
88
|
|
|
|
|
194
|
|
|
88
|
|
|
|
|
22934
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/minimum maximum/); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
*min = \&minimum; |
10
|
|
|
|
|
|
|
*max = \&maximum; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
HTML::Widget::Constraint::Length - Length Constraint |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $c = $widget->constraint( 'Length', 'foo' ); |
19
|
|
|
|
|
|
|
$c->min(23); |
20
|
|
|
|
|
|
|
$c->max(50); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Length Constraint. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 METHODS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 maximum |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Arguments: $max_value |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 minimum |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Arguments: $min_value |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 validate |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub validate { |
41
|
11
|
|
|
11
|
1
|
20
|
my ( $self, $value ) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Return valid on an empty value |
44
|
11
|
50
|
|
|
|
57
|
return 1 unless defined($value); |
45
|
11
|
100
|
|
|
|
24
|
return 1 if ( $value eq '' ); |
46
|
|
|
|
|
|
|
|
47
|
10
|
|
|
|
|
30
|
my $minimum = $self->minimum; |
48
|
10
|
|
|
|
|
66
|
my $maximum = $self->maximum; |
49
|
10
|
|
|
|
|
44
|
my $failed = 0; |
50
|
10
|
50
|
|
|
|
25
|
if ($minimum) { |
51
|
10
|
50
|
|
|
|
39
|
$failed++ unless ( length($value) >= $minimum ); |
52
|
|
|
|
|
|
|
} |
53
|
10
|
50
|
|
|
|
26
|
if ($maximum) { |
54
|
10
|
100
|
|
|
|
49
|
$failed++ unless ( length($value) <= $maximum ); |
55
|
|
|
|
|
|
|
} |
56
|
10
|
|
|
|
|
31
|
return !$failed; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 AUTHOR |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Sebastian Riedel, C |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 LICENSE |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
66
|
|
|
|
|
|
|
the same terms as Perl itself. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |