blib/lib/Acme/Affinity.pm

filter: Statementstmt 100% 46 / 46 Branchbran 58.3% 7 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 93.1% 68 / 73 CC 8 SCAR 7.0
CC
8
Cov
91%
_score
4.0
__ANON__
2.1
__ANON__
2.1
CRAP 2.0
↑ Summary
1 package Acme::Affinity;
2 2 our $AUTHORITY = 'cpan:GENE';
3  
4 # ABSTRACT: Compute the affinity between two people
5  
6 2 our $VERSION = '0.0114';
7  
8 2 ▶use Math::BigRat ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 has questions => (
15 is => 'ro',
16 4 ▶ isa => sub { die 'Not an ArrayRef' unless ref($_[0]) eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 4 4
17 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 2 required => 1,
19 );
20  
21  
22 has importance => (
23 is => 'ro',
24 4 ▶ isa => sub { die 'Not a HashRef' unless ref($_[0]) eq 'HASH' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 0 4 4
25 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
26 {
27 1 'irrelevant' => 0,
28 'a little important' => 1,
29 'somewhat important' => 10,
30 'very important' => 50,
31 'mandatory' => 250,
32 }
33 },
34 2 required => 1,
35 );
36  
37  
38 has me => (
39 is => 'ro',
40 4 ▶ isa => sub { die 'Not an ArrayRef' unless ref($_[0]) eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 4 4
41 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 2 required => 1,
43 );
44  
45  
46 has you => (
47 is => 'ro',
48 4 ▶ isa => sub { die 'Not an ArrayRef' unless ref($_[0]) eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 4 4
49 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
50 2 required => 1,
51 );
52  
53  
54 3 ▶sub score {
Subroutine score: called CC=1 SCAR=0.0
Pod documented
55 3 my $self = shift;
56  
57 3 my $me_score = _score( $self->me, $self->you, $self->importance );
58 3 my $you_score = _score( $self->you, $self->me, $self->importance );
59  
60 3 my $m = Math::BigRat->new($me_score);
61 3 my $y = Math::BigRat->new($you_score);
62  
63 3 my $question_count = Math::BigRat->new( scalar @{ $self->me } );
64  
65 3 my $product = $m->bmul($y);
66  
67 3 my $score = $product->broot($question_count);
68  
69 3 return $score->numify * 100;
70 }
71  
72 6 ▶sub _score {
Subroutine _score: called CC=4 SCAR=13.9
73 6 my ( $me, $you, $importance ) = @_;
74  
75 6 my $score = 0;
76 6 my $total = 0;
77  
78 6 for my $i ( 0 .. @$me - 1 ) {
79 12 $total += $importance->{ $me->[$i][2] };
80  
81 12 ▶ if ( $me->[$i][1] eq $you->[$i][0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($me->[$i][1] eq $you->[$i][0]) 6 6 12
82 6 $score += $importance->{ $me->[$i][2] };
83 }
84 }
85  
86 6 ▶ $score /= $total
Branch: 1 branch
BranchTrueFalseTotal
if $total != 0 6 0 6
87 if $total != 0;
88  
89 6 return $score;
90 }
91  
92 2 1;
93  
94 __END__
↑ Summary