OpenInteract2/ParamContainer.pm

filter: Statementstmt 93.6% 44 / 47 Branchbran 76.6% 23 / 30 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 5 totaltotal 80.6% 79 / 98 CC 19 SCAR 18.1
CC
19
Cov
86%
param_add
8.8
param
7.0
param_assign
5.0
CRAP 6.1
« OpenInteract2/Exception/Security.pm ↑ Summary OpenInteract2/Config/IniFile.pm »
1 package OpenInteract2::ParamContainer;
2  
3 # $Id: ParamContainer.pm,v 1.2 2005/02/13 20:19:10 lachoy Exp $
4  
5 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 87 $OpenInteract2::ParamContainer::VERSION = sprintf( "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/ );
9  
10 21 ▶sub get_skip_params { return () }
Subroutine get_skip_params: called CC=1 SCAR=0.0
Pod undocumented
11  
12 96 ▶sub param {
Subroutine param: called CC=7 SCAR=19.5
Pod undocumented
13 96 my ( $self, $key, $value ) = @_;
14 96 ▶ $self->{params} ||= {};
Condition100%2/2
$self->{"params"} ||= {}
l!l
7422
MC/DC100%1/1
$self->{"params"} ||= {}
$self->{"params"}
Truth table100%2/2
A
A= $self->{"params"}
Aresult
11
00
15 0 ▶ return \%{ $self->{params} } unless ( $key );
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 96 96
16 96 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 15 81 96
17 15 $self->{params}{ $key } = $value;
18 }
19 96 ▶ if ( ref $self->{params}{ $key } eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"params"}{$key} eq "ARRAY") 7 89 96
20 return ( wantarray )
21 2 ? @{ $self->{params}{ $key } }
22 7 ▶ : $self->{params}{ $key };
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 5 7
23 }
24 return ( wantarray )
25 ? ( $self->{params}{ $key } )
26 89 ▶ : $self->{params}{ $key };
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 88 89
27 }
28  
29 3 ▶sub param_add {
Subroutine param_add: called CC=8 SCAR=21.8
Pod undocumented
30 3 my ( $self, $key, @values ) = @_;
31 3 ▶ return undef unless ( $key );
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 3 3
32 3 ▶ $self->{params} ||= {};
Condition50%1/2
$self->{"params"} ||= {}
l!l
30
MC/DC0%0/1
$self->{"params"} ||= {}
$self->{"params"}
Truth table50%1/2
A
A= $self->{"params"}
Aresult
11
00
33 3 my $num_values = scalar @values;
34 3 ▶ return $self->{params}{ $key } unless ( scalar @values );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @values 0 3 3
35 3 ▶ if ( my $existing = $self->{params}{ $key } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $existing = $self->{'params'}{$key}) { } 2 1 3
36 2 my $typeof = ref( $existing );
37 2 ▶ if ( $typeof eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($typeof eq 'ARRAY') { } 1 1 2
elsif (not $typeof) { } 1 0 1
38 1 push @{ $self->{params}{ $key } }, @values;
39 }
40 elsif ( ! $typeof ) {
41 1 $self->{params}{ $key } = [ $existing, @values ];
42 }
43 else {
44 0 oi_error "Cannot add $num_values values to parameter '$key' ",
45 "since the parameter is defined as a '$typeof' to ",
46 "which I cannot reliably add values.";
47 }
48 }
49 else {
50 1 ▶ if ( $num_values == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num_values == 1) { } 0 1 1
51 0 $self->{params}{ $key } = $values[0];
52 }
53 else {
54 1 $self->{params}{ $key } = [ @values ];
55 }
56 }
57 3 return $self->param( $key );
58 }
59  
60 2 ▶sub param_clear {
Subroutine param_clear: called CC=2 SCAR=7.1
Pod undocumented
61 2 my ( $self, $key ) = @_;
62 2 ▶ $self->{params} ||= {};
Condition50%1/2
$self->{"params"} ||= {}
l!l
20
MC/DC0%0/1
$self->{"params"} ||= {}
$self->{"params"}
Truth table50%1/2
A
A= $self->{"params"}
Aresult
11
00
63 2 return delete $self->{params}{ $key };
64 }
65  
66 24 ▶sub param_assign {
Subroutine param_assign: called CC=5 SCAR=16.2
Pod undocumented
67 24 my ( $self, $params ) = @_;
68 24 ▶ return unless ( ref $params eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $params eq "HASH" 0 24 24
69 24 my %skip_params = $self->get_skip_params();
70 24 ▶ while ( my ( $key, $value ) = each %{ $params } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$params;}) 8 24 32
71 8 ▶ next if ( $skip_params{ $key } );
Branch: 1 branch
BranchTrueFalseTotal
if $skip_params{$key} 3 5 8
72 5 ▶ next unless ( defined $value );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 5 5
73 5 $self->param( $key, $value );
74 }
75 24 return $self;
76 }
77  
78 87 1;
79  
80 __END__
« OpenInteract2/Exception/Security.pm ↑ Summary OpenInteract2/Config/IniFile.pm »