| 1 | 403 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | |||||||||||
| 3 | package HTML::FormFu::Filter; | ||||||||||
| 4 | 403 | $HTML::FormFu::Filter::VERSION = '2.06'; | |||||||||
| 5 | # ABSTRACT: Filter Base Class | ||||||||||
| 6 | |||||||||||
| 7 | 403 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 403 | ▶ | use MooseX::Attribute::Chained; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 403 | with 'HTML::FormFu::Role::NestedHashUtils', | |||||||||
| 11 | 'HTML::FormFu::Role::HasParent', | ||||||||||
| 12 | 'HTML::FormFu::Role::Populate'; | ||||||||||
| 13 | |||||||||||
| 14 | 403 | ▶ | use HTML::FormFu::Attribute qw( mk_inherited_accessors ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 403 | use HTML::FormFu::ObjectUtil qw( | |||||||||
| 16 | 403 | ▶ | form name parent nested_name nested_names ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 403 | has type => ( is => 'rw', traits => ['Chained'] ); | |||||||||
| 19 | |||||||||||
| 20 | 403 | has localize_args => ( is => 'rw', traits => ['Chained'] ); | |||||||||
| 21 | |||||||||||
| 22 | sub process { | ||||||||||
| 23 | 56 | ▶ | my ( $self, $result, $params ) = @_; | ||||||||
|
Subroutine
process: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||
| 24 | |||||||||||
| 25 | 56 | my $name = $self->nested_name; | |||||||||
| 26 | 56 | my $value = $self->get_nested_hash_value( $params, $name ); | |||||||||
| 27 | |||||||||||
| 28 | 56 | my $filtered; | |||||||||
| 29 | |||||||||||
| 30 | 56 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | $filtered = [ map { $self->filter( $_, $params ) } @$value ]; | |||||||||
| 32 | } | ||||||||||
| 33 | else { | ||||||||||
| 34 | 56 | $filtered = $self->filter( $value, $params ); | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 56 | $self->set_nested_hash_value( $params, $name, $filtered ); | |||||||||
| 38 | |||||||||||
| 39 | 56 | return; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | sub clone { | ||||||||||
| 43 | 6 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 44 | |||||||||||
| 45 | 6 | my %new = %$self; | |||||||||
| 46 | |||||||||||
| 47 | 6 | return bless \%new, ref $self; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 403 | __PACKAGE__->meta->make_immutable; | |||||||||
| 51 | |||||||||||
| 52 | 403 | 1; | |||||||||
| 53 | |||||||||||
| 54 | __END__ | ||||||||||
| 55 | |||||||||||
| 56 | =pod | ||||||||||
| 57 | |||||||||||
| 58 | =encoding UTF-8 | ||||||||||
| 59 | |||||||||||
| 60 | =head1 NAME | ||||||||||
| 61 | |||||||||||
| 62 | HTML::FormFu::Filter - Filter Base Class | ||||||||||
| 63 | |||||||||||
| 64 | =head1 VERSION | ||||||||||
| 65 | |||||||||||
| 66 | version 2.06 | ||||||||||
| 67 | |||||||||||
| 68 | =head1 SYNOPSIS | ||||||||||
| 69 | |||||||||||
| 70 | --- | ||||||||||
| 71 | elements: | ||||||||||
| 72 | - type: Text | ||||||||||
| 73 | name: foo | ||||||||||
| 74 | filters: | ||||||||||
| 75 | - type: Encode | ||||||||||
| 76 | candidates: | ||||||||||
| 77 | - utf8 | ||||||||||
| 78 | - Hebrew | ||||||||||
| 79 | - type: Text | ||||||||||
| 80 | name: bar | ||||||||||
| 81 | filters: | ||||||||||
| 82 | - LowerCase | ||||||||||
| 83 | - Encode | ||||||||||
| 84 | filters: | ||||||||||
| 85 | - TrimEdges | ||||||||||
| 86 | |||||||||||
| 87 | =head1 DESCRIPTION | ||||||||||
| 88 | |||||||||||
| 89 | C<filters()> and C<filter> can be called on any L<form|HTML::FormFu>, | ||||||||||
| 90 | L<block element|HTML::FormFu::Element::Block> (includes fieldsets) or | ||||||||||
| 91 | L<field element|HTML::FormFu::Role::Element::Field>. | ||||||||||
| 92 | |||||||||||
| 93 | If called on a field element, no C<name> argument should be passed. | ||||||||||
| 94 | |||||||||||
| 95 | If called on a L<form|HTML::FormFu> or | ||||||||||
| 96 | L<block element|HTML::FormFu::Element::Block>, if no C<name> argument is | ||||||||||
| 97 | provided, a new filter is created for and added to every field on that form | ||||||||||
| 98 | or block. | ||||||||||
| 99 | |||||||||||
| 100 | See L<HTML::FormFu/"FORM LOGIC AND VALIDATION"> for further details. | ||||||||||
| 101 | |||||||||||
| 102 | =head1 METHODS | ||||||||||
| 103 | |||||||||||
| 104 | =head2 type | ||||||||||
| 105 | |||||||||||
| 106 | Returns the C<type> argument originally used to create the filter. | ||||||||||
| 107 | |||||||||||
| 108 | =head2 localise_args | ||||||||||
| 109 | |||||||||||
| 110 | Provide arguments that should be passed to L<localize|HTML::FormFu/localize> | ||||||||||
| 111 | to replace C<[_1]>, C<[_2]>, etc. in the localized string. | ||||||||||
| 112 | |||||||||||
| 113 | =head2 parent | ||||||||||
| 114 | |||||||||||
| 115 | Returns the L<HTML::FormFu::Role::Element::Field> object that the filter is | ||||||||||
| 116 | associated with. | ||||||||||
| 117 | |||||||||||
| 118 | =head2 get_parent | ||||||||||
| 119 | |||||||||||
| 120 | Arguments: \%options | ||||||||||
| 121 | |||||||||||
| 122 | Traverses the parent hierarchy, returning the first parent that matches the | ||||||||||
| 123 | supplied options. | ||||||||||
| 124 | |||||||||||
| 125 | =head2 form | ||||||||||
| 126 | |||||||||||
| 127 | Returns the L<HTML::FormFu> object that the filter's field is attached to. | ||||||||||
| 128 | |||||||||||
| 129 | =head2 name | ||||||||||
| 130 | |||||||||||
| 131 | Shorthand for C<< $filter->parent->name >> | ||||||||||
| 132 | |||||||||||
| 133 | =head1 CORE FILTERS | ||||||||||
| 134 | |||||||||||
| 135 | =over | ||||||||||
| 136 | |||||||||||
| 137 | =item L<HTML::FormFu::Filter::Callback> | ||||||||||
| 138 | |||||||||||
| 139 | =item L<HTML::FormFu::Filter::CompoundJoin> | ||||||||||
| 140 | |||||||||||
| 141 | =item L<HTML::FormFu::Filter::CompoundSprintf> | ||||||||||
| 142 | |||||||||||
| 143 | =item L<HTML::FormFu::Filter::CopyValue> | ||||||||||
| 144 | |||||||||||
| 145 | =item L<HTML::FormFu::Filter::Default> | ||||||||||
| 146 | |||||||||||
| 147 | =item L<HTML::FormFu::Filter::Encode> | ||||||||||
| 148 | |||||||||||
| 149 | =item L<HTML::FormFu::Filter::ForceListValue> | ||||||||||
| 150 | |||||||||||
| 151 | =item L<HTML::FormFu::Filter::FormatNumber> | ||||||||||
| 152 | |||||||||||
| 153 | =item L<HTML::FormFu::Filter::HTMLEscape> | ||||||||||
| 154 | |||||||||||
| 155 | =item L<HTML::FormFu::Filter::HTMLScrubber> | ||||||||||
| 156 | |||||||||||
| 157 | =item L<HTML::FormFu::Filter::LowerCase> | ||||||||||
| 158 | |||||||||||
| 159 | =item L<HTML::FormFu::Filter::NonNumeric> | ||||||||||
| 160 | |||||||||||
| 161 | =item L<HTML::FormFu::Filter::Regex> | ||||||||||
| 162 | |||||||||||
| 163 | =item L<HTML::FormFu::Filter::Split> | ||||||||||
| 164 | |||||||||||
| 165 | =item L<HTML::FormFu::Filter::TrimEdges> | ||||||||||
| 166 | |||||||||||
| 167 | =item L<HTML::FormFu::Filter::UpperCase> | ||||||||||
| 168 | |||||||||||
| 169 | =item L<HTML::FormFu::Filter::Whitespace> | ||||||||||
| 170 | |||||||||||
| 171 | =back | ||||||||||
| 172 | |||||||||||
| 173 | =head1 FILTER BASE CLASSES | ||||||||||
| 174 | |||||||||||
| 175 | The following are base classes for other filters, and generally needn't be | ||||||||||
| 176 | used directly. | ||||||||||
| 177 | |||||||||||
| 178 | =over | ||||||||||
| 179 | |||||||||||
| 180 | =item L<HTML::FormFu::Filter::_Compound> | ||||||||||
| 181 | |||||||||||
| 182 | =back | ||||||||||
| 183 | |||||||||||
| 184 | =head1 AUTHOR | ||||||||||
| 185 | |||||||||||
| 186 | Carl Franks, C<cfranks@cpan.org> | ||||||||||
| 187 | |||||||||||
| 188 | Based on the original source code of L<HTML::Widget::Filter>, by | ||||||||||
| 189 | Sebastian Riedel. | ||||||||||
| 190 | |||||||||||
| 191 | =head1 LICENSE | ||||||||||
| 192 | |||||||||||
| 193 | This library is free software, you can redistribute it and/or modify it under | ||||||||||
| 194 | the same terms as Perl itself. | ||||||||||
| 195 | |||||||||||
| 196 | =head1 AUTHOR | ||||||||||
| 197 | |||||||||||
| 198 | Carl Franks <cpan@fireartist.com> | ||||||||||
| 199 | |||||||||||
| 200 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 201 | |||||||||||
| 202 | This software is copyright (c) 2018 by Carl Franks. | ||||||||||
| 203 | |||||||||||
| 204 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 205 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 206 | |||||||||||
| 207 | =cut | ||||||||||