| 1 | package Net::HTTP::Spore::Role::Middleware; | ||||||||||||||||||||||||||||
| 2 | 26 | $Net::HTTP::Spore::Role::Middleware::VERSION = '0.09'; | |||||||||||||||||||||||||||
| 3 | 26 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 26 | ▶ | use Class::Load; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 26 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | has middlewares => ( | ||||||||||||||||||||||||||||
| 8 | is => 'rw', | ||||||||||||||||||||||||||||
| 9 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 10 | traits => ['Array'], | ||||||||||||||||||||||||||||
| 11 | lazy => 1, | ||||||||||||||||||||||||||||
| 12 | 23 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 26 | auto_deref => 1, | |||||||||||||||||||||||||||
| 14 | handles => { _add_middleware => 'push', _filter_middlewares => 'grep' }, | ||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 43 | ▶ | sub _load_middleware { | ||||||||||||||||||||||||||
|
Subroutine
_load_middleware: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 18 | 43 | my ( $self, $mw, $cond, @args ) = @_; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 43 | ▶ | Class::Load::load_class($mw) unless blessed($mw); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 41 | my $code = $mw->wrap( $cond, @args ); | |||||||||||||||||||||||||||
| 23 | 41 | $self->_trace_msg('== enabling middleware %s', $mw); | |||||||||||||||||||||||||||
| 24 | 41 | $self->_add_middleware($code); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 41 | ▶ | sub _complete_mw_name { | ||||||||||||||||||||||||||
|
Subroutine
_complete_mw_name: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 28 | 41 | my ($self, $mw) = @_; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 41 | ▶ | if ($mw =~ /^\+/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 31 | 1 | $mw =~ s/^\+//; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | elsif ($mw !~ /Net\:\:HTTP\:\:Spore\:\:Middleware/) { | ||||||||||||||||||||||||||||
| 34 | 40 | $mw = "Net::HTTP::Spore::Middleware::".$mw; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 41 | return $mw; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 43 | ▶ | sub enable { | ||||||||||||||||||||||||||
|
Subroutine
enable: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 43 | my ($self, $mw, @args) = @_; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 43 | ▶ | confess "middleware name is missing" unless $mw; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 42 | ▶ | $self->enable_if(sub{1}, $mw, @args); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 40 | $self; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 44 | ▶ | sub enable_if { | ||||||||||||||||||||||||||
|
Subroutine
enable_if: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 44 | my ($self, $cond, $mw, @args) = @_; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 44 | ▶ | confess "condition must be a code ref" if (!$cond || ref $cond ne 'CODE'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $cond or ref $cond ne "CODE"
MC/DC50%1/2
not $cond or ref $cond ne "CODE"
not $cond
ref $cond ne "CODE"
Truth table66%2/3
not(A) or B
A= not $condB= ref $cond ne "CODE"
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 43 | ▶ | if(ref($mw) eq 'CODE'){ # anonymous middleware | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 2 | Class::Load::load_class('Net::HTTP::Spore::Middleware'); | |||||||||||||||||||||||||||
| 56 | 2 | my $anon = Class::MOP::Class->create_anon_class( | |||||||||||||||||||||||||||
| 57 | superclasses => ['Net::HTTP::Spore::Middleware'], | ||||||||||||||||||||||||||||
| 58 | methods => { | ||||||||||||||||||||||||||||
| 59 | call => $mw | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | 2 | $mw = $anon->new_object; | |||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||
| 64 | 41 | $mw = $self->_complete_mw_name($mw); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 43 | $self->_load_middleware($mw, $cond, @args); | |||||||||||||||||||||||||||
| 67 | 41 | $self; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | ▶ | sub reset_middlewares { | ||||||||||||||||||||||||||
|
Subroutine
reset_middlewares: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 72 | 1 | $self->middlewares([]); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 26 | 1; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||