Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f40865cb

Von Moritz Bunkus vor mehr als 12 Jahren hinzugefügt

  • ID f40865cb4d108adeaf77e56b4ac006251c27b180
  • Vorgänger 5e45f456
  • Nachfolger 4bcb4508

GetModels-Controller-Helper: Weitere URL-Parameter für Callbacks übergeben können

Unterschiede anzeigen:

SL/Controller/Helper/GetModels.pm
3 3
use strict;
4 4

  
5 5
use Exporter qw(import);
6
our @EXPORT = qw(get_callback get_models);
6
our @EXPORT = qw(get_models_url_params get_callback get_models);
7 7

  
8 8
use constant PRIV => '__getmodelshelperpriv';
9 9

  
......
21 21
  map { push @{ $registered_handlers{$_} }, $additional_handlers{$_} if $additional_handlers{$_} } keys %registered_handlers;
22 22
}
23 23

  
24
sub get_models_url_params {
25
  my ($class, $sub_name_or_code) = @_;
26

  
27
  my $code     = (ref($sub_name_or_code) || '') eq 'CODE' ? $sub_name_or_code : sub { shift->$sub_name_or_code(@_) };
28
  my $callback = sub {
29
    my ($self, %params)   = @_;
30
    my @additional_params = $code->($self);
31
    return (
32
      %params,
33
      (scalar(@additional_params) == 1) && (ref($additional_params[0]) eq 'HASH') ? %{ $additional_params[0] } : @additional_params,
34
    );
35
  };
36

  
37
  push @{ $registered_handlers{callback} }, $callback;
38
}
39

  
24 40
sub get_callback {
25 41
  my ($self, %override_params) = @_;
26 42

  
......
102 118

  
103 119
=over 4
104 120

  
121
=item C<get_models_url_params $class, $sub>
122

  
123
Register one of the controller's subs to be called whenever an URL has
124
to be generated (e.g. for sort and pagination links). This is a way
125
for the controller to add additional parameters to the URL (e.g. for
126
filter parameters).
127

  
128
The C<$sub> parameter can be either a code reference or the name of
129
one of the controller's functions.
130

  
131
The value returned by this C<$sub> must be either a single hash
132
reference or a hash of key/value pairs to add to the URL.
133

  
105 134
=item C<register_get_models_handlers $class, %handlers>
106 135

  
107 136
This function should only be called from other controller helpers like

Auch abrufbar als: Unified diff