From: Sven Schöling Date: Thu, 30 May 2013 09:33:27 +0000 (+0200) Subject: registered_handlers pro Klasse speichern. X-Git-Tag: release-3.1.0beta1~401^2~2 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=33d5d38a2873a25f1e9c2c37a907644fdd33f026;p=kivitendo-erp.git registered_handlers pro Klasse speichern. Ansonsten kriegen sich mehrere Controller unter fcgi in die Haare. --- 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__