Permalink
Browse files

[delivers #15285829] Provide a function to resolve Plack localizer co…

…nfiguration
  • Loading branch information...
ctfliblime committed Jul 2, 2011
1 parent 47edced commit 5d38de7396c2ab0dd0fec385fabacd9e7bbe2dbb
Showing with 15 additions and 2 deletions.
  1. +15 −2 Koha/Plack/Localize.pm
View
@@ -2,14 +2,27 @@ package Koha::Plack::Localize;
use parent qw(Plack::Middleware);
use Koha;
-use Plack::Util::Accessor qw(host_map);
+use Plack::Util::Accessor qw(host_map host_mapper);
use Koha::Plack::Util;
+sub regex_mapper {
+ my $env = shift;
+ my $host_regexes = shift;
+ my $hostname = Koha::Plack::Util::GetCanonicalHostname($env);
+
+ for my $r (keys %$host_regexes) {
+ return $host_regexes->{$r} if ($hostname =~ $r);
+ }
+}
+
sub call {
my ($self, $env) = @_;
my $config;
- if (my $configs = $self->host_map) {
+ if ($self->host_mapper) {
+ $config = $self->host_mapper->($env);
+ }
+ elsif (my $configs = $self->host_map) {
my $hostname = Koha::Plack::Util::GetCanonicalHostname($env);
$config = $configs->{$hostname};
}

0 comments on commit 5d38de7

Please sign in to comment.