FormValidator::Simple::Plugin::Trim - Trim fields for FormValidator::Simple


FormValidator-Simple-Plugin-Trim documentation Contained in the FormValidator-Simple-Plugin-Trim distribution.

Index


Code Index:

NAME

Top

FormValidator::Simple::Plugin::Trim - Trim fields for FormValidator::Simple

SYNOPSIS

Top

 use FormValidator::Simple qw/Trim/;

 my $query = CGI->new
 $query->param('int_param', "123 ");

 my $result = FormValidator::Simple->check( $query => [
  int_param => [ 'TRIM', 'INT' ]
 ] );

 $result->valid('int_param') == 123

DESCRIPTION

Top

A group of validators for use with FormValidator::Simple that will trim white space in differnet ways. Will always validate any data passed through them as valid.

VALIDATION COMMANDS

Top

TRIM

Trim leading and trailing white space

TRIM_LEAD

Trim leading white space

TRIM_TRAIL

Trim trailing white space

TRIM_COLLAPSE

Trim leading and trailing white space, and collapse all whitespace characters into a single space.

AUTHOR

Top

Ash Berlin <ash@cpan.org>

LICENSE

Top

Free software. You can redistribute it and/or modify it under the same terms as perl itself.


FormValidator-Simple-Plugin-Trim documentation Contained in the FormValidator-Simple-Plugin-Trim distribution.

package FormValidator::Simple::Plugin::Trim;

use strict;
use warnings;

our $VERSION = '1.00';

use FormValidator::Simple::Constants;

sub TRIM {
  my ($self, $params, $args) = @_;

  s/^\s*(.*?)\s*$/$1/ms foreach (@$params);

  return (TRUE, $#$params ? $params : $params->[0] );
}

sub TRIM_LEAD {
  my ($self, $params, $args) = @_;

  $DB::single = 1;
  s/^\s+(.*)$/$1/ms foreach (@$params);

  return (TRUE, $#$params ? $params : $params->[0] );
}

sub TRIM_TRAIL {
  my ($self, $params, $args) = @_;

  s/^(.*?)\s+$/$1/ms foreach (@$params);

  return (TRUE, $#$params ? $params : $params->[0] );
}

sub TRIM_COLLAPSE {
  my ($self, $params, $args) = @_;

  for (@$params) {
    s/\s+/ /g;
    s/^\s*(.*?)\s*$/$1/ms;
  }

  return (TRUE, $#$params ? $params : $params->[0] );
}
1;

__END__