| 1 | package HTML::Widget::Filter; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | use base 'Class::Accessor::Chained::Fast'; | ||
| 6 | |||
| 7 | __PACKAGE__->mk_accessors(qw/names/); | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | HTML::Widget::Filter - Filter Base Class | ||
| 12 | |||
| 13 | =head1 SYNOPSIS | ||
| 14 | |||
| 15 | my $f = $widget->filter( $type, @names ); | ||
| 16 | $c->names(@names); | ||
| 17 | |||
| 18 | =head1 DESCRIPTION | ||
| 19 | |||
| 20 | Filter Base Class. | ||
| 21 | |||
| 22 | =head1 METHODS | ||
| 23 | |||
| 24 | =head2 filter | ||
| 25 | |||
| 26 | Arguments: $value | ||
| 27 | |||
| 28 | Return Value: $filtered_value | ||
| 29 | |||
| 30 | FIlter given value. | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | sub filter { return $_[0] } | ||
| 35 | |||
| 36 | =head2 init | ||
| 37 | |||
| 38 | Arguments: $widget | ||
| 39 | |||
| 40 | Called once when process() gets called for the first time. | ||
| 41 | |||
| 42 | =cut | ||
| 43 | |||
| 44 | sub init { } | ||
| 45 | |||
| 46 | =head2 names | ||
| 47 | |||
| 48 | Arguments: @names | ||
| 49 | |||
| 50 | Return Value: @names | ||
| 51 | |||
| 52 | Contains names of params to filter. | ||
| 53 | |||
| 54 | =head2 prepare | ||
| 55 | |||
| 56 | Arguments: $widget | ||
| 57 | |||
| 58 | Called whenever process() gets called. | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | sub prepare { } | ||
| 63 | |||
| 64 | =head2 process | ||
| 65 | |||
| 66 | Arguments: \%params, \@uploads | ||
| 67 | |||
| 68 | =cut | ||
| 69 | |||
| 70 | sub process { | ||
| 71 | my ( $self, $params ) = @_; | ||
| 72 | my @names = scalar @{ $self->names } ? @{ $self->names } : keys %$params; | ||
| 73 | for my $name (@names) { | ||
| 74 | my $values = $params->{$name}; | ||
| 75 | if ( ref $values eq 'ARRAY' ) { | ||
| 76 | $params->{$name} = [ map { $self->filter($_); } @$values ]; | ||
| 77 | } | ||
| 78 | else { | ||
| 79 | $params->{$name} = $self->filter($values); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | =head1 AUTHOR | ||
| 85 | |||
| 86 | Sebastian Riedel, C<sri@oook.de> | ||
| 87 | |||
| 88 | =head1 LICENSE | ||
| 89 | |||
| 90 | This library is free software, you can redistribute it and/or modify it under | ||
| 91 | the same terms as Perl itself. | ||
| 92 | |||
| 93 | =cut | ||
| 94 | |||
| 95 | 1; |