blib/lib/Kelp/Module/Routes.pm

filter: Statementstmt 100% 19 / 19 Branchbran n/a Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 92.8% 26 / 28 CC 2 SCAR 2.9
CC
2
Cov
95%
build
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« bin/kelp-generator ↑ Summary blib/lib/Kelp/Module/JSON.pm »
1 package Kelp::Module::Routes;
2  
3 37 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 37 ▶use Kelp::Base 'Kelp::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 37 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 37 our @CARP_NOT = qw(Kelp::Module Kelp);
8  
9 37 my $DEFAULT_ROUTER = 'Kelp::Routes';
10  
11 sub build
12 51 ▶{
Subroutine build: called CC=2 SCAR=7.0
Pod documented
13 51 my ($self, %args) = @_;
14  
15 51 ▶ my $router = delete($args{router}) // ('+' . $DEFAULT_ROUTER);
Condition50%1/2
delete $args{"router"} // '+' . $DEFAULT_ROUTER
l!l
051
MC/DC0%0/1
delete $args{"router"} // '+' . $DEFAULT_ROUTER
delete $args{"router"}
Truth table50%1/2
A
A= delete $args{"router"}
Aresult
11
00
16  
17 51 my $router_class = Plack::Util::load_class($router, $DEFAULT_ROUTER);
18 51 my $r = $router_class->new(%args);
19  
20 # Register two methods:
21 # * routes - contains the routes instance
22 # * add_route - a shortcut to the 'add' method
23 $self->register(
24 routes => $r,
25 110 ▶ add_route => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
26 110 my $app = shift;
27 110 return $r->add(@_);
28 }
29 51 );
30 }
31  
32 37 1;
33  
34 __END__
35  
36 =head1 NAME
37  
38 Kelp::Module::Routes - Default router module for Kelp
39  
40 =head1 SYNOPSIS
41  
42 # config.pl
43 {
44 # This module is included by default
45 # modules => ['Routes'],
46 modules_init => {
47 Routes => {
48 base => 'MyApp'
49 }
50 }
51 }
52  
53 # lib/MyApp.pm
54 sub build {
55 my $self = shift;
56 mt $self->add_route('/', 'home');
57 }
58  
59  
60 =head1 DESCRIPTION
61  
62 This module and L<Kelp::Module::Config> are automatically loaded into each Kelp
63 application. It initializes the routing table for the web application.
64  
65 =head1 REGISTERED METHODS
66  
67 This module registers the following methods into the underlying app:
68  
69 =head2 routes
70  
71 An instance to L<Kelp::Routes>, or whichever router was specified in the
72 configuration.
73  
74 =head2 add_route
75  
76 A shortcut to the L<Kelp::Routes/add> method.
77  
78 =head2 CONFIGURATION
79  
80 The configuration for this module contains the following keys:
81  
82 =head3 router
83  
84 The router class to use. The default value is C<Kelp::Routes>, but any other
85 class can be specified. A normal string will be considered a subclass of
86 C<Kelp::Routes>, for example:
87  
88 router => 'Custom'
89  
90 will look for C<Kelp::Routes::Custom>. To specify a fully qualified class,
91 prefix it with a plus sign.
92  
93 router => '+My::Special::Router'
94  
95 =head3 configuration of the router
96  
97 All other configuration is passed to the router. For the configuration of the
98 default router, see L<Kelp::Routes/ATTRIBUTES>.
99  
« bin/kelp-generator ↑ Summary blib/lib/Kelp/Module/JSON.pm »