line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cake::Controllers;
|
2
|
8
|
|
|
8
|
|
47
|
use warnings;
|
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
321
|
|
3
|
8
|
|
|
8
|
|
39
|
use strict;
|
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
258
|
|
4
|
8
|
|
|
8
|
|
74
|
use base 'Exporter';
|
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
10117
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw(
|
7
|
|
|
|
|
|
|
dispatcher
|
8
|
|
|
|
|
|
|
auto_chain
|
9
|
|
|
|
|
|
|
);
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $dispatch = bless ({},__PACKAGE__);
|
12
|
|
|
|
|
|
|
my $auto_chain = {};
|
13
|
|
|
|
|
|
|
my @methods = ('get','post','delete','put');
|
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
0
|
13
|
sub dispatcher {$dispatch}
|
16
|
3
|
|
|
3
|
0
|
20
|
sub auto_chain {$auto_chain}
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
##returns last added controller action
|
19
|
0
|
|
|
0
|
0
|
0
|
sub Action { return shift->{lastAction}; }
|
20
|
0
|
|
|
0
|
0
|
0
|
sub Path { return shift->{path}; }
|
21
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
22
|
|
|
|
|
|
|
# FIXME::: Not sure what should be fixed here
|
23
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
24
|
|
|
|
|
|
|
sub dispatch {
|
25
|
5
|
|
|
5
|
0
|
10
|
my $self = shift;
|
26
|
5
|
|
|
|
|
11
|
my $type = shift;
|
27
|
5
|
|
|
|
|
9
|
my $path = shift;
|
28
|
5
|
|
|
|
|
14
|
my @types = ($type);
|
29
|
|
|
|
|
|
|
|
30
|
5
|
50
|
|
|
|
31
|
if (ref $path eq 'ARRAY'){
|
|
|
50
|
|
|
|
|
|
31
|
0
|
|
|
|
|
0
|
@types = @{$path};
|
|
0
|
|
|
|
|
0
|
|
32
|
0
|
|
|
|
|
0
|
$path = shift;
|
33
|
|
|
|
|
|
|
}
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
elsif ($type eq 'any'){
|
36
|
0
|
|
|
|
|
0
|
@types = @methods;
|
37
|
|
|
|
|
|
|
}
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#code is last
|
40
|
5
|
|
|
|
|
11
|
my $code = pop @_;
|
41
|
5
|
|
|
|
|
42
|
my ($caller, $script, $line) = caller(1);
|
42
|
5
|
|
|
|
|
11
|
my ($abs_path,$namespace);
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
##redifine whole sub
|
45
|
5
|
50
|
|
|
|
18
|
if ($type eq 'route'){
|
46
|
0
|
|
|
|
|
0
|
my $hash = $code;
|
47
|
0
|
|
0
|
|
|
0
|
my $controller = $hash->{controller} || '+'.$caller;
|
48
|
0
|
|
|
|
|
0
|
$code = $hash->{action};
|
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
0
|
@types = ref $hash->{method} eq 'ARRAY' ? @{$hash->{method}} : $hash->{method};
|
|
0
|
|
|
|
|
0
|
|
51
|
0
|
0
|
0
|
|
|
0
|
@types = @methods if !$hash->{method} || $hash->{method} eq 'any';
|
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
0
|
if ($controller =~ s/^\+//g){
|
|
0
|
|
|
|
|
0
|
|
54
|
|
|
|
|
|
|
#nothing !!
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
else {$controller = $caller.'::Controllers::'.$controller;}
|
58
|
|
|
|
|
|
|
##require if not in controller folder
|
59
|
0
|
0
|
|
|
|
0
|
if ($controller !~ /(Controllers::|Plugins::)/i){
|
60
|
0
|
|
|
|
|
0
|
my $req = $controller.'.pm';
|
61
|
0
|
|
|
|
|
0
|
$req =~ s/::/\//g;
|
62
|
0
|
|
|
|
|
0
|
eval "require '$req'";
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
$caller = $controller;
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
5
|
100
|
|
|
|
30
|
if (ref $path eq 'Regexp'){
|
|
|
100
|
|
|
|
|
|
69
|
1
|
|
|
|
|
10
|
$abs_path = qr{$path};
|
70
|
|
|
|
|
|
|
} elsif ($path =~ m/^\//){
|
71
|
|
|
|
|
|
|
#for absolute paths
|
72
|
1
|
|
|
|
|
4
|
$abs_path = lc($path);
|
73
|
|
|
|
|
|
|
} else {
|
74
|
|
|
|
|
|
|
|
75
|
3
|
|
|
|
|
24
|
($namespace) = $caller =~ m/Controllers(::.*)$/;
|
76
|
3
|
50
|
|
|
|
13
|
if ($namespace){
|
77
|
3
|
|
|
|
|
14
|
$namespace =~ s/::/\//g;
|
78
|
3
|
|
|
|
|
11
|
$abs_path = lc($namespace.'/');
|
79
|
|
|
|
|
|
|
} else {
|
80
|
0
|
|
|
|
|
0
|
$abs_path = '/';
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
10
|
$abs_path .= lc($path);
|
84
|
3
|
|
|
|
|
8
|
$abs_path =~ s/\/$//;
|
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
|
87
|
5
|
|
100
|
|
|
89
|
local $dispatch->{lastAction} = {
|
88
|
|
|
|
|
|
|
code => $code,
|
89
|
|
|
|
|
|
|
line => $line,
|
90
|
|
|
|
|
|
|
script => $script,
|
91
|
|
|
|
|
|
|
class => $caller,
|
92
|
|
|
|
|
|
|
namespace => $namespace || '',
|
93
|
|
|
|
|
|
|
path => $abs_path
|
94
|
|
|
|
|
|
|
};
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
###if there is another rules left, process them
|
97
|
|
|
|
|
|
|
### accept ref code
|
98
|
5
|
|
|
|
|
17
|
foreach my $rule (@_) {
|
99
|
0
|
0
|
|
|
|
0
|
if (ref $rule eq 'CODE'){
|
100
|
0
|
|
|
|
|
0
|
$rule->($dispatch);
|
101
|
|
|
|
|
|
|
}
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
##new path ref
|
105
|
5
|
|
|
|
|
15
|
my $nPath = $dispatch->{lastAction}->{path};
|
106
|
|
|
|
|
|
|
|
107
|
5
|
100
|
66
|
|
|
42
|
if (ref $nPath eq 'Regexp' || ref $path eq 'Regexp') {
|
108
|
1
|
|
|
|
|
3
|
push(@{$dispatch->{regex}},{
|
|
1
|
|
|
|
|
13
|
|
109
|
|
|
|
|
|
|
regex => qr{$nPath},
|
110
|
|
|
|
|
|
|
methods => \@types,
|
111
|
|
|
|
|
|
|
action => $dispatch->{lastAction}
|
112
|
|
|
|
|
|
|
});
|
113
|
|
|
|
|
|
|
} else {
|
114
|
4
|
|
|
|
|
7
|
my $actions;
|
115
|
4
|
|
|
|
|
9
|
my $first_method = '';
|
116
|
|
|
|
|
|
|
#one reference for all methods
|
117
|
4
|
|
|
|
|
11
|
foreach my $method (@types){
|
118
|
4
|
50
|
|
|
|
13
|
if ($actions->{$first_method}){
|
119
|
0
|
|
|
|
|
0
|
$actions->{$method} = $actions->{$first_method};
|
120
|
|
|
|
|
|
|
} else {
|
121
|
4
|
|
|
|
|
13
|
$actions->{$method} = $dispatch->{lastAction};
|
122
|
4
|
|
|
|
|
12
|
$first_method = $method;
|
123
|
|
|
|
|
|
|
}
|
124
|
|
|
|
|
|
|
}
|
125
|
|
|
|
|
|
|
|
126
|
4
|
50
|
|
|
|
24
|
if ($dispatch->{$nPath}){
|
127
|
0
|
|
|
|
|
0
|
$dispatch->{$nPath} = {%{$dispatch->{$nPath}},%{$actions}};
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
128
|
|
|
|
|
|
|
} else {
|
129
|
4
|
|
|
|
|
27
|
$dispatch->{$nPath} = $actions;
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
}
|
132
|
|
|
|
|
|
|
}
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub auto {
|
135
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
136
|
0
|
|
|
|
|
|
my $code = pop(@_);
|
137
|
0
|
|
|
|
|
|
my ($caller, $script, $line) = caller(1);
|
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
push @{$auto_chain->{$caller}},{
|
|
0
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
code => $code,
|
141
|
|
|
|
|
|
|
line => $line
|
142
|
|
|
|
|
|
|
};
|
143
|
|
|
|
|
|
|
}
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub clear {
|
146
|
0
|
|
|
0
|
0
|
|
$dispatch = {};
|
147
|
|
|
|
|
|
|
}
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1;
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__END__
|