Cache/Choose/KeyRegexes.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 44 CC 3 SCAR 13.9
CC
3
Cov
0%
setup
6.0
choose_cache_backend
6.0
get_cache_key_regexes
2.0
CRAP 4.0
1 #!/usr/bin/perl
2  
3 package Catalyst::Plugin::Cache::Choose::KeyRegexes;
4  
5 use strict;
6 use warnings;
7 use MRO::Compat;
8  
9 sub setup {
10 my $app = shift;
11 my $ret = $app->maybe::next::method( @_ );
12  
13 my $regexes = $app->_get_cache_plugin_config->{key_regexes} ||= [];
14  
15 die "the regex list must be an array containing regexex/backend pairs" unless ref $regexes eq "ARRAY";
16  
17 $ret;
18 }
19  
20 sub get_cache_key_regexes {
21 my ( $c, %meta ) = @_;
22 @{ $c->_get_cache_plugin_config->{key_regexes} };
23 }
24  
25 sub choose_cache_backend {
26 my ( $c, %meta ) = @_;
27  
28 my @regexes = $c->get_cache_key_regexes( %meta );
29  
30 while ( @regexes and my ( $re, $backend ) = splice( @regexes, 0, 2 ) ) {
31 return $backend if $meta{key} =~ $re;
32 }
33  
34 $c->maybe::next::method( %meta );
35 }
36  
37 __PACKAGE__;
38  
39 __END__