| 1 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | package HTML::FormFu::Constraint::Callback; | ||||||||||||||||||||
| 4 | 3 | $HTML::FormFu::Constraint::Callback::VERSION = '2.06'; | |||||||||||||||||||
| 5 | # ABSTRACT: Code Callback Constraint | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | ▶ | use MooseX::Attribute::Chained; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 3 | extends 'HTML::FormFu::Constraint'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 3 | has callback => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | sub constrain_value { | ||||||||||||||||||||
| 14 | 5 | ▶ | my ( $self, $value, $params ) = @_; | ||||||||||||||||||
|
Subroutine
constrain_value: called CC=2 SCAR=7.3
Pod
undocumented
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 5 | ▶ | my $callback = $self->callback || sub {1}; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$self->callback || sub {
MC/DC0%0/2
$self->callback || sub {
1;
}
$self->callback
sub {
1;
}
Truth table33%1/3
A || B
A= $self->callbackB= sub {
1;
}
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | ## no critic (ProhibitNoStrict); | ||||||||||||||||||||
| 19 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 5 | my $ok = $callback->( $value, $params ); | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 5 | return $ok; | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 3 | 1; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | __END__ | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =pod | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =encoding UTF-8 | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =head1 NAME | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | HTML::FormFu::Constraint::Callback - Code Callback Constraint | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head1 VERSION | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | version 2.06 | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | =head1 SYNOPSIS | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | $field->constraint({ | ||||||||||||||||||||
| 47 | type => 'Callback', | ||||||||||||||||||||
| 48 | callback => \&foo, | ||||||||||||||||||||
| 49 | }); | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | --- | ||||||||||||||||||||
| 52 | elements: | ||||||||||||||||||||
| 53 | - type: Text | ||||||||||||||||||||
| 54 | name: foo | ||||||||||||||||||||
| 55 | constraints: | ||||||||||||||||||||
| 56 | - type: Callback | ||||||||||||||||||||
| 57 | callback: "main::my_constraint" | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | sub foo { | ||||||||||||||||||||
| 60 | my ( $value, $params ) = @_; | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | # return true or false | ||||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | =head1 DESCRIPTION | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | The first argument passed to the callback is the submitted value for the | ||||||||||||||||||||
| 68 | associated field. The second argument passed to the callback is a hashref of | ||||||||||||||||||||
| 69 | name/value pairs for all input fields. | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | This constraint doesn't honour the C<not()> value. | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | =head1 METHODS | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =head2 callback | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | Arguments: \&code-reference | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | Arguments: "subroutine-name" | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =head1 SEE ALSO | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | Is a sub-class of, and inherits methods from L<HTML::FormFu::Constraint> | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | L<HTML::FormFu> | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =head1 AUTHOR | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | Carl Franks C<cfranks@cpan.org> | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head1 LICENSE | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | This library is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||
| 94 | the same terms as Perl itself. | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =head1 AUTHOR | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | Carl Franks <cpan@fireartist.com> | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | This software is copyright (c) 2018 by Carl Franks. | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 105 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||