]> wagnertech.de Git - kivitendo-erp.git/blob - SL/Controller/Base.pm
Trennzeichen für Controller-Routing von :: auf / geändert
[kivitendo-erp.git] / SL / Controller / Base.pm
1 package SL::Controller::Base;
2
3 use parent qw(Rose::Object);
4
5 use List::Util qw(first);
6
7 sub parse_html_template {
8   my $self = shift;
9   my $name = shift;
10
11   return $::form->parse_html_template($name, { @_, SELF => $self });
12 }
13
14 sub url_for {
15   my $self = shift;
16
17   return $_[0] if scalar(@_) == 1;
18
19   my %params      = @_;
20   my $controller  = delete($params{controller}) || $self->_controller_name;
21   my $action      = delete($params{action})     || 'dispatch';
22   $params{action} = "${controller}/${action}";
23   my $query       = join('&', map { $::form->escape($_) . '=' . $::form->escape($params{$_}) } keys %params);
24
25   return "controller.pl?${query}";
26 }
27
28 sub _run_action {
29   my $self   = shift;
30   my $action = "action_" . shift;
31
32   return $self->_dispatch(@_) if $action eq 'action_dispatch';
33
34   $::form->error("Invalid action ${action} for controller " . ref($self)) if !$self->can($action);
35   $self->$action(@_);
36 }
37
38 sub _controller_name {
39   return (split(/::/, ref($_[0])))[-1];
40 }
41
42 sub _dispatch {
43   my $self    = shift;
44
45   my @actions = grep { m/^action_/ } keys %{ ref($self) . "::" };
46   my $action  = first { $::form->{$_} } @actions;
47
48   $self->$action(@_);
49 }
50
51 1;