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