1use strict;
2
3package HTML::FormFu::Filter::Callback;
4$HTML::FormFu::Filter::Callback::VERSION = '2.07';
5# ABSTRACT: filter with custom subroutine
6
7use Moose;
8use MooseX::Attribute::Chained;
9extends 'HTML::FormFu::Filter';
10
11has callback => ( is => 'rw', traits => ['Chained'] );
12
13sub filter {
14    my ( $self, $value, $params ) = @_;
15
16    my $callback = $self->callback || sub {$value};
17
18    ## no critic (ProhibitNoStrict);
19    no strict 'refs';
20
21    return $callback->( $value, $params );
22}
23
24__PACKAGE__->meta->make_immutable;
25
261;
27
28__END__
29
30=pod
31
32=encoding UTF-8
33
34=head1 NAME
35
36HTML::FormFu::Filter::Callback - filter with custom subroutine
37
38=head1 VERSION
39
40version 2.07
41
42=head1 SYNOPSIS
43
44    $field->filter({
45        type     => 'Callback',
46        callback => \&my_filter,
47    });
48
49    ---
50    elements:
51      - type: Text
52        name: foo
53        filters:
54          - type: Callback
55            callback: "main::my_filter"
56
57    sub my_filter {
58        my ($value) = @_;
59
60        # do something to $value
61
62        return $value;
63    }
64
65=head1 DESCRIPTION
66
67Filter using a user-provided subroutine.
68
69=head1 METHODS
70
71=head2 callback
72
73Arguments: \&code-reference
74
75Arguments: "subroutine-name"
76
77=head1 AUTHOR
78
79Carl Franks, C<cfranks@cpan.org>
80
81Based on the original source code of L<HTML::Widget::Filter::Callback>, by
82Lyo Kato, C<lyo.kato@gmail.com>
83
84=head1 LICENSE
85
86This library is free software, you can redistribute it and/or modify it under
87the same terms as Perl itself.
88
89=head1 AUTHOR
90
91Carl Franks <cpan@fireartist.com>
92
93=head1 COPYRIGHT AND LICENSE
94
95This software is copyright (c) 2018 by Carl Franks.
96
97This is free software; you can redistribute it and/or modify it under
98the same terms as the Perl 5 programming language system itself.
99
100=cut
101