Hello, Mailing List.
Attached to this email is a patch for two new HTML::FormFu constraints:
GreaterThan and LessThan (descriptions are in their respective pods).
Motivation:
Currently available constraints are not capable of evaluating situations
that require a value to be greater (or less) than a specified one.
Constraints such as Range, MaxRange, MinRange use equal to or greater
(less) than for their comparisons which is not helpful in times where
the value must be greater (less) than a specified one.
I believe these two new constraints provide valuable functionality to an
otherwise complete form processing framework.
//jp
Index: lib/HTML/FormFu/Constraint/GreaterThan.pm
===================================================================
--- lib/HTML/FormFu/Constraint/GreaterThan.pm (revision 0)
+++ lib/HTML/FormFu/Constraint/GreaterThan.pm (revision 0)
@@ -0,0 +1,63 @@
+package HTML::FormFu::Constraint::GreaterThan;
+
+use strict;
+use base 'HTML::FormFu::Constraint';
+use Scalar::Util qw(looks_like_number);
+
+__PACKAGE__->mk_item_accessors(qw(greaterthan));
+
+sub constrain_value {
+
+ my ($self,$value) = @_;
+
+ return 1 if !defined $value || $value eq '';
+ return if !looks_like_number($value);
+
+ if ( defined(my $greaterthan = $self->greaterthan) ) {
+ return 1 if $value > $greaterthan;
+ }
+
+ return 0;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+HTML::FormFu::Constraint::GreaterThan - Numerical Compare Constraint
+
+=head1 SYNOPSIS
+
+ type: greaterthan
+ lessthan: 1337
+
+=head1 DESCRIPTION
+
+Numerical compare constraint.
+
+This constraint doesn't honour the C<not()> value.
+
+=head1 METHODS
+
+=head2 greaterthan
+
+If defined, the input value must be greater than this.
+
+=head1 SEE ALSO
+
+Is a sub-class of, and inherits methods from L<HTML::FormFu::Constraint>
+
+L<HTML::FormFu>
+
+=head1 AUTHOR
+
+Justin Pacheco C<justinjpach...@gmail.com>
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
Index: lib/HTML/FormFu/Constraint/LessThan.pm
===================================================================
--- lib/HTML/FormFu/Constraint/LessThan.pm (revision 0)
+++ lib/HTML/FormFu/Constraint/LessThan.pm (revision 0)
@@ -0,0 +1,63 @@
+package HTML::FormFu::Constraint::LessThan;
+
+use strict;
+use base 'HTML::FormFu::Constraint';
+use Scalar::Util qw(looks_like_number);
+
+__PACKAGE__->mk_item_accessors(qw(lessthan));
+
+sub constrain_value {
+
+ my ($self,$value) = @_;
+
+ return 1 if !defined $value || $value eq '';
+ return if !looks_like_number($value);
+
+ if ( defined(my $lessthan = $self->lessthan) ) {
+ return 1 if $value < $lessthan;
+ }
+
+ return 0;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+HTML::FormFu::Constraint::LessThan - Numerical Compare Constraint
+
+=head1 SYNOPSIS
+
+ type: LessThan
+ lessthan: 1337
+
+=head1 DESCRIPTION
+
+Numerical compare constraint.
+
+This constraint doesn't honour the C<not()> value.
+
+=head1 METHODS
+
+=head2 lessthan
+
+If defined, the input value must be less than this.
+
+=head1 SEE ALSO
+
+Is a sub-class of, and inherits methods from L<HTML::FormFu::Constraint>
+
+L<HTML::FormFu>
+
+=head1 AUTHOR
+
+Justin Pacheco C<justinjpach...@gmail.com>
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
_______________________________________________
HTML-FormFu mailing list
HTML-FormFu@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu