Form::Factory::Feature::Control::Trim - Trims whitespace from a control value


Form-Factory documentation Contained in the Form-Factory distribution.

Index


Code Index:

NAME

Top

Form::Factory::Feature::Control::Trim - Trims whitespace from a control value

VERSION

Top

version 0.020

SYNOPSIS

Top

  has_control title => (
      control => 'text',
      features => {
          trim => 1,
      },
  );

DESCRIPTION

Top

Strips whitespace from the front and back of the given values.

METHODS

Top

check_control

Reports an error unless the control is a scalar value.

clean

Strips whitespace from the start and end of the control value.

AUTHOR

Top

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Top


Form-Factory documentation Contained in the Form-Factory distribution.
package Form::Factory::Feature::Control::Trim;
BEGIN {
  $Form::Factory::Feature::Control::Trim::VERSION = '0.020';
}
use Moose;

with qw( 
    Form::Factory::Feature 
    Form::Factory::Feature::Role::Clean
    Form::Factory::Feature::Role::Control
);

use Carp ();

sub check_control {
    my ($self, $control) = @_;

    return if $control->does('Form::Factory::Control::Role::ScalarValue');

    Carp::croak("the trim feature only works on scalar values, not $control");
}

sub clean {
    my $self    = shift;
    my $control = $self->control;

    my $value   = $control->current_value;
    $value =~ s/^\s*//;
    $value =~ s/\s*$//;

    $control->current_value($value);
}

1;