| 1 | package Router::Simple; | ||||||||||||||||||||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use 5.00800; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 13 | our $VERSION = '0.18'; | |||||||||||||||||||||||||||
| 6 | 13 | ▶ | use Router::Simple::SubMapper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Router::Simple::Route; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use List::Util qw/max/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use Class::Accessor::Lite 0.05 ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 13 | new => 1, | |||||||||||||||||||||||||||
| 13 | ro => [qw(routes directory_slash)], | ||||||||||||||||||||||||||||
| 14 | 13 | ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 13 | our $_METHOD_NOT_ALLOWED; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 44 | ▶ | sub connect { | ||||||||||||||||||||||||||
|
Subroutine
connect: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 44 | my $self = shift; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 44 | ▶ | if ($self->{directory_slash}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | # connect([$name, ]$pattern[, \%dest[, \%opt]]) | ||||||||||||||||||||||||||||
| 23 | 4 | ▶ | if (@_ == 1 || ref $_[1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ == 1 or ref $_[1]
MC/DC100%2/2
@_ == 1 or ref $_[1]
@_ == 1
ref $_[1]
Truth table100%3/3
A or B
A= @_ == 1B= ref $_[1]
| |||||||||||||||||||||||||||||
| 24 | 3 | unshift(@_, undef); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # \%opt | ||||||||||||||||||||||||||||
| 28 | 4 | ▶ | $_[3] ||= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$_[3] ||= {}
MC/DC100%1/1
$_[3] ||= {}
$_[3]
Truth table100%2/2
A
A= $_[3]
| |||||||||||||||||||||||||||||
| 29 | 4 | $_[3]->{directory_slash} = 1; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 44 | my $route = Router::Simple::Route->new(@_); | |||||||||||||||||||||||||||
| 33 | 44 | push @{ $self->{routes} }, $route; | |||||||||||||||||||||||||||
| 34 | 44 | return $self; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 4 | ▶ | sub submapper { | ||||||||||||||||||||||||||
|
Subroutine
submapper: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 4 | my ($self, $pattern, $dest, $opt) = @_; | |||||||||||||||||||||||||||
| 39 | 4 | ▶ | return Router::Simple::SubMapper->new( | ||||||||||||||||||||||||||
|
Condition75%3/4
$dest || {}
$opt || {}
MC/DC100%1/1
$dest || {}
$dest
MC/DC0%0/1
$opt || {}
$opt
Truth table100%2/2
A
A= $dest
Truth table50%1/2
A
A= $opt
| |||||||||||||||||||||||||||||
| 40 | parent => $self, | ||||||||||||||||||||||||||||
| 41 | pattern => $pattern, | ||||||||||||||||||||||||||||
| 42 | dest => $dest || +{}, | ||||||||||||||||||||||||||||
| 43 | opt => $opt || +{}, | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 51 | ▶ | sub _match { | ||||||||||||||||||||||||||
|
Subroutine
_match: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 48 | 51 | my ($self, $env) = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 51 | ▶ | if (ref $env) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | # "I think there was a discussion about that a while ago and it is up to apps to deal with empty PATH_INFO as root / iirc" | ||||||||||||||||||||||||||||
| 52 | # -- by @miyagawa | ||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||
| 54 | # see http://blog.64p.org/entry/2012/10/05/132354 | ||||||||||||||||||||||||||||
| 55 | 44 | ▶ | if ($env->{PATH_INFO} eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 1 | $env->{PATH_INFO} = '/'; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } else { | ||||||||||||||||||||||||||||
| 59 | 7 | $env = +{ PATH_INFO => $env } | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 51 | local $_METHOD_NOT_ALLOWED; | |||||||||||||||||||||||||||
| 63 | 51 | $self->{method_not_allowed} = 0; | |||||||||||||||||||||||||||
| 64 | 51 | for my $route (@{$self->{routes}}) { | |||||||||||||||||||||||||||
| 65 | 141 | my $match = $route->match($env); | |||||||||||||||||||||||||||
| 66 | 141 | ▶ | return ($match, $route) if $match; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 13 | $self->{method_not_allowed} = $_METHOD_NOT_ALLOWED; | |||||||||||||||||||||||||||
| 69 | 13 | return undef; # not matched. | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 5 | ▶ | sub method_not_allowed { | ||||||||||||||||||||||||||
|
Subroutine
method_not_allowed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 74 | 5 | $self->{method_not_allowed}; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 50 | ▶ | sub match { | ||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 50 | my ($self, $req) = @_; | |||||||||||||||||||||||||||
| 79 | 50 | my ($match) = $self->_match($req); | |||||||||||||||||||||||||||
| 80 | 50 | return $match; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | ▶ | sub routematch { | ||||||||||||||||||||||||||
|
Subroutine
routematch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 1 | my ($self, $req) = @_; | |||||||||||||||||||||||||||
| 85 | 1 | return $self->_match($req); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub as_string { | ||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my $mn = max(map { $_->{name} ? length($_->{name}) : 0 } @{$self->{routes}}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $nn = max(map { $_->{method} ? length(join(",",@{$_->{method}})) : 0 } @{$self->{routes}}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | return join('', map { | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sprintf "%-${mn}s %-${nn}s %s\n", $_->{name}||'', join(',', @{$_->{method} || []}) || '', $_->{pattern} | ||||||||||||||||||||||||||
|
Condition0%0/2
$_->{'method'} || []
MC/DC0%0/1
$_->{'method'} || []
$_->{'method'}
Truth table0%0/2
A
A= $_->{'method'}
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | } @{$self->{routes}}) . "\n"; | ||||||||||||||||||||||||||
|
Condition0%0/4
$_->{'name'} || ''
join(',', @{$_->{'method'} or [];}) || ''
MC/DC0%0/1
$_->{'name'} || ''
$_->{'name'}
MC/DC0%0/1
join(',', @{$_->{'method'} or [];}) || ''
join(',', @{$_->{'method'} or [];})
Truth table0%0/2
A
A= $_->{'name'}
Truth table0%0/2
A
A= join(',', @{$_->{'method'} or [];})
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 13 | 1; | |||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||