Cake/Controllers.pm

filter: Statementstmt 60.0% 48 / 80 Branchbran 42.8% 12 / 28 Conditioncond 40.0% 4 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 7 totaltotal 51.0% 72 / 141 CC 21 SCAR 39.4
CC
21
Cov
54%
dispatch
72.7
Action
2.0
Path
2.0
CRAP 51.3
« Cake/Server/Simple.pm ↑ Summary Cake/Actions/Form.pm »
1 package Cake::Controllers;
2 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 8 our @EXPORT = qw(
7 dispatcher
8 auto_chain
9 );
10
11 8 my $dispatch = bless ({},__PACKAGE__);
12 8 my $auto_chain = {};
13 8 my @methods = ('get','post','delete','put');
14
15 4 ▶sub dispatcher {$dispatch}
Subroutine dispatcher: called CC=1 SCAR=0.0
Pod undocumented
16 3 ▶sub auto_chain {$auto_chain}
Subroutine auto_chain: called CC=1 SCAR=0.0
Pod undocumented
17
18 ##returns last added controller action
19 0 ▶sub Action { return shift->{lastAction}; }
Subroutine Action: not called CC=1 SCAR=6.9
Pod undocumented
20 0 ▶sub Path { return shift->{path}; }
Subroutine Path: not called CC=1 SCAR=6.9
Pod undocumented
21 #----------------------------------------------------------------------------
22 # FIXME::: Not sure what should be fixed here
23 #----------------------------------------------------------------------------
24 5 ▶sub dispatch {
Subroutine dispatch: called CC=21 SCAR=42.9
Pod undocumented
25 5 my $self = shift;
26 5 my $type = shift;
27 5 my $path = shift;
28 5 my @types = ($type);
29
30 5 ▶ if (ref $path eq 'ARRAY'){
Branch: 2 branches
BranchTrueFalseTotal
if (ref $path eq 'ARRAY') { } 0 5 5
elsif ($type eq 'any') { } 0 5 5
31 0 @types = @{$path};
32 0 $path = shift;
33 }
34
35 elsif ($type eq 'any'){
36 0 @types = @methods;
37 }
38
39 #code is last
40 5 my $code = pop @_;
41 5 my ($caller, $script, $line) = caller(1);
42 5 my ($abs_path,$namespace);
43
44 ##redifine whole sub
45 5 ▶ if ($type eq 'route'){
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "route") 0 5 5
46 0 my $hash = $code;
47 0 ▶ my $controller = $hash->{controller} || '+'.$caller;
Condition0%0/2
$hash->{'controller'} || '+' . $caller
l!l
00
MC/DC0%0/1
$hash->{'controller'} || '+' . $caller
$hash->{'controller'}
Truth table0%0/2
A
A= $hash->{'controller'}
Aresult
11
00
48 0 $code = $hash->{action};
49
50 0 ▶ @types = ref $hash->{method} eq 'ARRAY' ? @{$hash->{method}} : $hash->{method};
Branch: 1 branch
BranchTrueFalseTotal
ref $hash->{'method'} eq 'ARRAY' ? : 0 0 0
51 0 ▶ @types = @methods if !$hash->{method} || $hash->{method} eq 'any';
Branch: 1 branch
BranchTrueFalseTotal
if not $hash->{"method"} or $hash->{"method"} eq "any" 0 0 0
Condition0%0/3
not $hash->{"method"} or $hash->{"method"} eq "any"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $hash->{"method"} or $hash->{"method"} eq "any"
not $hash->{"method"} $hash->{"method"} eq "any"
Truth table0%0/3
not(A) or B
A= not $hash->{"method"}B= $hash->{"method"} eq "any"
ABresult
1X1
011
000
52
53 0 ▶ if ($controller =~ s/^\+//g){
Branch: 1 branch
BranchTrueFalseTotal
if ($controller =~ s/^\+//g) { } 0 0 0
54 #nothing !!
55 }
56
57 0 else {$controller = $caller.'::Controllers::'.$controller;}
58 ##require if not in controller folder
59 0 ▶ if ($controller !~ /(Controllers::|Plugins::)/i){
Branch: 1 branch
BranchTrueFalseTotal
unless ($controller =~ /(Controllers::|Plugins::)/i) 0 0 0
60 0 my $req = $controller.'.pm';
61 0 $req =~ s/::/\//g;
62 0 eval "require '$req'";
63 }
64
65 0 $caller = $controller;
66 }
67
68 5 ▶ if (ref $path eq 'Regexp'){
Branch: 2 branches
BranchTrueFalseTotal
if (ref $path eq 'Regexp') { } 1 4 5
elsif ($path =~ m[^/]) { } 1 3 4
69 1 $abs_path = qr{$path};
70 } elsif ($path =~ m/^\//){
71 #for absolute paths
72 1 $abs_path = lc($path);
73 } else {
74
75 3 ($namespace) = $caller =~ m/Controllers(::.*)$/;
76 3 ▶ if ($namespace){
Branch: 1 branch
BranchTrueFalseTotal
if ($namespace) { } 3 0 3
77 3 $namespace =~ s/::/\//g;
78 3 $abs_path = lc($namespace.'/');
79 } else {
80 0 $abs_path = '/';
81 }
82
83 3 $abs_path .= lc($path);
84 3 $abs_path =~ s/\/$//;
85 }
86
87 local $dispatch->{lastAction} = {
88 5 ▶ code => $code,
Condition100%2/2
$namespace || ''
l!l
32
MC/DC100%1/1
$namespace || ''
$namespace
Truth table100%2/2
A
A= $namespace
Aresult
11
00
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 foreach my $rule (@_) {
99 0 ▶ if (ref $rule eq 'CODE'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rule eq "CODE") 0 0 0
100 0 $rule->($dispatch);
101 }
102 }
103
104 ##new path ref
105 5 my $nPath = $dispatch->{lastAction}->{path};
106
107 5 ▶ if (ref $nPath eq 'Regexp' || ref $path eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $nPath eq 'Regexp' or ref $path eq 'Regexp') { } 1 4 5
Condition66%2/3
ref $nPath eq "Regexp" or ref $path eq "Regexp"
l!l&&r!l&&!r
104
MC/DC50%1/2
ref $nPath eq "Regexp" or ref $path eq "Regexp"
ref $nPath eq "Regexp" ref $path eq "Regexp"
Truth table66%2/3
A or B
A= ref $nPath eq "Regexp"B= ref $path eq "Regexp"
ABresult
1X1
011
000
108 1 push(@{$dispatch->{regex}},{
109 regex => qr{$nPath},
110 methods => \@types,
111 action => $dispatch->{lastAction}
112 1 });
113 } else {
114 4 my $actions;
115 4 my $first_method = '';
116 #one reference for all methods
117 4 foreach my $method (@types){
118 4 ▶ if ($actions->{$first_method}){
Branch: 1 branch
BranchTrueFalseTotal
if ($actions->{$first_method}) { } 0 4 4
119 0 $actions->{$method} = $actions->{$first_method};
120 } else {
121 4 $actions->{$method} = $dispatch->{lastAction};
122 4 $first_method = $method;
123 }
124 }
125
126 4 ▶ if ($dispatch->{$nPath}){
Branch: 1 branch
BranchTrueFalseTotal
if ($dispatch->{$nPath}) { } 0 4 4
127 0 $dispatch->{$nPath} = {%{$dispatch->{$nPath}},%{$actions}};
128 } else {
129 4 $dispatch->{$nPath} = $actions;
130 }
131 }
132 }
133
134 0 ▶sub auto {
Subroutine auto: not called CC=1 SCAR=6.9
Pod undocumented
135 0 my $self = shift;
136 0 my $code = pop(@_);
137 0 my ($caller, $script, $line) = caller(1);
138
139 0 push @{$auto_chain->{$caller}},{
140 code => $code,
141 line => $line
142 };
143 }
144
145 0 ▶sub clear {
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
146 0 $dispatch = {};
147 }
148
149 8 1;
150
151
152 __END__
« Cake/Server/Simple.pm ↑ Summary Cake/Actions/Form.pm »