HTML::Widget::Constraint::AllOrNone - AllOrNone Constraint


HTML-Widget documentation Contained in the HTML-Widget distribution.

Index


Code Index:

NAME

Top

HTML::Widget::Constraint::AllOrNone - AllOrNone Constraint

SYNOPSIS

Top

    my $c = $widget->constraint( 'AllOrNone', 'foo', 'bar' );

DESCRIPTION

Top

AllOrNone means that if one is filled out, all of them have to be.

METHODS

Top

process

AUTHOR

Top

Marcus Ramberg, mramberg@cpan.org

LICENSE

Top

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


HTML-Widget documentation Contained in the HTML-Widget distribution.
package HTML::Widget::Constraint::AllOrNone;

use warnings;
use strict;
use base 'HTML::Widget::Constraint';

sub process {
    my ( $self, $w, $params ) = @_;
    my $results = [];
    my $one;
    for my $name ( @{ $self->names } ) {
        if ($self->not
            ? ( defined $params->{$name} && length $params->{$name} )
            : ( !defined $params->{$name} || !length $params->{$name} ) )
        {
            push @$results, HTML::Widget::Error->new(
                { name => $name, message => $self->mk_message } );
        }
        else {
            $one++;
        }
    }
    return ( $one ? $results : [] );
}

1;