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