Switch to MRO::Compat
[catagits/Catalyst-Plugin-Cache.git] / lib / Catalyst / Plugin / Cache / Choose / KeyRegexes.pm
CommitLineData
c28ee69c 1#!/usr/bin/perl
2
3package Catalyst::Plugin::Cache::Choose::KeyRegexes;
4
5use strict;
6use warnings;
ab8e499f 7use MRO::Compat;
c28ee69c 8
9sub setup {
10 my $app = shift;
ab8e499f 11 my $ret = $app->maybe::next::method( @_ );
c28ee69c 12
13 my $regexes = $app->config->{cache}{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
20sub get_cache_key_regexes {
21 my ( $c, %meta ) = @_;
22 @{ $c->config->{cache}{key_regexes} };
23}
24
25sub 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
ab8e499f 34 $c->maybe::next::method( %meta );
c28ee69c 35}
36
37__PACKAGE__;
38
39__END__
40
41=pod
42
43=head1 NAME
44
45Catalyst::Plugin::Cache::Choose::KeyRegex - Choose a cache backend based on key regexes.
46
47=head1 SYNOPSIS
48
49 use Catalyst::Plugin::Cache::Choose::KeyRegex;
50
51=head1 DESCRIPTION
52
53=cut
54
55