blib/lib/Pinto/Server/Router.pm

filter: Statementstmt 100% 30 / 30 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 50.0% 1 / 2 totaltotal 95.1% 39 / 41 CC 2 SCAR 2.2
CC
2
Cov
97%
route
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« blib/lib/Pinto/Server/Responder.pm ↑ Summary blib/lib/Pinto/Database.pm »
1 # ABSTRACT: Routes server requests
2  
3 package Pinto::Server::Router;
4  
5 15 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 15 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Plack::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use Router::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 #-------------------------------------------------------------------------------
12  
13 15 our $VERSION = '0.14'; # VERSION
14  
15 #-------------------------------------------------------------------------------
16  
17 has route_handler => (
18 is => 'ro',
19 isa => 'Router::Simple',
20 13 ▶ default => sub { Router::Simple->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
21 15 );
22  
23 #-------------------------------------------------------------------------------
24  
25 13 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
26 13 my ($self) = @_;
27  
28 13 my $r = $self->route_handler;
29  
30 13 $r->connect( '/action/{action}', { responder => 'Action' }, { method => 'POST' } );
31  
32 13 $r->connect( '/*', { responder => 'File' }, { method => [ 'GET', 'HEAD' ] } );
33  
34 13 return $self;
35 }
36  
37 #-------------------------------------------------------------------------------
38  
39  
40 140 ▶sub route {
Subroutine route: called CC=2 SCAR=7.0
Pod documented
41 140 my ( $self, $env, $root ) = @_;
42  
43 140 ▶ my $p = $self->route_handler->match($env)
Branch: 1 branch
BranchTrueFalseTotal
my $p = $self->route_handler->match($env) or return [404, [], ["Not Found"]] 140 0 140
44 or return [ 404, [], ['Not Found'] ];
45  
46 140 my $responder_class = 'Pinto::Server::Responder::' . $p->{responder};
47 140 Class::Load::load_class($responder_class);
48  
49 140 my $request = Plack::Request->new($env);
50 140 my $responder = $responder_class->new( request => $request, root => $root );
51  
52 # HACK: Plack-1.02 calls URI::Escape::uri_escape() with arguments
53 # that inadvertently cause $_ to be compiled into a regex. This
54 # will emit warning if $_ is undef, or may blow up if it contains
55 # certain stuff. To avoid this, just make sure $_ is empty for
56 # now. A patch has been sent to Miyagawa.
57 140 local $_ = '';
58  
59 140 return $responder->respond;
60 }
61  
62 #-------------------------------------------------------------------------------
63  
64 15 __PACKAGE__->meta->make_immutable;
65  
66 #-------------------------------------------------------------------------------
67  
68 15 1;
69  
70 __END__
« blib/lib/Pinto/Server/Responder.pm ↑ Summary blib/lib/Pinto/Database.pm »