TypeSafe/Question.pm

filter: Statementstmt 88.7% 63 / 71 Branchbran 50.0% 9 / 18 Conditioncond 44.4% 8 / 18 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 89.4% 17 / 19 Podpod 0.0% 0 / 4 totaltotal 70.2% 99 / 141 CC 16 SCAR 17.1
CC
16
Cov
75%
new
19.1
_args
5.2
new
4.0
CRAP 5.5
« TypeSafe/RetryPolicy.pm ↑ Summary TypeSafe/Error.pm »
1 package WebService::TypeSafe::Question;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶sub _args {
Subroutine _args: called CC=4 SCAR=16.4
9 11 my (@args) = @_;
10 0 ▶ return %{ $args[0] } if @args == 1 && ref($args[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if @args == 1 and ref $args[0] eq "HASH" 0 11 11
Condition33%1/3
@args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
1100
MC/DC0%0/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1 ref $args[0] eq "HASH"
Truth table33%1/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
ABresult
0X0
100
111
11 11 ▶ croak 'constructor expects named arguments' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 11 11
12 11 return @args;
13 }
14  
15 11 ▶sub _base {
Subroutine _base: called CC=2 SCAR=7.0
16 11 my ($class, $type, @args) = @_;
17 11 my %args = _args(@args);
18 11 my %allowed = map { $_ => 1 } qw(instructions criteria);
19 11 my @unknown = grep { !$allowed{$_} } keys %args;
20 11 ▶ croak 'unknown question field(s): ' . join(', ', sort @unknown) if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 0 11 11
21 11 return bless { type => $type, %args }, $class;
22 }
23  
24 6 ▶sub as_hash { return { %{ $_[0] } } }
Subroutine as_hash: called CC=1 SCAR=0.0
Pod undocumented
25 3 ▶sub type { return $_[0]->{type} }
Subroutine type: called CC=1 SCAR=0.0
Pod undocumented
26 0 ▶sub instructions { return $_[0]->{instructions} }
Subroutine instructions: not called CC=1 SCAR=6.9
Pod undocumented
27 0 ▶sub criteria { return $_[0]->{criteria} }
Subroutine criteria: not called CC=1 SCAR=6.9
Pod undocumented
28  
29 package WebService::TypeSafe::Question::Choice;
30 3 ▶use parent -norequire, 'WebService::TypeSafe::Question';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 3 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
33 3 my ($class, @args) = @_;
34 3 my $self = $class->_base('choice', @args);
35 croak 'Choice criteria must be a nonempty hash reference'
36 3 ▶ unless ref($self->{criteria}) eq 'HASH' && keys %{ $self->{criteria} };
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"criteria"} eq "HASH" and keys %{$$self{"criteria"};} 1 2 3
Condition66%2/3
ref $self->{"criteria"} eq "HASH" and keys %{$$self{"criteria"};}
!ll&&!rl&&r
012
MC/DC50%1/2
ref $self->{"criteria"} eq "HASH" and keys %{$$self{"criteria"};}
ref $self->{"criteria"} eq "HASH" keys %{$$self{"criteria"};}
Truth table66%2/3
A and B
A= ref $self->{"criteria"} eq "HASH"B= keys %{$$self{"criteria"};}
ABresult
0X0
100
111
37 2 ▶ croak 'Choice accepts at most 255 criteria' if keys(%{ $self->{criteria} }) > 255;
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"criteria"};} > 255 0 2 2
38 2 return $self;
39 }
40  
41 package WebService::TypeSafe::Question::Noul;
42 3 ▶use parent -norequire, 'WebService::TypeSafe::Question';
Subroutine BEGIN: called CC=1 SCAR=0.0
43 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
44 6 ▶sub new {
Subroutine new: called CC=6 SCAR=29.5
45 6 my ($class, @args) = @_;
46 6 my $self = $class->_base('noul', @args);
47 6 ▶ if (exists $self->{criteria} && defined $self->{criteria}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"criteria"} and defined $self->{"criteria"}) 0 6 6
Condition33%1/3
exists $self->{"criteria"} and defined $self->{"criteria"}
!ll&&!rl&&r
600
MC/DC0%0/2
exists $self->{"criteria"} and defined $self->{"criteria"}
exists $self->{"criteria"} defined $self->{"criteria"}
Truth table33%1/3
A and B
A= exists $self->{"criteria"}B= defined $self->{"criteria"}
ABresult
0X0
100
111
48 croak 'Noul criteria must be a hash reference'
49 0 ▶ unless ref($self->{criteria}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"criteria"} eq "HASH" 0 0 0
50 0 ▶ my @bad = grep { $_ ne 'true' && $_ ne 'false' } keys %{ $self->{criteria} };
Condition0%0/3
$_ ne 'true' && $_ ne 'false'
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne 'true' && $_ ne 'false'
$_ ne 'true' $_ ne 'false'
Truth table0%0/3
A && B
A= $_ ne 'true'B= $_ ne 'false'
ABresult
0X0
100
111
51 0 ▶ croak 'Noul criteria only accepts true and false keys' if @bad;
Branch: 1 branch
BranchTrueFalseTotal
if @bad 0 0 0
52 }
53 6 return $self;
54 }
55  
56 package WebService::TypeSafe::Question::Score;
57 3 ▶use parent -norequire, 'WebService::TypeSafe::Question';
Subroutine BEGIN: called CC=1 SCAR=0.0
58 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
59 2 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
60 2 my ($class, @args) = @_;
61 2 my $self = $class->_base('score', @args);
62 croak 'Score criteria must be an array reference with 2 to 10 levels'
63 unless ref($self->{criteria}) eq 'ARRAY'
64 2 ▶ && @{ $self->{criteria} } >= 2 && @{ $self->{criteria} } <= 10;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"criteria"} eq "ARRAY" and @{$self->{"criteria"};} >= 2 and @{$self->{"criteria"};} <= 10 1 1 2
Condition66%4/6
ref $self->{"criteria"} eq "ARRAY" and @{$self->{"criteria"};} >= 2 and @{$self->{"criteria"};} <= 10
!ll&&!rl&&r
101
ref $self->{"criteria"} eq "ARRAY" and @{$self->{"criteria"};} >= 2
!ll&&!rl&&r
011
MC/DC33%1/3
ref $self->{"criteria"} eq "ARRAY" and @{$self->{"criteria"};} >= 2 and @{$self->{"criteria"};} <= 10
ref $self->{"criteria"} eq "ARRAY" @{$self->{"criteria"};} >= 2 @{$self->{"criteria"};} <= 10
Truth table50%2/4
A and B and C
A= ref $self->{"criteria"} eq "ARRAY"B= @{$self->{"criteria"};} >= 2C= @{$self->{"criteria"};} <= 10
ABCresult
0XX0
10X0
1100
1111
65 1 return $self;
66 }
67  
68 3 1;
« TypeSafe/RetryPolicy.pm ↑ Summary TypeSafe/Error.pm »