Terse/Controller.pm

filter: Statementstmt 27.2% 55 / 202 Branchbran 11.0% 11 / 100 Conditioncond 5.8% 5 / 85 MC/DCmcdc 6.0% 3 / 50 Subroutinesub 44.0% 11 / 25 Podpod 14.2% 1 / 7 totaltotal 18.3% 86 / 469 CC 89 SCAR 53.1
CC
89
Cov
18%
dispatch
600.0
__ANON__
306.0
_partial_match
132.0
CRAP 201.6
↑ Summary Terse/WebSocket.pm »
1 package Terse::Controller;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶no warnings 'reserved';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use attributes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base 'Terse';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use B 'svref_2object';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our %HTTP;
10 1 ▶BEGIN { %HTTP = map { $_ => 1 } qw/get post put delete connect head options trace patch/; }
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
13 1 my ($pkg, @args) = @_;
14 1 my $self = $pkg->SUPER::new(
15 app => 0,
16 restrict_path => '/',
17 @args
18 );
19 1 (my $namespace = $pkg) =~ s/^.*Controller:://;
20 1 $namespace =~ s/\:\:/\//g;
21 1 $self->namespace = lc( $namespace );
22 1 $self->default_req = [split "/", $self->namespace]->[-1];
23 1 ▶ $self->build_controller($self->app_config) if ($self->can('build_controller'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("build_controller") 1 0 1
24 1 return $self;
25 }
26  
27 0 ▶sub preprocess_req {
Subroutine preprocess_req: not called CC=4 SCAR=30.0
Pod undocumented
28 0 my ($self, $req, $t) = @_;
29 0 ▶ if (!$req) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req) 0 0 0
30 0 my $alias = $Terse::Controller::dispatcher{ref $self}{_alias};
31 0 my $path = $t->request->uri->path;
32 0 for my $candidate (keys %{$alias}) {
33 0 my @captured = $path =~ m/^$candidate$/;
34 0 ▶ if (scalar @captured) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @captured) 0 0 0
35 0 $t->captured = \@captured;
36 0 $req = $alias->{$candidate}->{req};
37 }
38 }
39 }
40 0 return $req;
41 }
42  
43 0 ▶sub build_terse {
Subroutine build_terse: not called CC=7 SCAR=40.3
Pod undocumented
44 0 my ($self, $t) = @_;
45 0 ▶ if ($self->models) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->models) 0 0 0
46 0 ▶ $t->models ||= {};
Condition0%0/2
$t->models ||= {}
l!l
00
MC/DC0%0/1
$t->models ||= {}
$t->models
Truth table0%0/2
A
A= $t->models
Aresult
11
00
47 0 ▶ $t->{model} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
48 0 my ($t, $model) = @_;
49 0 ▶ $t->raiseError("invalid model: ${model}", 400) unless $self->models->{$model};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->models->{$model} 0 0 0
50 0 ▶ return $t->models->{$model} ||= $self->models->{$model}->connect($t);
Condition0%0/3
$t->models->{$model} ||= $self->models->{$model}->connect($t)
l!l&&r!l&&!r
000
MC/DC0%0/2
$t->models->{$model} ||= $self->models->{$model}->connect($t)
$t->models->{$model} $self->models->{$model}->connect($t)
Truth table0%0/3
A ||= B
A= $t->models->{$model}B= $self->models->{$model}->connect($t)
ABresult
1X1
011
000
51 0 };
52 }
53 0 ▶ if ($self->controllers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->controllers) 0 0 0
54 0 ▶ $t->{controller} = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
55 0 my ($t, $controller) = @_;
56 0 ▶ return $self->controllers->{$controller} if $self->controllers->{$controller};
Branch: 1 branch
BranchTrueFalseTotal
if $self->controllers->{$controller} 0 0 0
57 return $self->controllers->{$self->controllers->{_alias}->{$controller}->{namespace}}
58 0 ▶ if $self->controllers->{_alias}->{$controller};
Branch: 1 branch
BranchTrueFalseTotal
if $self->controllers->{"_alias"}{$controller} 0 0 0
59 0 for my $key (keys %{$self->controllers->{_alias}}) {
60 0 my @captured = $controller =~ m/^$key$/;
61 0 ▶ if (scalar @captured) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @captured) 0 0 0
62 0 $controller = $self->controllers->{$self->controllers->{_alias}->{$key}->{namespace}};
63 0 $t->captured = \@captured;
64 0 return $controller;
65 }
66 }
67 0 return;
68 0 };
69 }
70 0 ▶ if ($self->views) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->views) 0 0 0
71 0 ▶ $t->{view} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
72 0 my ($t, $view) = @_;
73 0 ▶ $t->raiseError("invalid view: ${view}", 400) unless $self->views->{$view};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->views->{$view} 0 0 0
74 0 return $self->views->{$view};
75 0 };
76 }
77 0 ▶ if ($self->plugins) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->plugins) 0 0 0
78 0 ▶ $t->plugins ||= {};
Condition0%0/2
$t->plugins ||= {}
l!l
00
MC/DC0%0/1
$t->plugins ||= {}
$t->plugins
Truth table0%0/2
A
A= $t->plugins
Aresult
11
00
79 0 ▶ $t->{plugin} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
80 0 my ($t, $plugin) = @_;
81 0 ▶ $t->raiseError("invalid plugin: ${plugin}", 400) unless $self->plugins->{$plugin};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->plugins->{$plugin} 0 0 0
82 return $t->plugins->{$plugin} ||= ($self->plugins->{$plugin}->can('connect')
83 ? $self->plugins->{$plugin}->connect($t)
84 0 ▶ : $self->plugins->{$plugin});
Branch: 1 branch
BranchTrueFalseTotal
$self->plugins->{$plugin}->can('connect') ? : 0 0 0
Condition0%0/3
$t->plugins->{$plugin} ||= $self->plugins->{$plugin}->can("connect") ? $self->plugins->{$plugin}->connect($t) : $self->plugins->{$plugin}
l!l&&r!l&&!r
000
MC/DC0%0/2
$t->plugins->{$plugin} ||= $self->plugins->{$plugin}->can("connect") ? $self->plugins->{$plugin}->connect($t) : $self->plugins->{$plugin}
$t->plugins->{$plugin} $self->plugins->{$plugin}->can("connect") ? $self->plugins->{$plugin}->connect($t) : $self->plugins->{$plugin}
Truth table0%0/3
A ||= B
A= $t->plugins->{$plugin}B= $self->plugins->{$plugin}->can("connect") ? $self->plugins->{$plugin}->connect($t) : $self->plugins->{$plugin}
ABresult
1X1
011
000
85 0 };
86 }
87 0 return $t;
88 }
89  
90 7 ▶sub MODIFY_CODE_ATTRIBUTES {
Subroutine MODIFY_CODE_ATTRIBUTES: called CC=2 SCAR=6.9
91 7 my ($package, $coderef, @attributes, @disallowed) = @_;
92 1 ▶ no warnings qw(reserved);
Subroutine BEGIN: called CC=1 SCAR=0.0
93 7 my $name = svref_2object($coderef)->GV->NAME;
94 7 my %attr = PARSE_ATTRIBUTES($name, @attributes);
95 7 push @{ $Terse::Controller::dispatcher{$package}{$attr{req}} }, \%attr;
96 7 ▶ if ($attr{path}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr{"path"}) 2 5 7
97 2 (my $namespace = $package) =~ s/^.*Controller:://;
98 2 $namespace =~ s/\:\:/\//g;
99 $Terse::Controller::dispatcher{$package}{_alias}{$attr{path}} = {
100 namespace => lc( $namespace ),
101 req => $attr{req}
102 2 };
103 }
104 7 return ();
105 }
106  
107 0 ▶sub FETCH_CODE_ATTRIBUTES {
Subroutine FETCH_CODE_ATTRIBUTES: not called CC=1 SCAR=6.9
108 0 my ($class, $coderef) = @_;
109 0 my $cv = svref_2object($coderef);
110 0 return @{$Terse::Controller::dispatcher{$class}{ $cv->GV->NAME }};
111 }
112  
113 7 ▶sub PARSE_ATTRIBUTES {
Subroutine PARSE_ATTRIBUTES: called CC=8 SCAR=20.8
Pod undocumented
114 7 my ($sub, @attributes) = @_;
115 7 my %attr = (
116 req => $sub,
117 callback => $sub
118 );
119 7 for my $attribute (@attributes) {
120 13 ▶ if ($attribute =~ m/^\s*params\((.*)\)\s*$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attribute =~ /^\s*params\((.*)\)\s*$/) { } 1 12 13
elsif ($attribute =~ /^\s*([^\s\(]+)\s*\(([\s\'\"]*?)(.*)([\s\'\"]*?)\)/) { } 7 5 12
121 1 $attr{params} = { eval $1 };
122 }
123 elsif ($attribute =~ m/^\s*([^\s\(]+)\s*\(([\s\'\"]*?)(.*)([\s\'\"]*?)\)/) {
124 7 my $k = lc($1);
125 7 $attr{$k} = $3;
126 7 ▶ if ($HTTP{$k} || $k =~ m/^(any|websocket|deleayed)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Terse::Controller::HTTP{$k} or $k =~ /^(any|websocket|deleayed)$/i) 3 4 7
Condition100%3/3
$Terse::Controller::HTTP{$k} or $k =~ /^(any|websocket|deleayed)$/i
l!l&&r!l&&!r
124
MC/DC100%2/2
$Terse::Controller::HTTP{$k} or $k =~ /^(any|websocket|deleayed)$/i
$Terse::Controller::HTTP{$k} $k =~ /^(any|websocket|deleayed)$/i
Truth table100%3/3
A or B
A= $Terse::Controller::HTTP{$k}B= $k =~ /^(any|websocket|deleayed)$/i
ABresult
1X1
011
000
127 3 $attr{req} = $attr{$k};
128 }
129 }
130 else {
131 5 $attr{lc($attribute)} = 1;
132 }
133 }
134 7 ▶ $attr{any} = 1 if ($attr{websocket} && scalar keys %attr < 4);
Branch: 1 branch
BranchTrueFalseTotal
if $attr{"websocket"} and scalar keys %attr < 4 1 6 7
Condition66%2/3
$attr{"websocket"} and scalar keys %attr < 4
!ll&&!rl&&r
601
MC/DC50%1/2
$attr{"websocket"} and scalar keys %attr < 4
$attr{"websocket"} scalar keys %attr < 4
Truth table66%2/3
A and B
A= $attr{"websocket"}B= scalar keys %attr < 4
ABresult
0X0
100
111
135 7 return %attr;
136 }
137  
138 0 ▶sub delayed_response_handle {
Subroutine delayed_response_handle: not called CC=1 SCAR=6.9
Pod undocumented
139 0 my ($self, $t, $response, $sid, $ct, $status) = @_;
140 0 ▶ $t->{_delayed_response} = sub {
Subroutine __ANON__: not called CC=17 SCAR=57.2
141 0 my $responder = shift;
142 0 ▶ my $view = $t->view($t->response_view || $self->response_view);
Condition0%0/3
$t->response_view || $self->response_view
l!l&&r!l&&!r
000
MC/DC0%0/2
$t->response_view || $self->response_view
$t->response_view $self->response_view
Truth table0%0/3
A || B
A= $t->response_viewB= $self->response_view
ABresult
1X1
011
000
143 0 ▶ my $res = $t->_build_response($sid,
Condition0%0/14
$t->content_type || $view && $view->content_type || $ct
l!l&&r!l&&!r
000
$t->content_type or $view and $view->content_type
l!l&&r!l&&!r
000
$view and $view->content_type
!ll&&!rl&&r
000
$t->response->status_code ||= ($status ||= 200)
l!l&&r!l&&!r
000
$status ||= 200
l!l
00
MC/DC0%0/4
$t->content_type || $view && $view->content_type || $ct
$t->content_type $view $view->content_type $ct
MC/DC0%0/2
$t->response->status_code ||= ($status ||= 200)
$t->response->status_code ($status ||= 200)
MC/DC0%0/1
$status ||= 200
$status
Truth table0%0/6
A or B and C || D
A= $t->content_typeB= $viewC= $view->content_typeD= $ct
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
Truth table0%0/3
A ||= B
A= $t->response->status_codeB= ($status ||= 200)
ABresult
1X1
011
000
Truth table0%0/2
A
A= $status
Aresult
11
00
144 $t->content_type || $view && $view->content_type || $ct,
145 $t->response->status_code ||= $status ||= 200
146 );
147 0 $res = [splice @{$res->finalize}, 0, 2];
148 0 my $writer = $responder->($res);
149 0 $response = eval { $response->($writer); };
150 0 ▶ if ($@ || $t->response->error) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@ or $t->response->error) { } 0 0 0
elsif ($response) { } 0 0 0
Condition0%0/3
$@ or $t->response->error
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or $t->response->error
$@ $t->response->error
Truth table0%0/3
A or B
A= $@B= $t->response->error
ABresult
1X1
011
000
151 0 ▶ $res->[0] = $t->response->status_code || 500;
Condition0%0/2
$t->response->status_code || 500
l!l
00
MC/DC0%0/1
$t->response->status_code || 500
$t->response->status_code
Truth table0%0/2
A
A= $t->response->status_code
Aresult
11
00
152 $t->raiseError($@) if #@;
153 0 ▶ push @{$res}, [$t->response->serialize];
Branch: 1 branch
BranchTrueFalseTotal
if push @{$res;}, [$t->response->serialize] 0 0 0
154 0 return $responder->($res);
155 }
156 elsif ($response) {
157 0 ▶ $view = $t->view($t->response_view || $self->response_view);
Condition0%0/3
$t->response_view || $self->response_view
l!l&&r!l&&!r
000
MC/DC0%0/2
$t->response_view || $self->response_view
$t->response_view $self->response_view
Truth table0%0/3
A || B
A= $t->response_viewB= $self->response_view
ABresult
1X1
011
000
158 0 ▶ if ($view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($view) { } 0 0 0
159 0 my (undef, $render) = $view->render($t, $response);
160 0 ▶ if ($t->response->error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->response->error) 0 0 0
161 0 ▶ $res->[0] = $t->response->status_code || 500;
Condition0%0/2
$t->response->status_code || 500
l!l
00
MC/DC0%0/1
$t->response->status_code || 500
$t->response->status_code
Truth table0%0/2
A
A= $t->response->status_code
Aresult
11
00
162 0 ▶ push @{$res}, [$t->response->no_response ? () : $t->response->serialize];
Branch: 1 branch
BranchTrueFalseTotal
$t->response->no_response ? : 0 0 0
163 0 return $responder->($res);
164 }
165 0 $response = $render;
166 } else {
167 0 $response = $response->serialize;
168 }
169 0 $writer->write($response);
170 }
171 0 $writer->close;
172 0 };
173 0 return $t;
174 }
175  
176  
177 0 ▶sub response_handle {
Subroutine response_handle: not called CC=9 SCAR=45.0
Pod undocumented
178 0 my ($self, $t, $response_body, $sid, $ct, $status) = @_;
179 0 ▶ $ct ||= 'application/json';
Condition0%0/2
$ct ||= "application/json"
l!l
00
MC/DC0%0/1
$ct ||= "application/json"
$ct
Truth table0%0/2
A
A= $ct
Aresult
11
00
180 0 my $res = $t->{_delayed_response};
181 0 ▶ return $res if ($res);
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
182 0 ▶ my ($content_type, $body) = $self->views && $self->views->{$t->response_view || $self->response_view}
Branch: 1 branch
BranchTrueFalseTotal
$self->views && $self->views->{$t->response_view or $self->response_view} ? : 0 0 0
Condition0%0/9
$self->views and $self->views->{$t->response_view or $self->response_view}
!ll&&!rl&&r
000
$t->response_view || $self->response_view
l!l&&r!l&&!r
000
$t->response_view || $self->response_view
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->views and $self->views->{$t->response_view or $self->response_view}
$self->views $self->views->{$t->response_view or $self->response_view}
MC/DC0%0/2
$t->response_view || $self->response_view
$t->response_view $self->response_view
MC/DC0%0/2
$t->response_view || $self->response_view
$t->response_view $self->response_view
Truth table0%0/3
A and B
A= $self->viewsB= $self->views->{$t->response_view or $self->response_view}
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= $t->response_viewB= $self->response_view
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $t->response_viewB= $self->response_view
ABresult
1X1
011
000
183 ? $t->view($t->response_view || $self->response_view)->render($t, $response_body)
184 : ($ct, $response_body->serialize());
185 0 ▶ $res = $t->_build_response($sid, $content_type, $response_body->status_code ||= $status ||= 200);
Condition0%0/5
$response_body->status_code ||= ($status ||= 200)
l!l&&r!l&&!r
000
$status ||= 200
l!l
00
MC/DC0%0/2
$response_body->status_code ||= ($status ||= 200)
$response_body->status_code ($status ||= 200)
MC/DC0%0/1
$status ||= 200
$status
Truth table0%0/3
A ||= B
A= $response_body->status_codeB= ($status ||= 200)
ABresult
1X1
011
000
Truth table0%0/2
A
A= $status
Aresult
11
00
186 0 $res->body($body);
187 0 return $res->finalize;
188 }
189  
190 0 ▶sub dispatch {
Subroutine dispatch: not called CC=24 SCAR=64.0
Pod undocumented
191 0 my ($self, $req, $t, @params) = @_;
192 0 ▶ my $package = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
193 0 my $dispatch = $Terse::Controller::dispatcher{$package};
194 0 ▶ my @dispatcher = @{ $dispatch->{$req} || [] };
Condition0%0/2
$dispatch->{$req} || []
l!l
00
MC/DC0%0/1
$dispatch->{$req} || []
$dispatch->{$req}
Truth table0%0/2
A
A= $dispatch->{$req}
Aresult
11
00
195 0 my $in;
196 0 ▶ $in = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
197 0 my @ISA = eval "\@$_[0]::ISA";
198 0 for (@ISA) {
199 0 $in->($_);
200 0 $dispatch = $Terse::Controller::dispatcher{$_};
201 0 ▶ next unless $dispatch && $dispatch->{$req};
Branch: 1 branch
BranchTrueFalseTotal
unless $dispatch and $dispatch->{$req} 0 0 0
Condition0%0/3
$dispatch and $dispatch->{$req}
!ll&&!rl&&r
000
MC/DC0%0/2
$dispatch and $dispatch->{$req}
$dispatch $dispatch->{$req}
Truth table0%0/3
A and B
A= $dispatchB= $dispatch->{$req}
ABresult
0X0
100
111
202 0 unshift @dispatcher, @{ $dispatch->{$req} };
203 }
204 0 };
205 0 $in->($package);
206 0 ▶ if (!scalar @dispatcher) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @dispatcher) 0 0 0
207 0 $t->logError('Invalid dispatch request', 400);
208 0 return;
209 }
210 0 $dispatch = undef;
211 0 my $path = $t->request->uri->path;
212 0 ▶ my $caps = scalar @{ $t->captured || [] };
Condition0%0/2
$t->captured || []
l!l
00
MC/DC0%0/1
$t->captured || []
$t->captured
Truth table0%0/2
A
A= $t->captured
Aresult
11
00
213 0 DISPATCH: for my $candidate (reverse @dispatcher) {
214 0 ▶ next DISPATCH unless ($candidate->{lc($t->request->method)} || $candidate->{any});
Branch: 1 branch
BranchTrueFalseTotal
unless $$candidate{lc $t->request->method} or $candidate->{"any"} 0 0 0
Condition0%0/3
$$candidate{lc $t->request->method} or $candidate->{"any"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$$candidate{lc $t->request->method} or $candidate->{"any"}
$$candidate{lc $t->request->method} $candidate->{"any"}
Truth table0%0/3
A or B
A= $$candidate{lc $t->request->method}B= $candidate->{"any"}
ABresult
1X1
011
000
215 0 ▶ next DISPATCH unless (!$candidate->{captured} || $caps == $candidate->{captured});
Branch: 1 branch
BranchTrueFalseTotal
unless not $candidate->{"captured"} or $caps == $candidate->{"captured"} 0 0 0
Condition0%0/3
not $candidate->{"captured"} or $caps == $candidate->{"captured"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $candidate->{"captured"} or $caps == $candidate->{"captured"}
not $candidate->{"captured"} $caps == $candidate->{"captured"}
Truth table0%0/3
not(A) or B
A= not $candidate->{"captured"}B= $caps == $candidate->{"captured"}
ABresult
1X1
011
000
216 0 ▶ if ($candidate->{params}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($candidate->{"params"}) 0 0 0
217 0 for my $param (keys %{$candidate->{params}}) {
218 0 ▶ next DISPATCH if (!$t->params->{$param});
Branch: 1 branch
BranchTrueFalseTotal
unless $t->params->{$param} 0 0 0
219 next DISPATCH unless $self->_partial_match(
220 $t->params->{$param},
221 0 ▶ $candidate->{params}->{$param}
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_partial_match($t->params->{$param}, $candidate->{"params"}{$param}) 0 0 0
222 );
223 }
224 }
225 0 ▶ $t->request->uri->path =~ m/$candidate->{path}/ or next if $candidate->{path};
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->{"path"} 0 0 0
Condition0%0/5
$candidate->{'path'} && ($t->request->uri->path =~ /$candidate->{'path'}/ || (next))
!ll&&!rl&&r
000
$t->request->uri->path =~ /$candidate->{"path"}/ or next
l!l
00
MC/DC0%0/2
$candidate->{'path'} && ($t->request->uri->path =~ /$candidate->{'path'}/ || (next))
$candidate->{'path'} $t->request->uri->path =~ /$candidate->{"path"}/
Truth table0%0/3
A && B
A= $candidate->{'path'}B= $t->request->uri->path =~ /$candidate->{"path"}/
ABresult
0X0
100
111
226 0 $dispatch = $candidate;
227 0 last;
228 }
229  
230 0 ▶ $dispatch = $self->dispatch_hook($dispatch) if $self->can('dispatch_hook');
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("dispatch_hook") 0 0 0
231 0 my $callback = $dispatch->{callback};
232 0 ▶ if (!$callback) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($callback) 0 0 0
233 0 $t->logError('No callback found to dispatch the request', 400);
234 0 return;
235 }
236 0 $t->response_namespace = $self->namespace;
237 0 ▶ $t->response_handler = $callback if $callback !~ m/auth/;
Branch: 1 branch
BranchTrueFalseTotal
unless $callback =~ /auth/ 0 0 0
238 0 ▶ $t->response_view = $dispatch->{view} if $dispatch->{view};
Branch: 1 branch
BranchTrueFalseTotal
if $dispatch->{"view"} 0 0 0
239 0 ▶ $t->content_type($dispatch->{content_type}) if $dispatch->{content_type};
Branch: 1 branch
BranchTrueFalseTotal
if $dispatch->{"content_type"} 0 0 0
240 0 ▶ if ($dispatch->{delayed}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dispatch->{'delayed'}) { } 0 0 0
elsif ($dispatch->{'websocket'}) { } 0 0 0
241 0 ▶ return $t->delayed_response(sub { $self->$callback($t, @params); $t->response; });
Subroutine __ANON__: not called CC=1 SCAR=6.9
242 } elsif ($dispatch->{websocket}) {
243 0 ▶ $self->websockets ||= {};
Condition0%0/2
$self->websockets ||= {}
l!l
00
MC/DC0%0/1
$self->websockets ||= {}
$self->websockets
Truth table0%0/2
A
A= $self->websockets
Aresult
11
00
244 0 $self->websockets->{$t->sid->value} = $t->websocket($self->$callback($t, @params), close_delete => 1);
245 0 return $t;
246 }
247 0 return $self->$callback($t, @params);
248 }
249  
250 0 ▶sub _partial_match {
Subroutine _partial_match: not called CC=11 SCAR=48.8
251 0 my ($self, $param, $spec) = @_;
252 0 ▶ return 0 if !$param && $spec;
Branch: 1 branch
BranchTrueFalseTotal
if not $param and $spec 0 0 0
Condition0%0/3
not $param and $spec
!ll&&!rl&&r
000
MC/DC0%0/2
not $param and $spec
not $param $spec
Truth table0%0/3
not(A) and B
A= not $paramB= $spec
ABresult
0X0
100
111
253 0 my ($ref, $match) = (ref $spec, 1);
254 0 ▶ if (!$ref) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $ref) { } 0 0 0
elsif ($ref eq 'ARRAY') { } 0 0 0
elsif ($ref eq 'HASH') { } 0 0 0
255 0 ▶ $match = ref $param ? 0 : $param =~ m/^$spec$/;
Branch: 1 branch
BranchTrueFalseTotal
ref $param ? : 0 0 0
256 } elsif ($ref eq 'ARRAY') {
257 0 ▶ for (my $i = 0; $i < scalar @{$spec}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$spec;}) 0 0 0
258 0 $match = $self->_partial_match($param->[$i], $spec->[$i]);
259 0 ▶ last if (!$match);
Branch: 1 branch
BranchTrueFalseTotal
unless $match 0 0 0
260 }
261 } elsif ($ref eq 'HASH') {
262 0 for my $key ( keys %{$spec} ) {
263 0 $match = $self->_partial_match($param->{$key}, $spec->{$key});
264 0 ▶ last if (!$match);
Branch: 1 branch
BranchTrueFalseTotal
unless $match 0 0 0
265 }
266 }
267 0 return $match;
268 }
269  
270 1 1;
271  
272 __END__;
↑ Summary Terse/WebSocket.pm »