OX/RouteBuilder/HTTPMethod.pm

filter: Statementstmt 85.7% 36 / 42 Branchbran 50.0% 5 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 79.3% 50 / 63 CC 6 SCAR 10.8
CC
6
Cov
79%
__ANON__
6.3
parse_action_spec
3.0
compile_routes
1.1
CRAP 2.9
« OX/Application/Role/RouterConfig.pm ↑ Summary OX/Meta/Role/HasRoutes.pm »
1 package OX::RouteBuilder::HTTPMethod;
2 34 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 34 $OX::RouteBuilder::HTTPMethod::AUTHORITY = 'cpan:STEVAN';
4 }
5 34 $OX::RouteBuilder::HTTPMethod::VERSION = '0.14';
6 34 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 34 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 # ABSTRACT: OX::RouteBuilder which routes to a method in a controller based on the HTTP method
9  
10 34 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 34 with 'OX::RouteBuilder';
13  
14  
15 6 ▶sub compile_routes {
Subroutine compile_routes: called CC=1 SCAR=0.5
Pod undocumented
16 6 my $self = shift;
17 6 my ($app) = @_;
18  
19 6 my $spec = $self->route_spec;
20 6 my $params = $self->params;
21  
22 6 my ($defaults, $validations) = $self->extract_defaults_and_validations($params);
23 6 $defaults = { %$spec, %$defaults };
24  
25 1 ▶ my $target = sub {
Subroutine __ANON__: called CC=4 SCAR=18.4
26 1 my ($req) = @_;
27  
28 1 my $match = $req->mapping;
29 1 my $a = $match->{action};
30  
31 1 my $err;
32 1 ▶ my $s = try { $app->fetch($a) } catch { ($err) = split "\n"; undef };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
33 return [
34 1 ▶ 500,
Branch: 1 branch
BranchTrueFalseTotal
unless $s 1 0 1
35 [],
36 ["Cannot resolve $a in " . blessed($app) . ": $err"]
37 ] unless $s;
38  
39 0 my $component = $s->get;
40 0 my $method = lc($req->method);
41  
42 0 ▶ if ($component->can($method)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($component->can($method)) { } 0 0 0
elsif ($component->can('any')) { } 0 0 0
43 0 return $component->$method(@_);
44 }
45 elsif ($component->can('any')) {
46 0 return $component->any(@_);
47 }
48 else {
49 return [
50 0 500,
51 [],
52 ["Component $component has no method $method"]
53 ];
54 }
55 6 };
56  
57 return {
58 6 path => $self->path,
59 defaults => $defaults,
60 target => $target,
61 validations => $validations,
62 };
63 }
64  
65 167 ▶sub parse_action_spec {
Subroutine parse_action_spec: called CC=3 SCAR=11.0
Pod undocumented
66 167 my $class = shift;
67 167 my ($action_spec) = @_;
68  
69 167 ▶ return if ref($action_spec);
Branch: 1 branch
BranchTrueFalseTotal
if ref $action_spec 76 91 167
70 91 ▶ return unless $action_spec =~ /^(\w+)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $action_spec =~ /^(\w+)$/ 86 5 91
71  
72 return {
73 5 action => $1,
74 name => $action_spec,
75 };
76 }
77  
78 34 __PACKAGE__->meta->make_immutable;
79  
80  
81 34 1;
82  
83 __END__
« OX/Application/Role/RouterConfig.pm ↑ Summary OX/Meta/Role/HasRoutes.pm »