Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 93f51d62

Von Moritz Bunkus vor etwa 12 Jahren hinzugefügt

  • ID 93f51d6216763896c85506cb815a9acbd653d4d5
  • Vorgänger 220746bf
  • Nachfolger 011c1238

Vermeidung von Package-Variablen

Unterschiede anzeigen:

SL/Controller/Helper/GetModels.pm
5 5
use Exporter qw(import);
6 6
our @EXPORT = qw(get_callback get_models);
7 7

  
8
my $current_action;
8
use constant PRIV => '__getmodelshelperpriv';
9

  
9 10
my %registered_handlers = ( callback => [], get_models => [] );
10 11

  
11 12
sub register_get_models_handlers {
......
15 16
  $only           = [ $only ] if !ref $only;
16 17
  my %hook_params = @{ $only } ? ( only => $only ) : ();
17 18

  
18
  $class->run_before(sub { $current_action = $_[1]; }, %hook_params);
19
  $class->run_before(sub { $_[0]->{PRIV()} = { current_action => $_[1] }; }, %hook_params);
19 20

  
20 21
  map { push @{ $registered_handlers{$_} }, $additional_handlers{$_} if $additional_handlers{$_} } keys %registered_handlers;
21 22
}
......
23 24
sub get_callback {
24 25
  my ($self, %override_params) = @_;
25 26

  
26
  my %default_params = _run_handlers($self, 'callback', action => $current_action);
27
  my %default_params = _run_handlers($self, 'callback', action => ($self->{PRIV()} || {})->{current_action});
27 28

  
28 29
  return $self->url_for(%default_params, %override_params);
29 30
}

Auch abrufbar als: Unified diff