From 33d5d38a2873a25f1e9c2c37a907644fdd33f026 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 30 May 2013 11:33:27 +0200 Subject: [PATCH] registered_handlers pro Klasse speichern. Ansonsten kriegen sich mehrere Controller unter fcgi in die Haare. --- SL/Controller/Helper/GetModels.pm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/SL/Controller/Helper/GetModels.pm b/SL/Controller/Helper/GetModels.pm index 6b408b3f8..8e2ede133 100644 --- a/SL/Controller/Helper/GetModels.pm +++ b/SL/Controller/Helper/GetModels.pm @@ -7,7 +7,7 @@ our @EXPORT = qw(get_models_url_params get_callback get_models); use constant PRIV => '__getmodelshelperpriv'; -my %registered_handlers = ( callback => [], get_models => [] ); +my $registered_handlers = {}; sub register_get_models_handlers { my ($class, %additional_handlers) = @_; @@ -18,7 +18,8 @@ sub register_get_models_handlers { $class->run_before(sub { $_[0]->{PRIV()} = { current_action => $_[1] }; }, %hook_params); - map { push @{ $registered_handlers{$_} }, $additional_handlers{$_} if $additional_handlers{$_} } keys %registered_handlers; + my $handlers = _registered_handlers($class); + map { push @{ $handlers->{$_} }, $additional_handlers{$_} if $additional_handlers{$_} } keys %$handlers; } sub get_models_url_params { @@ -34,7 +35,7 @@ sub get_models_url_params { ); }; - push @{ $registered_handlers{callback} }, $callback; + push @{ _registered_handlers($class)->{callback} }, $callback; } sub get_callback { @@ -62,7 +63,7 @@ sub get_models { sub _run_handlers { my ($self, $handler_type, %params) = @_; - foreach my $sub (@{ $registered_handlers{$handler_type} }) { + foreach my $sub (@{ _registered_handlers(ref $self)->{$handler_type} }) { if (ref $sub eq 'CODE') { %params = $sub->($self, %params); } elsif ($self->can($sub)) { @@ -75,6 +76,10 @@ sub _run_handlers { return %params; } +sub _registered_handlers { + $registered_handlers->{$_[0]} //= { callback => [], get_models => [] } +} + 1; __END__ -- 2.20.1