| 1 | package Articulate::Role::Routes; | ||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 5 | ▶ | 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 | 5 | ▶ | no strict 'refs'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||
| 40 | 0 | ▶ | $$routes //= []; | ||||||||||
|
Condition0%0/2
$$routes //= []
MC/DC0%0/1
$$routes //= []
$$routes
Truth table0%0/2
A
A= $$routes
| |||||||||||||
| 41 | 0 | $_->($self) for @$$routes; | |||||||||||
| 42 | } | ||||||||||||
| 43 | 0 | $self->enabled(1); | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | has enabled => ( | ||||||||||||
| 47 | is => 'rw', | ||||||||||||
| 48 | 16 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 49 | 5 | ); | |||||||||||
| 50 | |||||||||||||
| 51 | 5 | with 'Articulate::Role::Component'; | |||||||||||
| 52 | |||||||||||||
| 53 | 5 | 1; | |||||||||||