| 1 | package Net::HTTP::Spore::Middleware::Format; | ||||||||||||||||||||||||||||
| 2 | 12 | $Net::HTTP::Spore::Middleware::Format::VERSION = '0.09'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: base class for formats middlewares | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 12 | extends 'Net::HTTP::Spore::Middleware'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 12 | has serializer_key => | |||||||||||||||||||||||||||
| 9 | ( is => 'ro', isa => 'Str', lazy => 1, default => 'sporex.serialization' ); | ||||||||||||||||||||||||||||
| 10 | 12 | has deserializer_key => | |||||||||||||||||||||||||||
| 11 | ( is => 'ro', isa => 'Str', lazy => 1, default => 'sporex.deserialization' ); | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub encode { die "must be implemented" } | ||||||||||||||||||||||||||
|
Subroutine
encode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub decode { die "must be implemented" } | ||||||||||||||||||||||||||
|
Subroutine
decode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub accept_type { die "must be implemented" } | ||||||||||||||||||||||||||
|
Subroutine
accept_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub content_type { die "must be implemented" } | ||||||||||||||||||||||||||
|
Subroutine
content_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 7 | ▶ | sub should_serialize { | ||||||||||||||||||||||||||
|
Subroutine
should_serialize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 20 | 7 | $self->_check_serializer( shift, $self->serializer_key ); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 7 | ▶ | sub should_deserialize { | ||||||||||||||||||||||||||
|
Subroutine
should_deserialize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 25 | 7 | $self->_check_serializer( shift, $self->deserializer_key ); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 14 | ▶ | sub _check_serializer { | ||||||||||||||||||||||||||
|
Subroutine
_check_serializer: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||
| 29 | 14 | my ( $self, $env, $key ) = @_; | |||||||||||||||||||||||||||
| 30 | 14 | ▶ | if ( exists $env->{$key} && $env->{$key} == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $env->{$key} and $env->{$key} == 1
MC/DC0%0/2
exists $env->{$key} and $env->{$key} == 1
exists $env->{$key}
$env->{$key} == 1
Truth table33%1/3
A and B
A= exists $env->{$key}B= $env->{$key} == 1
| |||||||||||||||||||||||||||||
| 31 | 0 | return 0; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||
| 34 | 14 | return 1; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 7 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 7 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 7 | ▶ | return unless $self->should_serialize( $req->env ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 7 | $req->header( $self->accept_type ); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 7 | ▶ | if ( $req->env->{'spore.payload'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | $req->env->{'spore.payload'} = | ||||||||||||||||||||||||||||
| 47 | 2 | $self->encode( $req->env->{'spore.payload'} ); | |||||||||||||||||||||||||||
| 48 | 2 | $req->header( $self->content_type ); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 7 | $req->env->{ $self->serializer_key } = 1; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | return $self->response_cb( | ||||||||||||||||||||||||||||
| 54 | 7 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||
| 55 | 7 | my $res = shift; | |||||||||||||||||||||||||||
| 56 | 7 | ▶ | if ( $res->body ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 7 | ▶ | return if $res->code >= 500; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 7 | ▶ | return unless $self->should_deserialize( $res->env ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 7 | my $content = $self->decode( $res->body ); | |||||||||||||||||||||||||||
| 60 | 7 | $res->body($content); | |||||||||||||||||||||||||||
| 61 | 7 | $res->env->{ $self->deserializer_key } = 1; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 7 | ); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 12 | 1; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | __END__ | ||||||||||||||||||||||||||||