OX/RouteBuilder/ControllerAction.pm

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