File Coverage

blib/lib/Test/CallFlow/ArgCheck/Code.pm
Criterion Covered Total %
statement 7 7 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 11 11 100.0


line stmt bran cond sub pod time code
1             package Test::CallFlow::ArgCheck::Code;
2 2     2   12 use strict;
  2         2  
  2         208  
3 2     2   11 use base 'Test::CallFlow::ArgCheck';
  2         3  
  2         256  
4              
5             =head1 Test::CallFlow::ArgCheck::Code
6              
7             my $truth =
8             Test::CallFlow::ArgCheck::Code
9             ->new(
10             test => sub {
11             my ($self, $at, $args) = @_;
12             ref $args->[$at] =~ $self->{re}
13             },
14             re => qr/Good/
15             )
16             ->check( bless {}, 'My::Godness' );
17              
18             Delegates decision about validity of arguments to associated code reference (sub).
19              
20             See base class C.
21              
22             =head1 FUNCTIONS
23              
24             =head2 check
25              
26             $checker->check( 1, [ 'foo', 'bar' ] ) ? 'ok' : die;
27              
28             Checks given argument by calling associated code reference with it.
29              
30             Arguments passed to called sub are
31              
32             0. this ArgChecker object
33             1. position of argument to test
34             2. reference to array of arguments.
35              
36             This way the associated sub can be written like a member of this class, using its properties.
37              
38             =cut
39              
40             sub check {
41 8     8 1 24 $_[0]->{test}->(@_);
42             }
43              
44             1;
45