| 1 | package Web::Machine::Util::BodyEncoding; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Module to handle body encoding | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 19 | our $VERSION = '0.17'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 19 | ▶ | use Scalar::Util qw/ weaken isweak /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 19 | ▶ | use Encode (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 19 | ▶ | use Web::Machine::Util qw[ first pair_key pair_value ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 19 | ▶ | use Sub::Exporter -setup => { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | exports => [qw[ | ||||||||||||||||||||||||||||
| 15 | encode_body_if_set | ||||||||||||||||||||||||||||
| 16 | encode_body | ||||||||||||||||||||||||||||
| 17 | ]] | ||||||||||||||||||||||||||||
| 18 | 19 | }; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 7 | ▶ | sub encode_body_if_set { | ||||||||||||||||||||||||||
|
Subroutine
encode_body_if_set: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 7 | my ($resource, $response) = @_; | |||||||||||||||||||||||||||
| 22 | 7 | ▶ | encode_body( $resource, $response ) if $response->body; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 44 | ▶ | sub encode_body { | ||||||||||||||||||||||||||
|
Subroutine
encode_body: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 44 | my ($resource, $response) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 44 | my $metadata = $resource->request->env->{'web.machine.context'}; | |||||||||||||||||||||||||||
| 29 | 44 | my $chosen_encoding = $metadata->{'Content-Encoding'}; | |||||||||||||||||||||||||||
| 30 | 44 | my $encoder = $resource->encodings_provided->{ $chosen_encoding }; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 44 | my $chosen_charset = $metadata->{'Charset'}; | |||||||||||||||||||||||||||
| 33 | 44 | my $charsetter; | |||||||||||||||||||||||||||
| 34 | 44 | ▶ | if ( $chosen_charset && $resource->charsets_provided ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$chosen_charset and $resource->charsets_provided
MC/DC50%1/2
$chosen_charset and $resource->charsets_provided
$chosen_charset
$resource->charsets_provided
Truth table66%2/3
A and B
A= $chosen_charsetB= $resource->charsets_provided
| |||||||||||||||||||||||||||||
| 35 | 18 | ▶ | my $match = first { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||
| 36 | 18 | ▶ | my $name = $_ && ref $_ ? pair_key($_) : $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_ and ref $_
MC/DC50%1/2
$_ and ref $_
$_
ref $_
Truth table66%2/3
A and B
A= $_B= ref $_
| |||||||||||||||||||||||||||||
| 37 | 18 | ▶ | $name && $name eq $chosen_charset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 14 | @{ $resource->charsets_provided }; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | $charsetter | ||||||||||||||||||||||||||||
| 42 | = ref $match | ||||||||||||||||||||||||||||
| 43 | ? pair_value($match) | ||||||||||||||||||||||||||||
| 44 | 14 | ▶ | : sub { Encode::encode( $match, $_[1] ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 44 | ▶ | $charsetter ||= sub { $_[1] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$charsetter ||= sub {
$_[1];
}
MC/DC0%0/2
$charsetter ||= sub {
$_[1];
}
$charsetter
sub {
$_[1];
}
Truth table66%2/3
A ||= B
A= $charsetterB= sub {
$_[1];
}
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 44 | ▶ | push @{ $resource->request->env->{'web.machine.content_filters'} ||= [] }, | ||||||||||||||||||||||||||
|
Condition50%1/2
$resource->request->env->{"web.machine.content_filters"} ||= []
MC/DC0%0/1
$resource->request->env->{"web.machine.content_filters"} ||= []
$resource->request->env->{"web.machine.content_filters"}
Truth table50%1/2
A
A= $resource->request->env->{"web.machine.content_filters"}
| |||||||||||||||||||||||||||||
| 50 | 153 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 51 | 153 | my $chunk = shift; | |||||||||||||||||||||||||||
| 52 | 153 | ▶ | weaken $resource unless isweak $resource; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 153 | ▶ | return unless defined $chunk; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 147 | return $resource->$encoder($resource->$charsetter($chunk)); | |||||||||||||||||||||||||||
| 55 | 44 | }; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 19 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||