blib/lib/Circle/Rule/Resultset.pm

filter: Statementstmt 27.0% 10 / 37 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 4 totaltotal 21.6% 13 / 60 SCAR 37.0
CC
8
Cov
20%
merge_from
30.0
push_result
12.0
get_result
6.0
CRAP 40.3
« blib/lib/Circle/Net/IRC/User.pm ↑ Summary blib/lib/Circle/Widget/Entry.pm »
1 # You may distribute under the terms of the GNU General Public License
2 #
3 # (C) Paul Evans, 2008-2010 -- leonerd@leonerd.org.uk
4  
5 package Circle::Rule::Resultset;
6  
7 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub new
13 {
14 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
15  
16 0 return bless {}, $class;
17 }
18  
19 sub get_result
20 {
21 0 ▶ my $self = shift;
Subroutine get_result: not called CC=2 SCAR=17.9
Pod undocumented
22 0 my ( $name ) = @_;
23  
24 0 ▶ carp "No result '$name'" unless exists $self->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$name} 0 0 0
25  
26 0 return $self->{$name};
27 }
28  
29 sub push_result
30 {
31 0 ▶ my $self = shift;
Subroutine push_result: not called CC=3 SCAR=24.8
Pod undocumented
32 0 my ( $name, $value ) = @_;
33  
34 0 ▶ if( !exists $self->{$name} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $self->{$name}) { } 0 0 0
elsif (ref $self->{$name} eq 'ARRAY') { } 0 0 0
35 0 $self->{$name} = [ $value ];
36 }
37 elsif( ref $self->{$name} eq "ARRAY" ) {
38 0 push @{ $self->{$name} }, $value;
39 }
40 else {
41 0 croak "Expected '$name' to be an ARRAY result";
42 }
43 }
44  
45 sub merge_from
46 {
47 0 ▶ my $self = shift;
Subroutine merge_from: not called CC=5 SCAR=34.0
Pod undocumented
48 0 my ( $other ) = @_;
49  
50 0 foreach my $name ( %$other ) {
51 0 my $otherval = $other->{$name};
52  
53 0 ▶ if( !$self->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{$name}) 0 0 0
54 0 $self->{$name} = $otherval;
55 0 next;
56 }
57  
58 0 my $myval = $self->{$name};
59  
60 # Already had it - type matches?
61 0 ▶ if( ref $myval ne ref $otherval ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $myval ne ref $otherval) 0 0 0
62 0 croak "Cannot merge; '$name' has different result types";
63 }
64  
65 0 my $type = ref $myval;
66  
67 0 ▶ if( ref $myval eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $myval eq 'ARRAY') { } 0 0 0
68 0 push @$myval, @$otherval;
69 }
70 else {
71 0 croak "Don't know how to handle result type '$name' ($type)";
72 }
73 }
74 }
75  
76 4 0x55AA;
« blib/lib/Circle/Net/IRC/User.pm ↑ Summary blib/lib/Circle/Widget/Entry.pm »