| 1 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Constraint::Range; | ||||||||||||||||||||||||||||
| 4 | 4 | $HTML::FormFu::Constraint::Range::VERSION = '2.06'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Numerical Range Constraint | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use MooseX::Attribute::Chained; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use MooseX::Aliases; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | extends 'HTML::FormFu::Constraint'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Scalar::Util qw( looks_like_number ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 4 | has minimum => ( | |||||||||||||||||||||||||||
| 16 | is => 'rw', | ||||||||||||||||||||||||||||
| 17 | alias => 'min', | ||||||||||||||||||||||||||||
| 18 | traits => ['Chained'], | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | has maximum => ( | |||||||||||||||||||||||||||
| 22 | is => 'rw', | ||||||||||||||||||||||||||||
| 23 | alias => 'max', | ||||||||||||||||||||||||||||
| 24 | traits => ['Chained'], | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub constrain_value { | ||||||||||||||||||||||||||||
| 28 | 12 | ▶ | my ( $self, $value ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
constrain_value: called CC=8 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 12 | ▶ | return 1 if !defined $value || $value eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $value or $value eq ""
MC/DC0%0/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table33%1/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 12 | ▶ | return if !looks_like_number($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 12 | ▶ | if ( defined( my $min = $self->minimum ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 8 | ▶ | return 0 if $value < $min; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 10 | ▶ | if ( defined( my $max = $self->maximum ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 7 | ▶ | return 0 if $value > $max; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 8 | return 1; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub _localize_args { | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_localize_args: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | return $self->min, $self->max; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 4 | 1; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =pod | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 NAME | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | HTML::FormFu::Constraint::Range - Numerical Range Constraint | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 VERSION | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | version 2.06 | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | type: Range | ||||||||||||||||||||||||||||
| 72 | min: 18 | ||||||||||||||||||||||||||||
| 73 | max: 35 | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Numerical range constraint. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | This constraint doesn't honour the C<not()> value. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =head1 METHODS | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head2 minimum | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head2 min | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | If defined, the input value must be equal to or greater than this. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | L</min> is an alias for L</minimum>. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head2 maximum | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head2 max | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | If defined, the input value must be equal to or less than this. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | L</max> is an alias for L</maximum>. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Is a sub-class of, and inherits methods from L<HTML::FormFu::Constraint> | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | L<HTML::FormFu> | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Carl Franks C<cfranks@cpan.org> | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | This library is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 112 | the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | Carl Franks <cpan@fireartist.com> | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | This software is copyright (c) 2018 by Carl Franks. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 123 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =cut | ||||||||||||||||||||||||||||