blib/lib/Thunderhorse/Router/Location.pm

filter: Statementstmt 100% 46 / 46 Branchbran 90.0% 18 / 20 Conditioncond 84.6% 11 / 13 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 10 / 10 Podpod 66.6% 2 / 3 totaltotal 91.0% 91 / 100 CC 16 SCAR 12.4
CC
16
Cov
95%
_build_pagi_app
5.1
_build_action_re
5.0
BUILD
3.2
CRAP 3.4
« blib/lib/Thunderhorse/Response.pm ↑ Summary blib/lib/Thunderhorse/Module/Middleware.pm »
1 package Thunderhorse::Router::Location;
2 24 $Thunderhorse::Router::Location::VERSION = '0.107';
3 24 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 24 ▶use Gears::X::Thunderhorse;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use Thunderhorse qw(build_handler adapt_pagi);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 24 extends 'Gears::Router::Location::SigilMatch';
10  
11 24 has option 'action' => (
12 isa => Str,
13 );
14  
15 24 has field '_action_re' => (
16 isa => RegexpRef,
17 lazy => 1,
18 );
19  
20 24 has param 'name' => (
21 isa => Str,
22 lazy => 1,
23 );
24  
25 24 has param 'to' => (
26 isa => Str | CodeRef,
27 required => 0,
28 );
29  
30 24 has param 'order' => (
31 isa => Int,
32 default => 0,
33 );
34  
35 24 has param 'pagi' => (
36 isa => Bool,
37 default => false,
38 );
39  
40 24 has param 'pagi_middleware' => (
41 isa => CodeRef,
42 required => 0,
43 );
44  
45 24 has param 'controller' => (
46 isa => InstanceOf ['Thunderhorse::Controller'],
47 );
48  
49 24 has field 'pagi_app' => (
50 isa => CodeRef,
51 lazy => 1,
52 );
53  
54 179 ▶sub BUILD ($self, $)
Subroutine BUILD: called CC=3 SCAR=11.7
Pod undocumented
55 {
56 179 ▶ Gears::X::Thunderhorse->raise('controller has no method ' . $self->to)
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->to and not $self->get_destination 0 179 179
Condition66%2/3
defined $self->to and not $self->get_destination
!ll&&!rl&&r
161630
MC/DC0%0/2
defined $self->to and not $self->get_destination
defined $self->to not $self->get_destination
Truth table66%2/3
A and not(B)
A= defined $self->toB= not $self->get_destination
ABresult
0X0
100
111
57 if defined $self->to && !$self->get_destination;
58  
59 # register the route in the router
60 179 $self->router->_register_location($self->name, $self);
61 }
62  
63 17 ▶sub _build_action_re ($self)
Subroutine _build_action_re: called CC=5 SCAR=16.1
64 {
65 17 my ($scope, $method) = split /\./, $self->action;
66 17 ▶ $scope = $scope eq '*' ? qr{[^.]+} : quotemeta lc $scope;
Branch: 1 branch
BranchTrueFalseTotal
$scope eq '*' ? : 2 15 17
67  
68 17 ▶ if (($method // '*') eq '*') {
Branch: 2 branches
BranchTrueFalseTotal
if (($method // '*') eq '*') { } 11 6 17
elsif (lc $method eq 'get') { } 3 3 6
Condition100%2/2
$method // "*"
l!l
89
MC/DC100%1/1
$method // "*"
$method
Truth table100%2/2
A
A= $method
Aresult
11
00
69 11 $method = qr{(\.[^.]+)?};
70 }
71 elsif (lc $method eq 'get') {
72 3 $method = '[.](get|head)';
73 }
74 else {
75 3 $method = quotemeta lc ".$method";
76 }
77  
78 17 return qr{^$scope$method$};
79 }
80  
81 172 ▶sub _build_name ($self)
Subroutine _build_name: called CC=2 SCAR=6.9
82 {
83 172 ▶ my $action = $self->action // 'any';
Condition100%2/2
$self->action // "any"
l!l
16156
MC/DC100%1/1
$self->action // "any"
$self->action
Truth table100%2/2
A
A= $self->action
Aresult
11
00
84 172 my $pattern = $self->pattern;
85 172 my $id = $self->router->_get_next_route_id;
86  
87 # autogenerated location name should be readable, but unique
88 172 return "${id}_${action}_${pattern}";
89 }
90  
91 97 ▶sub _build_pagi_app ($self)
Subroutine _build_pagi_app: called CC=5 SCAR=16.2
92 {
93 # TODO: add router sealing when the app is started (prevent it from
94 # changing and breaking assumptions)
95  
96 # this needs to be checked lazily, because we don't know if this is a
97 # bridge in BUILD
98 97 ▶ Gears::X::Thunderhorse->raise('PAGI apps cannot be bridges')
Branch: 1 branch
BranchTrueFalseTotal
if $self->pagi and $self->is_bridge 0 97 97
Condition66%2/3
$self->pagi and $self->is_bridge
!ll&&!rl&&r
87100
MC/DC0%0/2
$self->pagi and $self->is_bridge
$self->pagi $self->is_bridge
Truth table66%2/3
A and B
A= $self->pagiB= $self->is_bridge
ABresult
0X0
100
111
99 if $self->pagi && $self->is_bridge;
100  
101 97 ▶ my $pagi = $self->pagi
Branch: 1 branch
BranchTrueFalseTotal
$self->pagi ? : 10 87 97
102 ? adapt_pagi($self->get_destination)
103 : build_handler($self->controller, $self->get_destination)
104 ;
105  
106 97 ▶ if (my $mw = $self->pagi_middleware) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mw = $self->pagi_middleware) 3 94 97
107 3 $pagi = $mw->($pagi);
108 }
109  
110 97 return $pagi;
111 }
112  
113 260 ▶sub get_destination ($self)
Subroutine get_destination: called CC=3 SCAR=11.0
Pod documented
114 {
115 260 my $to = $self->to;
116 260 ▶ return undef unless defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to 2 258 260
117  
118 258 ▶ return $to if ref $to eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $to eq "CODE" 126 132 258
119 132 return $self->controller->can($self->to);
120 }
121  
122 842 ▶sub compare ($self, $path, $action)
Subroutine compare: called CC=3 SCAR=11.0
Pod documented
123 {
124 842 ▶ return undef if $self->has_action && $action !~ $self->_action_re;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_action and not $action =~ $self->_action_re 124 718 842
Condition100%3/3
$self->has_action and not $action =~ $self->_action_re
!ll&&!rl&&r
592126124
MC/DC100%2/2
$self->has_action and not $action =~ $self->_action_re
$self->has_action not $action =~ $self->_action_re
Truth table100%3/3
A and not(B)
A= $self->has_actionB= not $action =~ $self->_action_re
ABresult
0X0
100
111
125 718 return $self->SUPER::compare($path);
126 }
127  
128 __END__
« blib/lib/Thunderhorse/Response.pm ↑ Summary blib/lib/Thunderhorse/Module/Middleware.pm »