Articulate/Role/Routes.pm

filter: Statementstmt 69.5% 16 / 23 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 66.6% 22 / 33 SCAR 12.3
CC
3
Cov
64%
enable
6.8
BEGIN
1.0
BEGIN
1.0
CRAP 3.4
« Articulate/Sortation.pm ↑ Summary Articulate/Request.pm »
1 package Articulate::Role::Routes;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Articulate::Role::Routes - allow routes to be enabled
9  
10 =cut
11  
12 =head1 DESCRIPTION
13  
14 This is a helper role for route classes which works in tandem with L<Articulate::Syntax::Routes> (which allows a declarative style of routing).
15  
16 Note that it is not mandatory to use either of these, you can use your frameworks's own routing capabiity and merely use Articulate for the service. If you do this, you will need to handle serialisation of L<Articulate::Response> objects yourself.
17  
18 =head1 ATTRIBUTE
19  
20 =head3 enabled
21  
22 Do not set this directly, use C<enable>.
23  
24 =cut
25  
26 =head1 METHOD
27  
28 =head3 enable
29  
30 Finds all that were declared in that package. Note that this does B<not> respect inheritance by searching parent classes, roles, etc. for routes declared there: B<only> routes defined in the package to which this role is applied will be enabled.
31  
32 =cut
33  
34 sub enable { #ideally we want this to be able to switch on and off the routes.
35 0 ▶ my $self = shift;
Subroutine enable: not called CC=3 SCAR=19.2
Pod documented
36 0 my $class = ref $self;
37 0 my $routes = "${class}::__routes";
38 {
39 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
40 0 ▶ $$routes //= [];
Condition0%0/2
$$routes //= []
l!l
00
MC/DC0%0/1
$$routes //= []
$$routes
Truth table0%0/2
A
A= $$routes
Aresult
11
00
41 0 $_->( $self ) for @$$routes;
42 }
43 0 $self->enabled(1);
44 }
45  
46 has enabled => (
47 is => 'rw',
48 12 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 4 );
50  
51 4 with 'Articulate::Role::Component';
52  
53 4 1;
« Articulate/Sortation.pm ↑ Summary Articulate/Request.pm »