| 1 | package Pickles::Dispatcher::Auto; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use parent qw/Pickles::Dispatcher/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Class::Load ":all"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Module::Pluggable::Object; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Pickles::Context; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use String::CamelCase qw/camelize decamelize/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 11 | ▶ | sub match { | ||||||||||||||||||||||||||
|
Subroutine
match: called CC=9 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 11 | my $self = shift; | |||||||||||||||||||||||||||
| 14 | 11 | my ($req) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 11 | my $match = $self->SUPER::match(@_); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 11 | ▶ | if (exists $match->{controller} && exists $match->{action}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $match->{"controller"} and exists $match->{"action"}
MC/DC50%1/2
exists $match->{"controller"} and exists $match->{"action"}
exists $match->{"controller"}
exists $match->{"action"}
Truth table66%2/3
A and B
A= exists $match->{"controller"}B= exists $match->{"action"}
| |||||||||||||||||||||||||||||
| 19 | 4 | return $match; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 7 | ▶ | my $path_info = $req->env->{PATH_INFO} || $req->path_info; | ||||||||||||||||||||||||||
|
Condition33%1/3
$req->env->{'PATH_INFO'} || $req->path_info
MC/DC0%0/2
$req->env->{'PATH_INFO'} || $req->path_info
$req->env->{'PATH_INFO'}
$req->path_info
Truth table33%1/3
A || B
A= $req->env->{'PATH_INFO'}B= $req->path_info
| |||||||||||||||||||||||||||||
| 23 | 7 | $path_info =~ s{^/}{}; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 7 | my $is_index = $path_info =~ m{/$}; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 7 | my @parts = split "/", $path_info; | |||||||||||||||||||||||||||
| 28 | 7 | ▶ | my $action = $is_index ? "index" : pop @parts || "index"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
pop @parts or "index"
MC/DC0%0/1
pop @parts or "index"
pop @parts
Truth table50%1/2
A
A= pop @parts
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 7 | my $controller = ""; | |||||||||||||||||||||||||||
| 31 | 7 | my %args; | |||||||||||||||||||||||||||
| 32 | 7 | ▶ | if (@parts) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 6 | my @camelized_parts = map { camelize $_ } @parts; | |||||||||||||||||||||||||||
| 34 | 6 | $controller .= join "::", @camelized_parts; | |||||||||||||||||||||||||||
| 35 | 6 | $controller .= "::Root"; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | else { | ||||||||||||||||||||||||||||
| 38 | 1 | $controller = "Root"; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 7 | $match = +{ | |||||||||||||||||||||||||||
| 42 | controller => $controller, | ||||||||||||||||||||||||||||
| 43 | action => $action, | ||||||||||||||||||||||||||||
| 44 | }; | ||||||||||||||||||||||||||||
| 45 | 7 | for my $key( keys %{$match} ) { | |||||||||||||||||||||||||||
| 46 | 14 | ▶ | next if $key =~ m/^(controller|action)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | $args{$key} = delete $match->{$key}; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 7 | $match->{args} = \%args; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 7 | return $match; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub load_controllers { | ||||||||||||||||||||||||||
|
Subroutine
load_controllers: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 0 | my ($self, $prefix) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my @controllers = Module::Pluggable::Object->new( | |||||||||||||||||||||||||||
| 58 | require => 1, | ||||||||||||||||||||||||||||
| 59 | search_path => ["$prefix\::Controller"], | ||||||||||||||||||||||||||||
| 60 | )->plugins; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | for my $controller (@controllers) { | |||||||||||||||||||||||||||
| 63 | 0 | load_class($controller); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | 1; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $_sub_controller_class = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 70 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 71 | 0 | my $match = $self->match; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $controller = $match->{controller} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | (my $class = sprintf "%s::Controller::%s", $self->appname, camelize($controller)) =~ s{/}{::}g; | |||||||||||||||||||||||||||
| 74 | 0 | return $class; | |||||||||||||||||||||||||||
| 75 | 2 | }; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $_sub__prepare = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 78 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | 0 | my $match = $self->dispatcher->match($self->req); | |||||||||||||||||||||||||||
| 80 | 0 | my @paths = split '::', decamelize($match->{controller}); | |||||||||||||||||||||||||||
| 81 | 0 | my $controller = $match->{controller}; | |||||||||||||||||||||||||||
| 82 | 0 | my $view_template; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | $controller =~ /Root$/ and pop @paths; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | $view_template = join("/", map { $_ } @paths) . "/" . decamelize($match->{action}); | |||||||||||||||||||||||||||
| 85 | 0 | $self->stash->{'VIEW_TEMPLATE'} = $view_template; | |||||||||||||||||||||||||||
| 86 | 2 | }; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 2 | ▶ | no warnings "redefine"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 2 | *Pickles::Context::_prepare = $_sub__prepare; | |||||||||||||||||||||||||||
| 90 | 2 | *Pickles::Context::controller_class = $_sub_controller_class; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | 1; | |||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||