line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Kelp::Base 'Kelp::Routes'; |
3
|
1
|
|
|
1
|
|
408
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
53
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
188
|
|
5
|
|
|
|
|
|
|
my $self = shift; |
6
|
|
|
|
|
|
|
my $app = shift or croak "no app supplied"; |
7
|
6
|
|
|
6
|
1
|
9
|
my $match = shift or croak "no route pattern instance supplied"; |
8
|
6
|
50
|
|
|
|
13
|
|
9
|
6
|
50
|
|
|
|
21
|
my $to = $match->to or croak 'No destination defined'; |
10
|
|
|
|
|
|
|
|
11
|
6
|
50
|
|
|
|
14
|
return $self->SUPER::dispatch($app, $match) if ref $to; |
12
|
|
|
|
|
|
|
|
13
|
6
|
100
|
|
|
|
17
|
my ($controller_class, $action) = ($to =~ /^(.+)::(\w+)$/) |
14
|
|
|
|
|
|
|
or croak "Invalid controller '$to'"; |
15
|
5
|
50
|
|
|
|
32
|
|
16
|
|
|
|
|
|
|
my $controller = $app->_clone($controller_class); |
17
|
|
|
|
|
|
|
return $controller->$action(@{ $match->param }); |
18
|
5
|
|
|
|
|
21
|
} |
19
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
10
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
1; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=pod |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Kelp::Routes::Controller - Routes and controller for Kelp |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# config.pl |
33
|
|
|
|
|
|
|
# --------- |
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
modules_init => { |
36
|
|
|
|
|
|
|
Routes => { |
37
|
|
|
|
|
|
|
base => 'MyApp::Controller', |
38
|
|
|
|
|
|
|
router => 'Controller' |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# MyApp/Controller.pm |
44
|
|
|
|
|
|
|
# ------------------- |
45
|
|
|
|
|
|
|
package MyApp::Controller; |
46
|
|
|
|
|
|
|
use Kelp::Base 'MyApp'; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub shared_method { |
49
|
|
|
|
|
|
|
my $self = shift; # $self is an instance of 'MyApp::Controller' |
50
|
|
|
|
|
|
|
... |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# MyApp/Controller/Users.pm |
55
|
|
|
|
|
|
|
# ------------------------- |
56
|
|
|
|
|
|
|
package MyApp::Controller::Users; |
57
|
|
|
|
|
|
|
use Kelp::Base 'MyApp::Controller'; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub read { |
60
|
|
|
|
|
|
|
my $self = shift; # $self is an instance of 'MyApp::Controller::Users' |
61
|
|
|
|
|
|
|
... |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This router module reblesses a Kelp application into its own controller class. |
68
|
|
|
|
|
|
|
This allows you to structure your web application in a classic object oriented |
69
|
|
|
|
|
|
|
fashion, having C<$self> an instance to the current class rather than the main |
70
|
|
|
|
|
|
|
web application. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
You must create a main I<controller> class which inherits from Kelp. Each |
73
|
|
|
|
|
|
|
subsequent class can inherit from this class, taking advantage of any common |
74
|
|
|
|
|
|
|
functionality. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |