File: KeyRegexes.pm

package info (click to toggle)
libcatalyst-plugin-cache-perl 0.12-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 264 kB
  • sloc: perl: 1,855; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,008 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl

package Catalyst::Plugin::Cache::Choose::KeyRegexes;

use strict;
use warnings;
use MRO::Compat;

sub setup {
    my $app = shift;
    my $ret = $app->maybe::next::method( @_ );

    my $regexes = $app->_get_cache_plugin_config->{key_regexes} ||= [];

    die "the regex list must be an array containing regexex/backend pairs" unless ref $regexes eq "ARRAY";

    $ret;
}

sub get_cache_key_regexes {
    my ( $c, %meta ) = @_;
    @{ $c->_get_cache_plugin_config->{key_regexes} };
}

sub choose_cache_backend {
    my ( $c, %meta ) = @_;

    my @regexes = $c->get_cache_key_regexes( %meta );

    while ( @regexes and my ( $re, $backend ) = splice( @regexes, 0, 2 ) ) {
        return $backend if $meta{key} =~ $re;
    }

    $c->maybe::next::method( %meta );
}

__PACKAGE__;

__END__

=pod

=head1 NAME

Catalyst::Plugin::Cache::Choose::KeyRegex - Choose a cache backend based on key regexes.

=head1 SYNOPSIS

	use Catalyst::Plugin::Cache::Choose::KeyRegex;

=head1 DESCRIPTION

=cut