| 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
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | my $backend = delete $auth_options{backend} | ||||||||||||||||||||||||||||
| 80 | 2 | ▶ | or carp 'No auth backend provided!'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | my $class = 'Authen::Simple::' . $backend; | |||||||||||||||||||||||||||
| 83 | 2 | ▶ | print "Authenticating using $class\n" if is_interactive; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
builtin::blessed($response) and $response->can("finalize")
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")
| |||||||||||||||||||||||||||||
| 101 | if blessed($response) && $response->can('finalize'); | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 130 | return $response; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 107 | 14 | 1; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||||||||