| 1 | package HTML::Widget::Constraint::Equal; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | use base 'HTML::Widget::Constraint'; | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | HTML::Widget::Constraint::Equal - Equal Constraint | ||
| 10 | |||
| 11 | =head1 SYNOPSIS | ||
| 12 | |||
| 13 | my $c = $widget->constraint( 'Equal', 'foo', 'bar' ); | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | Equal Constraint. All provided elements must be the same. Combine this | ||
| 18 | with the All constraint to make sure all elements are equal. | ||
| 19 | |||
| 20 | =head1 METHODS | ||
| 21 | |||
| 22 | =head2 process | ||
| 23 | |||
| 24 | =cut | ||
| 25 | |||
| 26 | sub process { | ||
| 27 | my ( $self, $w, $params ) = @_; | ||
| 28 | my $results = []; | ||
| 29 | my $equal = $params->{ ${ $self->names }[0] }; | ||
| 30 | my $failures = 0; | ||
| 31 | |||
| 32 | for my $name ( @{ $self->names } ) { | ||
| 33 | $failures++ if $params->{$name} ne $equal; | ||
| 34 | } | ||
| 35 | |||
| 36 | if ($failures) { | ||
| 37 | for my $name ( @{ $self->names } ) { | ||
| 38 | push @$results, HTML::Widget::Error->new( | ||
| 39 | { name => $name, message => $self->mk_message } ); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | return $results; | ||
| 44 | } | ||
| 45 | |||
| 46 | =head2 render_errors | ||
| 47 | |||
| 48 | Arguments: @names | ||
| 49 | |||
| 50 | A list of element names for which an error should be displayed. | ||
| 51 | |||
| 52 | If this is not set, the default behaviour is for the error to be displayed | ||
| 53 | for all of the Constraint's named elements. | ||
| 54 | |||
| 55 | =head1 AUTHOR | ||
| 56 | |||
| 57 | Marcus Ramberg, C<mramberg@cpan.org> | ||
| 58 | |||
| 59 | =head1 LICENSE | ||
| 60 | |||
| 61 | This library is free software, you can redistribute it and/or modify it under | ||
| 62 | the same terms as Perl itself. | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | 1; |