blib/lib/Pickles/Dispatcher/Auto.pm

filter: Statementstmt 72.9% 54 / 74 Branchbran 58.3% 7 / 12 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 75.0% 9 / 12 Podpod 50.0% 1 / 2 totaltotal 67.2% 76 / 113 CC 12 SCAR 17.1
CC
12
Cov
69%
match
9.3
load_controllers
6.0
__ANON__
6.0
CRAP 5.5
↑ Summary
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
BranchTrueFalseTotal
if (exists $match->{"controller"} and exists $match->{"action"}) 4 7 11
Condition66%2/3
exists $match->{"controller"} and exists $match->{"action"}
!ll&&!rl&&r
704
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"}
ABresult
0X0
100
111
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
l!l&&r!l&&!r
700
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$is_index ? : 3 4 7
Condition50%1/2
pop @parts or "index"
l!l
40
MC/DC0%0/1
pop @parts or "index"
pop @parts
Truth table50%1/2
A
A= pop @parts
Aresult
11
00
29  
30 7 my $controller = "";
31 7 my %args;
32 7 ▶ if (@parts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts) { } 6 1 7
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
BranchTrueFalseTotal
if $key =~ /^(controller|action)$/ 14 0 14
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
BranchTrueFalseTotal
my $controller = $match->{"controller"} or return 0 0 0
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
BranchTrueFalseTotal
$controller =~ /Root$/ and pop @paths 0 0 0
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__
↑ Summary