line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Eidolon::Driver::Router::Consequent; |
2
|
|
|
|
|
|
|
# ============================================================================== |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Eidolon |
5
|
|
|
|
|
|
|
# Copyright (c) 2009, Atma 7 |
6
|
|
|
|
|
|
|
# --- |
7
|
|
|
|
|
|
|
# Eidolon/Driver/Router/Consequent.pm - consequent regexp router |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# ============================================================================== |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
74219
|
use base qw/Eidolon::Driver::Router/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
87
|
|
12
|
1
|
|
|
1
|
|
6
|
use List::Util qw/first/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
145
|
|
13
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
100
|
|
14
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
608
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = "0.01"; # 2009-04-06 05:10:02 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
19
|
|
|
|
|
|
|
# find_handler() |
20
|
|
|
|
|
|
|
# find query handler |
21
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
22
|
|
|
|
|
|
|
sub find_handler |
23
|
|
|
|
|
|
|
{ |
24
|
0
|
|
|
0
|
1
|
|
my ($self, $r, $query, @params, $route, $ctrl, $handler); |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$self = shift; |
27
|
0
|
|
|
|
|
|
$r = Eidolon::Core::Registry->get_instance; |
28
|
0
|
|
0
|
|
|
|
$query = $r->cgi->get_query || "/"; |
29
|
0
|
|
|
|
|
|
$route = undef; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
throw DriverError::Router::NoRoutes if (!exists $r->config->{"routes"}); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# find matching route |
34
|
0
|
|
|
0
|
|
|
$route = first { @params = $query =~ /^$_$/ } keys %{ $r->config->{"routes"} }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# do neccessary checks |
37
|
0
|
0
|
|
|
|
|
throw DriverError::Router::NotFound($query) if (!$route); |
38
|
0
|
0
|
0
|
|
|
|
throw DriverError::Router::Forbidden if |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
39
|
|
|
|
|
|
|
( |
40
|
|
|
|
|
|
|
$r->loader->get_object("Eidolon::Driver::User") && |
41
|
|
|
|
|
|
|
!$r->loader->get_object("Eidolon::Driver::User")->authorized && |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
( |
44
|
|
|
|
|
|
|
$r->config->{"app"}->{"policy"} eq "private" && |
45
|
|
|
|
|
|
|
!defined($r->config->{"routes"}->{ $route }->[2]) || |
46
|
|
|
|
|
|
|
defined($r->config->{"routes"}->{ $route }->[2]) && |
47
|
|
|
|
|
|
|
$r->config->{"routes"}->{ $route }->[2] eq "private" |
48
|
|
|
|
|
|
|
) |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$ctrl = $r->config->{"routes"}->{ $route }->[0]; |
52
|
0
|
|
0
|
|
|
|
$handler = $r->config->{"routes"}->{ $route }->[1] || "default"; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# try to load the controller |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
0
|
|
|
local $SIG{"__DIE__"} = sub {}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
eval "require $ctrl"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
throw CoreError::Compile($@) if $@; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$self->{"controller"} = $ctrl; |
63
|
0
|
|
|
|
|
|
$self->{"handler"} = "$ctrl\::$handler"; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# delete undefined parameters |
66
|
0
|
|
|
|
|
|
foreach (0 .. $#params) |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
0
|
|
|
|
|
delete $params[$_] unless (defined $params[$_]); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->{"params"} = \@params; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |