| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 65 | 91 | ▶ | return unless $action_spec =~ /^(\w+)\.(\w+)$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||