line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Sub::Contract::ArgumentChecks - Conditions on input/return arguments |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: ArgumentChecks.pm,v 1.8 2009/06/16 12:23:58 erwan_lemonnier Exp $ |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Sub::Contract::ArgumentChecks; |
8
|
|
|
|
|
|
|
|
9
|
22
|
|
|
22
|
|
1283
|
use strict; |
|
22
|
|
|
|
|
43
|
|
|
22
|
|
|
|
|
729
|
|
10
|
22
|
|
|
22
|
|
116
|
use warnings; |
|
22
|
|
|
|
|
44
|
|
|
22
|
|
|
|
|
601
|
|
11
|
22
|
|
|
22
|
|
189
|
use Carp qw(croak); |
|
22
|
|
|
|
|
45
|
|
|
22
|
|
|
|
|
1184
|
|
12
|
22
|
|
|
22
|
|
116
|
use Data::Dumper; |
|
22
|
|
|
|
|
69
|
|
|
22
|
|
|
|
|
1484
|
|
13
|
|
|
|
|
|
|
|
14
|
22
|
|
|
|
|
546
|
use accessors ('type', # 'in' or 'out' |
15
|
|
|
|
|
|
|
'list_checks', # an anonymous array of checks on list-style passed arguments |
16
|
|
|
|
|
|
|
'hash_checks', # an anonymous hash of checks on hash-style passed arguments |
17
|
22
|
|
|
22
|
|
25314
|
); |
|
22
|
|
|
|
|
17965
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#--------------------------------------------------------------- |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# new - constructor |
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
107
|
|
|
107
|
1
|
163
|
my($class,$type) = @_; |
28
|
107
|
|
33
|
|
|
490
|
$class = ref $class || $class; |
29
|
|
|
|
|
|
|
|
30
|
107
|
50
|
|
|
|
556
|
croak "BUG: type must be in or out" if ($type !~ /^(in|out)$/); |
31
|
|
|
|
|
|
|
|
32
|
107
|
|
|
|
|
376
|
my $self = bless({},$class); |
33
|
107
|
|
|
|
|
438
|
$self->type($type); |
34
|
107
|
|
|
|
|
918
|
$self->list_checks([]); |
35
|
107
|
|
|
|
|
613
|
$self->hash_checks({}); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub add_list_check { |
39
|
113
|
|
|
113
|
1
|
324
|
my ($self,$check) = @_; |
40
|
113
|
|
|
|
|
164
|
push @{$self->list_checks}, $check; |
|
113
|
|
|
|
|
257
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub add_hash_check { |
44
|
72
|
|
|
72
|
1
|
118
|
my ($self,$key,$check) = @_; |
45
|
72
|
|
|
|
|
171
|
$self->hash_checks->{$key} = $check; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub has_list_args { |
49
|
51
|
|
|
51
|
1
|
67
|
return scalar @{$_[0]->list_checks}; |
|
51
|
|
|
|
|
153
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub has_hash_args { |
53
|
158
|
|
|
158
|
1
|
327
|
return scalar keys %{$_[0]->hash_checks}; |
|
158
|
|
|
|
|
429
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |