Config/DriverPool.pm

filter: Statementstmt 86.0% 37 / 43 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 3 / 3 totaltotal 88.5% 54 / 61 CC 3 SCAR 3.1
CC
3
Cov
85%
get_driver
2.3
add_driver
2.1
BEGIN
1.0
CRAP 1.4
« Config/Driver.pm ↑ Summary
1 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package CHI::Config::DriverPool;
6  
7 3 our $VERSION = '0.001001'; # TRIAL
8  
9 # ABSTRACT: A Collection of Driver definitions
10  
11 3 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 3 ▶use Moo qw( has );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Carp qw( carp croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 ## no critic (ValuesAndExpressions::ProhibitConstantPragma)
17 3 ▶use constant DEBUGGING => $ENV{CHI_CONFIG_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 ▶has '_drivers' => ( is => ro =>, lazy => 1, default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
20  
21 8 ▶sub add_driver {
Subroutine add_driver: called CC=2 SCAR=7.6
Pod documented
22 8 my ( $self, %config ) = @_;
23  
24 8 require CHI::Config::Driver;
25  
26 8 my $instance = CHI::Config::Driver->new(%config);
27 8 my $name = $instance->name;
28  
29 8 ▶ if ( not exists $self->_drivers->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->_drivers->{$name}) 4 4 8
30 4 $self->_drivers->{$name} = $instance;
31 4 return;
32 }
33 4 return unless DEBUGGING;
34 ## Shadowing should be default anyway.
35 0 my $template = '%s: %s';
36 0 my $old = sprintf $template, ' Kept', $self->_drivers->{$name}->source;
37 0 my $new = sprintf $template, 'Ignored', $instance->source;
38 0 carp "Duplicate Driver definition ignored\n\t$old\n\t$new\n";
39 0 return;
40 }
41  
42 4 ▶sub get_driver {
Subroutine get_driver: called CC=2 SCAR=8.1
Pod documented
43 4 my ( $self, $name ) = @_;
44 4 ▶ return $self->_drivers->{$name} if exists $self->_drivers->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->_drivers->{$name} 4 0 4
45 0 croak "No default for driver <$name> defined and none specified in configuration";
46 }
47  
48 4 ▶sub get_cache {
Subroutine get_cache: called CC=1 SCAR=0.0
Pod documented
49 4 my ( $self, $name ) = @_;
50 4 return $self->get_driver($name)->get_cache;
51 }
52  
53 3 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 3 1;
56  
57 __END__
« Config/Driver.pm ↑ Summary