blib/lib/Pinto/Server.pm

filter: Statementstmt 100% 64 / 64 Branchbran 75.0% 6 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 18 / 18 Podpod 66.6% 2 / 3 totaltotal 94.9% 93 / 98 CC 6 SCAR 5.8
CC
6
Cov
96%
to_app
4.0
call
3.0
BEGIN
1.0
CRAP 1.8
« blib/lib/Pinto/Result.pm ↑ Summary blib/lib/Pinto/RevisionWalker.pm »
1 # ABSTRACT: Web interface to a Pinto repository
2  
3 package Pinto::Server;
4  
5 14 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use MooseX::ClassAttribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use MooseX::Types::Moose qw(Int HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 14 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 14 ▶use Class::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 ▶use IO::Interactive qw(is_interactive);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 14 ▶use Plack::Middleware::Auth::Basic;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 14 ▶use Pinto::Types qw(Dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 14 ▶use Pinto::Constants qw(:server);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 14 ▶use Pinto::Server::Router;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 14 ▶use Pinto::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 #-------------------------------------------------------------------------------
22  
23 14 our $VERSION = '0.14'; # VERSION
24  
25 #-------------------------------------------------------------------------------
26  
27  
28 14 has root => (
29 is => 'ro',
30 isa => Dir,
31 required => 1,
32 coerce => 1,
33 );
34  
35  
36 14 has auth => (
37 is => 'ro',
38 isa => HashRef,
39 traits => ['Hash'],
40 handles => { auth_options => 'elements' },
41 );
42  
43  
44 has router => (
45 is => 'ro',
46 isa => 'Pinto::Server::Router',
47 13 ▶ default => sub { Pinto::Server::Router->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
48 14 lazy => 1,
49 );
50  
51  
52 14 class_has default_port => (
53 is => 'ro',
54 isa => Int,
55 default => $PINTO_SERVER_DEFAULT_PORT,
56 );
57  
58 #-------------------------------------------------------------------------------
59  
60 13 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
61 13 my ($self) = @_;
62  
63 13 my $repo = Pinto::Repository->new( root => $self->root );
64 13 $repo->assert_sanity_ok;
65  
66 13 return $self;
67 }
68  
69 #-------------------------------------------------------------------------------
70  
71  
72 13 ▶sub to_app {
Subroutine to_app: called CC=4 SCAR=13.9
Pod documented
73 13 my ($self) = @_;
74  
75 13 ▶ my $app = sub { $self->call(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
76  
77 13 ▶ if ( my %auth_options = $self->auth_options ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%auth_options) = $self->auth_options) 2 11 13
78  
79 my $backend = delete $auth_options{backend}
80 2 ▶ or carp 'No auth backend provided!';
Branch: 1 branch
BranchTrueFalseTotal
my $backend = delete $auth_options{"backend"} or carp("No auth backend provided!") 2 0 2
81  
82 2 my $class = 'Authen::Simple::' . $backend;
83 2 ▶ print "Authenticating using $class\n" if is_interactive;
Branch: 1 branch
BranchTrueFalseTotal
if is_interactive() 0 2 2
84 2 Class::Load::load_class($class);
85  
86 2 $app = Plack::Middleware::Auth::Basic->wrap( $app, authenticator => $class->new(%auth_options) );
87 }
88  
89 13 return $app;
90 }
91  
92 #-------------------------------------------------------------------------------
93  
94  
95 140 ▶sub call {
Subroutine call: called CC=3 SCAR=11.0
Pod documented
96 140 my ( $self, $env ) = @_;
97  
98 140 my $response = $self->router->route( $env, $self->root );
99  
100 130 ▶ $response = $response->finalize
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($response) and $response->can("finalize") 57 73 130
Condition66%2/3
builtin::blessed($response) and $response->can("finalize")
!ll&&!rl&&r
73057
MC/DC50%1/2
builtin::blessed($response) and $response->can("finalize")
builtin::blessed($response) $response->can("finalize")
Truth table66%2/3
A and B
A= builtin::blessed($response)B= $response->can("finalize")
ABresult
0X0
100
111
101 if blessed($response) && $response->can('finalize');
102  
103 130 return $response;
104 }
105  
106 #-------------------------------------------------------------------------------
107 14 1;
108  
109 __END__
« blib/lib/Pinto/Result.pm ↑ Summary blib/lib/Pinto/RevisionWalker.pm »