Contract/ArgumentChecks.pm

filter: Statementstmt 100% 33 / 33 Branchbran 50.0% 1 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 90.9% 50 / 55 CC 3 SCAR 4.3
CC
3
Cov
92%
new
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Contract/Debug.pm ↑ Summary
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 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 23 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 23 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 23 ▶use accessors ('type', # 'in' or 'out'
Subroutine BEGIN: called CC=1 SCAR=0.0
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 23 );
18  
19 23 our $VERSION = '0.12';
20  
21 #---------------------------------------------------------------
22 #
23 # new - constructor
24 #
25  
26 107 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
Pod documented
27 107 my($class,$type) = @_;
28 107 ▶ $class = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
01070
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
29  
30 107 ▶ croak "BUG: type must be in or out" if ($type !~ /^(in|out)$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /^(in|out)$/ 0 107 107
31  
32 107 my $self = bless({},$class);
33 107 $self->type($type);
34 107 $self->list_checks([]);
35 107 $self->hash_checks({});
36 }
37  
38 113 ▶sub add_list_check {
Subroutine add_list_check: called CC=1 SCAR=0.0
Pod documented
39 113 my ($self,$check) = @_;
40 113 push @{$self->list_checks}, $check;
41 }
42  
43 72 ▶sub add_hash_check {
Subroutine add_hash_check: called CC=1 SCAR=0.0
Pod documented
44 72 my ($self,$key,$check) = @_;
45 72 $self->hash_checks->{$key} = $check;
46 }
47  
48 51 ▶sub has_list_args {
Subroutine has_list_args: called CC=1 SCAR=0.0
Pod documented
49 51 return scalar @{$_[0]->list_checks};
50 }
51  
52 158 ▶sub has_hash_args {
Subroutine has_hash_args: called CC=1 SCAR=0.0
Pod documented
53 158 return scalar keys %{$_[0]->hash_checks};
54 }
55  
56  
57 23 1;
58  
59 __END__
« Contract/Debug.pm ↑ Summary