| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||