Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 29637d3f

Von Moritz Bunkus vor etwa 12 Jahren hinzugefügt

  • ID 29637d3f54132b3c10293f3600902d107127cdbc
  • Vorgänger 706d20f4
  • Nachfolger a99a31d6

Controller-Base: _controller_name in controller_name umbenennen; action_name() ergänzt

Unterschiede anzeigen:

SL/Controller/Base.pm
10 10
use SL::Request qw(flatten);
11 11
use SL::MoreCommon qw(uri_encode);
12 12

  
13
use Rose::Object::MakeMethods::Generic
14
(
15
  scalar => [ qw(action_name) ],
16
);
17

  
13 18
#
14 19
# public/helper functions
15 20
#
......
20 25
  return $_[0] if (scalar(@_) == 1) && !ref($_[0]);
21 26

  
22 27
  my %params      = ref($_[0]) eq 'HASH' ? %{ $_[0] } : @_;
23
  my $controller  = delete($params{controller}) || $self->_controller_name;
28
  my $controller  = delete($params{controller}) || $self->controller_name;
24 29
  my $action      = $params{action}             || 'dispatch';
25 30

  
26 31
  my $script;
......
124 129
  $file->close;
125 130
}
126 131

  
132
sub controller_name {
133
  my $class = ref($_[0]) || $_[0];
134
  $class    =~ s/^SL::Controller:://;
135
  return $class;
136
}
137

  
127 138
#
128 139
# Before/after run hooks
129 140
#
......
198 209

  
199 210
  $::form->error("Invalid action '${action}' for controller " . ref($self)) if !$self->can($sub);
200 211

  
212
  $self->action_name($action);
201 213
  $self->_run_hooks('before', $action);
202 214
  $self->$sub(@_);
203 215
  $self->_run_hooks('after', $action);
204 216
}
205 217

  
206
sub _controller_name {
207
  my $class = ref($_[0]) || $_[0];
208
  $class    =~ s/^SL::Controller:://;
209
  return $class;
210
}
211

  
212 218
sub _dispatch {
213 219
  my $self    = shift;
214 220

  
......
218 224
  my $sub     = "action_${action}";
219 225

  
220 226
  if ($self->can($sub)) {
227
    $self->action_name($action);
221 228
    $self->_run_hooks('before', $action);
222 229
    $self->$sub(@_);
223 230
    $self->_run_hooks('after', $action);
......
470 477

  
471 478
The controller to call is given by C<$params{controller}>. It defaults
472 479
to the current controller as returned by
473
L</_controller_name>.
480
L</controller_name>.
474 481

  
475 482
The action to call is given by C<$params{action}>. It defaults to
476 483
C<dispatch>.
......
543 550
request is routed. Only controllers that handle login requests
544 551
themselves should return trueish for this function.
545 552

  
553
=item C<controller_name>
554

  
555
Returns the name of the curernt controller package without the
556
C<SL::Controller::> prefix. This method can be called both as a class
557
method and an instance method.
558

  
559
=item C<action_name>
560

  
561
Returns the name of the currently executing action. If the dispatcher
562
mechanism was used then this is not C<dispatch> but the actual method
563
name the dispatching resolved to.
564

  
546 565
=back
547 566

  
548 567
=head2 PRIVATE FUNCTIONS
......
551 570

  
552 571
=over 4
553 572

  
554
=item C<_controller_name>
555

  
556
Returns the name of the curernt controller package without the
557
C<SL::Controller::> prefix.
558

  
559 573
=item C<_dispatch>
560 574

  
561 575
Implements the method lookup for indirect dispatching mentioned in the
SL/Controller/Helper/Paginated.pm
12 12
sub make_paginated {
13 13
  my ($class, %specs)       = @_;
14 14

  
15
  $specs{MODEL}           ||=  $class->_controller_name;
15
  $specs{MODEL}           ||=  $class->controller_name;
16 16
  $specs{MODEL}             =~ s{ ^ SL::DB:: (?: .* :: )? }{}x;
17 17
  $specs{PER_PAGE}        ||= "SL::DB::Manager::$specs{MODEL}"->default_objects_per_page;
18 18
  $specs{FORM_PARAMS}     ||= [ qw(page per_page) ];
SL/Controller/Helper/Sorted.pm
12 12
sub make_sorted {
13 13
  my ($class, %specs) = @_;
14 14

  
15
  $specs{MODEL} ||=  $class->_controller_name;
15
  $specs{MODEL} ||=  $class->controller_name;
16 16
  $specs{MODEL}   =~ s{ ^ SL::DB:: (?: .* :: )? }{}x;
17 17

  
18 18
  while (my ($column, $spec) = each %specs) {

Auch abrufbar als: Unified diff