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