Slick/Route.pm

filter: Statementstmt 87.1% 34 / 39 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 84.3% 43 / 51 CC 5 SCAR 12.1
CC
5
Cov
81%
dispatch
6.2
BEGIN
1.0
BEGIN
1.0
CRAP 3.4
« Slick/CacheExecutor/Redis.pm ↑ Summary Slick/DatabaseExecutor.pm »
1 package Slick::Route;
2  
3 1 ▶use 5.036;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Types::Standard qw(CodeRef HashRef Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Slick::Events qw(EVENTS BEFORE_DISPATCH AFTER_DISPATCH);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use experimental qw(try);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶no warnings qw(experimental::try);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 with 'Slick::EventHandler';
13  
14 1 has route => (
15 is => 'ro',
16 isa => Str,
17 required => 1
18 );
19  
20 1 has callback => (
21 is => 'ro',
22 isa => CodeRef,
23 required => 1
24 );
25  
26 11 ▶sub dispatch {
Subroutine dispatch: called CC=5 SCAR=18.2
Pod documented
27 11 my ( $self, $app, $context ) = @_;
28  
29 11 my @args = ( $app, $context );
30  
31 11 for ( @{ $self->event_handlers->{ BEFORE_DISPATCH() } } ) {
32 2 try {
33 2 ▶ if ( !$_->(@args) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not &$_(@args)) 1 0 1
34 1 goto DONE;
35 }
36 }
37 catch ($e) {
38 1 push $context->stash->{'slick.errors'}->@*, Slick::Error->new($e);
39 };
40 }
41  
42 10 try { $self->callback->(@args); }
43 catch ($e) {
44 0 push $context->stash->{'slick.errors'}->@*, Slick::Error->new($e)
45 };
46  
47 10 for ( @{ $self->event_handlers->{ AFTER_DISPATCH() } } ) {
48 0 try {
49 0 ▶ if ( !$_->(@args) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not &$_(@args)) 0 0 0
50 0 goto DONE;
51 }
52 }
53 catch ($e) {
54 0 push $context->stash->{'slick.errors'}->@*, Slick::Error->new($e);
55 }
56 }
57  
58 DONE:
59  
60 11 return;
61 }
62  
63 1 1;
64  
65 =encoding utf8
66  
67 =head1 NAME
68  
69 Slick::Route
70  
71 =head1 SYNOPSIS
72  
73 An OO wrapper around a central callback and the route path itself.
74  
75 Inherits from L<Slick::EventHandler>.
76  
77 =head1 API
78  
79 =head2 route
80  
81 Returns the route at which this L<Slick::Route> is responsible for.
82  
83 =head2 callback
84  
85 Returns a C<CodeRef> to the callback that will be called with the route is hit.
86  
87 =head2 dispatch
88  
89 Dispatches a L<Slick> and a L<Slick::Context> against all local events and the callback.
90  
91 =head1 See also
92  
93 =over 2
94  
95 =item * L<Slick::Context>
96  
97 =item * L<Slick::Database>
98  
99 =item * L<Slick::DatabaseExecutor>
100  
101 =item * L<Slick::DatabaseExecutor::MySQL>
102  
103 =item * L<Slick::DatabaseExecutor::Pg>
104  
105 =item * L<Slick::EventHandler>
106  
107 =item * L<Slick::Events>
108  
109 =item * L<Slick::Methods>
110  
111 =item * L<Slick::RouteMap>
112  
113 =item * L<Slick::Util>
114  
115 =back
116  
117 =cut
« Slick/CacheExecutor/Redis.pm ↑ Summary Slick/DatabaseExecutor.pm »