Pickles/Dispatcher.pm

filter: Statementstmt 96.6% 57 / 59 Branchbran 75.0% 9 / 12 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 11 / 11 Podpod 75.0% 3 / 4 totaltotal 87.2% 82 / 94 CC 11 SCAR 11.2
CC
11
Cov
89%
new
5.2
load_controllers
5.1
match
3.0
CRAP 3.1
« Pickles/View/TT.pm ↑ Summary Pickles/Context.pm »
1 package Pickles::Dispatcher;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Cwd();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Router::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use String::CamelCase qw(camelize);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶sub new {
Subroutine new: called CC=5 SCAR=16.4
Pod documented
10 6 my ($class, %args) = @_;
11  
12 6 ▶ my $file = $args{file} || Carp::croak("No file given to $class->new");
Condition50%1/2
$args{'file'} || Carp::croak("No file given to $class->new")
l!l
60
MC/DC0%0/1
$args{'file'} || Carp::croak("No file given to $class->new")
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
Aresult
11
00
13 6 my $pkg = $file;
14 6 $pkg =~ s/([^A-Za-z0-9_])/sprintf("_%2x", unpack("C", $1))/eg;
15  
16 6 ▶ if (! File::Spec->file_name_is_absolute( $file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($file)) 1 5 6
17 1 $file = Cwd::abs_path( $file );
18 }
19 6 my $fqname = sprintf '%s::%s', $class, $pkg;
20 6 my $router_pkg = sprintf <<'SANDBOX', $fqname;
21 package %s;
22 use Router::Simple::Declare;
23 {
24 delete $INC{$file};
25 my $conf = require $file or die $!;
26 $conf;
27 }
28 SANDBOX
29 4 ▶ my $router = eval $router_pkg;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶ if (! eval { $router->isa( 'Router::Simple' ) } || $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not eval { do { $router->isa("Router::Simple") } } or $@) 0 6 6
Condition33%1/3
not eval { do { $router->isa("Router::Simple") } } or $@
l!l&&r!l&&!r
006
MC/DC0%0/2
not eval { do { $router->isa("Router::Simple") } } or $@
not eval { do { $router->isa("Router::Simple") } } $@
Truth table33%1/3
not(A) or B
A= not eval { do { $router->isa("Router::Simple") } }B= $@
ABresult
1X1
011
000
31 0 Carp::croak("file $args{file} returned something other than Router::Simple");
32 }
33 6 bless { router => $router }, $class;
34 }
35  
36 11 ▶sub router {
Subroutine router: called CC=1 SCAR=0.0
Pod documented
37 11 my $self = shift;
38 11 $self->{router};
39 }
40  
41 6 ▶sub match {
Subroutine match: called CC=3 SCAR=11.0
Pod documented
42 6 my( $self, $req ) = @_;
43 6 my $match = $self->router->match( $req->env );
44 6 my %args;
45 6 for my $key( keys %{$match} ) {
46 15 ▶ next if $key =~ m{^(controller|action)$};
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^(controller|action)$/ 12 3 15
47 3 $args{$key} = delete $match->{$key};
48 }
49 6 $match->{args} = \%args;
50 6 $match;
51 }
52  
53 5 ▶sub load_controllers {
Subroutine load_controllers: called CC=5 SCAR=16.3
Pod undocumented
54 5 my( $self, $prefix ) = @_;
55 5 my $routes = $self->router->{routes};
56 5 ▶ if ($routes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($routes) 5 0 5
57 5 my %seen;
58 5 foreach my $route (@$routes) {
59 110 my $dest = $route->dest;
60 110 my $controller = $dest->{controller};
61 110 ▶ if (! $controller) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($controller) 0 110 110
62 0 warn "No controller specified for path " . $route->pattern;
63 }
64 110 ▶ next if $seen{ $controller }++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$controller}++ 90 20 110
65 20 Plack::Util::load_class( "Controller::" . camelize($controller), $prefix );
66 }
67 }
68 5 1;
69 }
70  
71 4 1;
72  
73 __END__
« Pickles/View/TT.pm ↑ Summary Pickles/Context.pm »