blib/lib/Versionify/Dispatch.pm

filter: Statementstmt 100% 44 / 44 Branchbran 100% 10 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 69 / 69 CC 7 SCAR 11.9
CC
7
Cov
100%
get_function
6.0
register
2.0
BEGIN
1.0
CRAP 3.3
↑ Summary
1 package Versionify::Dispatch;
2  
3 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use MooseX::FollowPBP;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Sort::Versions;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use version; our $VERSION = qv('0.2.4');
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 has 'default_version' => (
11 is => 'rw',
12 isa => 'Str',
13 );
14  
15 3 has 'function' => (
16 is => 'rw',
17 isa => 'HashRef[CodeRef]',
18 reader => '_get_function',
19 writer => 'set_function',
20 );
21  
22 10 ▶sub get_function {
Subroutine get_function: called CC=6 SCAR=17.9
Pod documented
23 10 my $self = shift;
24 10 my $version = shift;
25
26 10 ▶ $version ||= $self->get_default_version;
Condition100%3/3
$version ||= $self->get_default_version
l!l&&r!l&&!r
532
MC/DC100%2/2
$version ||= $self->get_default_version
$version $self->get_default_version
Truth table100%3/3
A ||= B
A= $versionB= $self->get_default_version
ABresult
1X1
011
000
27
28 10 my $function_lookup_ref = $self->_get_function;
29 10 ▶ if($version)
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 8 2 10
30 {
31 8 my $matching_function = $function_lookup_ref->{$version};
32 8 ▶ return $matching_function if $matching_function;
Branch: 1 branch
BranchTrueFalseTotal
if $matching_function 3 5 8
33 }
34 7 my @available_versions = keys %$function_lookup_ref;
35 7 ▶ @available_versions = grep {versioncmp($version, $_) > 0} @available_versions if $version;
Branch: 1 branch
BranchTrueFalseTotal
if $version 5 2 7
36 7 @available_versions = sort {versioncmp($a, $b)} @available_versions;
37 7 ▶ croak 'No valid functions stored' unless @available_versions;
Branch: 1 branch
BranchTrueFalseTotal
unless @available_versions 1 6 7
38
39 6 return $function_lookup_ref->{$available_versions[-1]};
40 }
41  
42 2 ▶sub register{
Subroutine register: called CC=2 SCAR=6.9
Pod documented
43 2 my $self = shift;
44 2 my %functions_to_register = @_;
45
46 2 my $function_lookup_ref = $self->_get_function;
47 2 ▶ my %function_lookup = $function_lookup_ref ? %$function_lookup_ref : ();
Branch: 1 branch
BranchTrueFalseTotal
$function_lookup_ref ? : 1 1 2
48 2 my @new_function_versions = keys %functions_to_register;
49
50 2 @function_lookup{@new_function_versions} = @functions_to_register{@new_function_versions};
51 2 $self->set_function(\%function_lookup);
52 }
53  
54 3 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 3 __PACKAGE__->meta->make_immutable;
56  
57  
58 3 1; # Magic true value required at end of module
59 __END__
↑ Summary