| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Eidolon::Driver::Router::Basic; |
|
2
|
|
|
|
|
|
|
# ============================================================================== |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# Eidolon |
|
5
|
|
|
|
|
|
|
# Copyright (c) 2009, Atma 7 |
|
6
|
|
|
|
|
|
|
# --- |
|
7
|
|
|
|
|
|
|
# Eidolon/Driver/Router/Basic.pm - basic router |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# ============================================================================== |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
84166
|
use base qw/Eidolon::Driver::Router/; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
84
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use List::Util qw/first/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
134
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
25
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
13252
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = "0.02"; # 2009-04-06 01:41:56 |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
19
|
|
|
|
|
|
|
# $ _find_controller($items) |
|
20
|
|
|
|
|
|
|
# find controller |
|
21
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
22
|
|
|
|
|
|
|
sub _find_controller |
|
23
|
|
|
|
|
|
|
{ |
|
24
|
0
|
|
|
0
|
|
|
my ($self, $items, $r, $ctrl, $ctrl_path, $module); |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
($self, $items) = @_; |
|
27
|
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$r = Eidolon::Core::Registry->get_instance; |
|
29
|
0
|
|
|
|
|
|
$ctrl = ""; |
|
30
|
0
|
|
|
|
|
|
$ctrl_path = $r->config->{"app"}->{"lib"} . "/" . |
|
31
|
|
|
|
|
|
|
$r->config->{"app"}->{"name"} . "/Controller/"; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# compose controller's name |
|
34
|
0
|
|
|
|
|
|
while ($_ = shift(@$items)) |
|
35
|
|
|
|
|
|
|
{ |
|
36
|
0
|
|
|
|
|
|
$module = ucfirst($_); |
|
37
|
0
|
|
|
|
|
|
$ctrl_path .= "/$module"; |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
0
|
0
|
|
|
|
if (-d $ctrl_path) |
|
|
|
0
|
0
|
|
|
|
|
|
40
|
|
|
|
|
|
|
{ |
|
41
|
0
|
|
|
|
|
|
$ctrl .= "::$module"; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
elsif (-f "$ctrl_path.pm" && ($module ne "Default" || $ctrl)) |
|
44
|
|
|
|
|
|
|
{ |
|
45
|
0
|
|
|
|
|
|
$ctrl .= "::$module"; |
|
46
|
0
|
|
|
|
|
|
last; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
else |
|
49
|
|
|
|
|
|
|
{ |
|
50
|
0
|
|
|
|
|
|
unshift(@$items, $_); |
|
51
|
0
|
|
|
|
|
|
last; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
$ctrl = "::Default" if (!$ctrl); |
|
56
|
0
|
|
|
|
|
|
$self->{"controller"} = $r->config->{"app"}->{"name"}."::Controller$ctrl"; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
60
|
|
|
|
|
|
|
# _find_action($items) |
|
61
|
|
|
|
|
|
|
# find action |
|
62
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
63
|
|
|
|
|
|
|
sub _find_action |
|
64
|
|
|
|
|
|
|
{ |
|
65
|
0
|
|
|
0
|
|
|
my ($self, $r, $items, $handler, $ctrl, $action, @params); |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
($self, $items) = @_; |
|
68
|
0
|
0
|
0
|
|
|
|
$action = ($items && (@$items > 0)) ? join("/", @$items) : undef; |
|
69
|
0
|
|
|
|
|
|
$handler = undef; |
|
70
|
0
|
|
|
|
|
|
$ctrl = $self->{"controller"}; |
|
71
|
0
|
|
|
|
|
|
$r = Eidolon::Core::Registry->get_instance; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
{ |
|
74
|
0
|
|
|
0
|
|
|
local $SIG{"__DIE__"} = sub {}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
eval "require $ctrl"; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
throw CoreError::Compile($@) if ($@); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# find action |
|
81
|
0
|
0
|
|
|
|
|
if ($action) |
|
82
|
|
|
|
|
|
|
{ |
|
83
|
|
|
|
|
|
|
$handler = first |
|
84
|
|
|
|
|
|
|
{ |
|
85
|
0
|
0
|
|
0
|
|
|
/^Action\(['|"]?(.+?)['|"]?\)$/o && |
|
86
|
|
|
|
|
|
|
(@params = $action =~ /^$1$/) |
|
87
|
0
|
|
|
|
|
|
} keys %{ $ctrl->code_cache }; |
|
|
0
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# if handler was found |
|
90
|
0
|
0
|
|
|
|
|
if ($handler) |
|
91
|
|
|
|
|
|
|
{ |
|
92
|
0
|
|
|
|
|
|
$handler = $ctrl->code_cache->{ $handler }; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# delete undefined parameters |
|
95
|
0
|
|
|
|
|
|
foreach (0 .. $#params) |
|
96
|
|
|
|
|
|
|
{ |
|
97
|
0
|
0
|
|
|
|
|
delete $params[$_] unless (defined $params[$_]); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$self->{"params"} = \@params; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
else |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
0
|
|
|
|
|
|
$handler = $ctrl->code_cache->{"Default"}; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
throw DriverError::Router::NotFound if (!$handler); |
|
109
|
|
|
|
|
|
|
throw DriverError::Router::Forbidden if |
|
110
|
|
|
|
|
|
|
( |
|
111
|
|
|
|
|
|
|
$r->loader->get_object("Eidolon::Driver::User") && |
|
112
|
|
|
|
|
|
|
!$r->loader->get_object("Eidolon::Driver::User")->authorized && |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
( |
|
115
|
|
|
|
|
|
|
( |
|
116
|
|
|
|
|
|
|
$r->config->{"app"}->{"policy"} eq "private" && |
|
117
|
0
|
|
|
0
|
|
|
!first { /^Public$/ } @{ $ctrl->attr_cache->{$handler} } |
|
118
|
|
|
|
|
|
|
) || |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
0
|
0
|
0
|
|
|
first { /^Private$/ } @{ $ctrl->attr_cache->{$handler} } |
|
|
0
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
121
|
|
|
|
|
|
|
) |
|
122
|
|
|
|
|
|
|
); |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$self->{"handler"} = $handler; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
128
|
|
|
|
|
|
|
# find_handler() |
|
129
|
|
|
|
|
|
|
# find query handler |
|
130
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
|
131
|
|
|
|
|
|
|
sub find_handler |
|
132
|
|
|
|
|
|
|
{ |
|
133
|
0
|
|
|
0
|
1
|
|
my ($self, $r, $query, @items); |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
$self = shift; |
|
136
|
0
|
|
|
|
|
|
$r = Eidolon::Core::Registry->get_instance; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
$query = $r->cgi->get_query; |
|
139
|
0
|
0
|
|
|
|
|
@items = $query ? split /\//, $query : (); |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
$self->_find_controller( \@items ); |
|
142
|
0
|
|
|
|
|
|
$self->_find_action ( \@items ); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |