blib/lib/Raisin/Routes/Endpoint.pm

filter: Statementstmt 96.6% 57 / 59 Branchbran 72.7% 16 / 22 Conditioncond 50.0% 7 / 14 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 3 totaltotal 77.5% 90 / 116 CC 20 SCAR 19.7
CC
20
Cov
84%
_rep_regex
13.6
match
7.0
new
4.1
CRAP 7.1
« blib/lib/Raisin/Routes.pm ↑ Summary blib/lib/Raisin/Request.pm »
1 #!perl
2 #PODNAME: Raisin::Routes::Endpoint
3 #ABSTRACT: Endpoint class for Raisin::Routes.
4  
5 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package Raisin::Routes::Endpoint;
9 18 $Raisin::Routes::Endpoint::VERSION = '0.94';
10 18 ▶use Plack::Util::Accessor qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
11 check
12 code
13 desc
14 entity
15 method
16 named
17 params
18 path
19 regex
20 summary
21 produces
22 18 );
23  
24 18 ▶use Raisin::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 83 ▶sub new {
Subroutine new: called CC=4 SCAR=14.1
Pod undocumented
27 83 my ($class, %args) = @_;
28  
29 83 my $self = bless {}, $class;
30  
31 83 $self->check({});
32 83 $self->params([]);
33  
34 83 @$self{ keys %args } = values %args;
35  
36 # Populate params index
37 83 for my $p (@{ $self->params }) {
38 59 ▶ if ($p->named && (my $re = $p->regex)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->named and my $re = $p->regex) 0 59 59
Condition66%2/3
$p->named and my $re = $p->regex
!ll&&!rl&&r
39200
MC/DC0%0/2
$p->named and my $re = $p->regex
$p->named my $re = $p->regex
Truth table66%2/3
A and B
A= $p->namedB= my $re = $p->regex
ABresult
0X0
100
111
39 0 $self->{check}{ $p->name } = $re;
40 }
41 }
42  
43 83 $self->regex($self->_build_regex);
44 83 $self;
45 }
46  
47 83 ▶sub _build_regex {
Subroutine _build_regex: called CC=2 SCAR=7.0
48 83 my $self = shift;
49 83 ▶ return $self->path if ref($self->path) eq 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->path eq "Regexp" 0 83 83
50  
51 83 my $regex = $self->path;
52  
53 83 $regex =~ s/(.?)([:*?])(\w+)/$self->_rep_regex($1, $2, $3)/eg;
54 83 $regex =~ s/[{}]//g;
55  
56 # Allows any extensions
57 83 $regex .= "(?:\\\.[^.]+?)?";
58  
59 83 qr/^$regex$/;
60 }
61  
62 50 ▶sub _rep_regex {
Subroutine _rep_regex: called CC=9 SCAR=26.1
63 50 my ($self, $char, $switch, $token) = @_;
64  
65 50 my ($a, $b, $r) = ("(?<$token>", ')', undef);
66  
67 50 for ($switch) {
68 50 ▶ if ($_ eq ':' || $_ eq '?') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq ":" or $_ eq "?") 50 0 50
Condition33%1/3
$_ eq ":" or $_ eq "?"
l!l&&r!l&&!r
5000
MC/DC0%0/2
$_ eq ":" or $_ eq "?"
$_ eq ":" $_ eq "?"
Truth table33%1/3
A or B
A= $_ eq ":"B= $_ eq "?"
ABresult
1X1
011
000
69 50 ▶ $r = $a . ($self->check->{$token} // '[^/]+?') . $b;
Condition50%1/2
$self->check->{$token} // "[^/]+?"
l!l
050
MC/DC0%0/1
$self->check->{$token} // "[^/]+?"
$self->check->{$token}
Truth table50%1/2
A
A= $self->check->{$token}
Aresult
11
00
70 }
71 50 ▶ if ($_ eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "*") 0 50 50
72 0 $r = $a . '.+' . $b;
73 }
74 }
75  
76 50 ▶ $char = $char . '?' if $char eq '/' && $switch eq '?';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "/" and $switch eq "?" 0 50 50
Condition33%1/3
$char eq "/" and $switch eq "?"
!ll&&!rl&&r
0500
MC/DC0%0/2
$char eq "/" and $switch eq "?"
$char eq "/" $switch eq "?"
Truth table33%1/3
A and B
A= $char eq "/"B= $switch eq "?"
ABresult
0X0
100
111
77 50 ▶ $r .= '?' if $switch eq '?';
Branch: 1 branch
BranchTrueFalseTotal
if $switch eq "?" 0 50 50
78  
79 50 return $char . $r;
80 }
81  
82 20 ▶sub tags {
Subroutine tags: called CC=2 SCAR=6.9
Pod undocumented
83 20 my $self = shift;
84  
85 20 ▶ unless ($self->{tags}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"tags"}) 17 3 20
86 17 return [Raisin::Util::make_tag_from_path($self->path)];
87 }
88  
89 3 $self->{tags};
90 }
91  
92 467 ▶sub match {
Subroutine match: called CC=7 SCAR=19.5
Pod undocumented
93 467 my ($self, $method, $path) = @_;
94  
95 467 $self->{named} = undef;
96  
97 467 ▶ return if !$method || lc($method) ne lc($self->method);
Branch: 1 branch
BranchTrueFalseTotal
if not $method or lc $method ne lc $self->method 321 146 467
Condition66%2/3
not $method or lc $method ne lc $self->method
l!l&&r!l&&!r
0321146
MC/DC50%1/2
not $method or lc $method ne lc $self->method
not $method lc $method ne lc $self->method
Truth table66%2/3
not(A) or B
A= not $methodB= lc $method ne lc $self->method
ABresult
1X1
011
000
98 146 ▶ return if $path !~ $self->regex;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ $self->regex 70 76 146
99  
100 76 my %captured = %+;
101  
102 76 foreach my $p (@{ $self->params }) {
103 96 ▶ next unless $p->named;
Branch: 1 branch
BranchTrueFalseTotal
unless $p->named 72 24 96
104 24 my $copy = $captured{ $p->name };
105 24 ▶ return unless $p->validate(\$copy, 'quite');
Branch: 1 branch
BranchTrueFalseTotal
unless $p->validate(\$copy, "quite") 1 23 24
106 }
107  
108 75 $self->named(\%captured);
109  
110 75 1;
111 }
112  
113 18 1;
114  
115 __END__
« blib/lib/Raisin/Routes.pm ↑ Summary blib/lib/Raisin/Request.pm »