| 1 | package Plack::Middleware::Curlizer; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use ShellQuote::Any; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Plack::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use parent 'Plack::Middleware'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Plack::Util::Accessor qw/ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | callback | ||||||||||||||||||||||||||||
| 10 | 2 | /; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | sub prepare_app { | ||||||||||||||||||||||||||
|
Subroutine
prepare_app: called CC=2 SCAR=10.1
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | unless ($self->callback) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | $self->callback(sub{ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 19 | 0 | my ($curl) = @_; | |||||||||||||||||||||||||||
| 20 | 0 | print "$curl\n"; | |||||||||||||||||||||||||||
| 21 | 0 | }); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 2 | my($self, $env) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | my $req = Plack::Request->new($env); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | my $curl = $self->_build_curl_cmd($req); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | if ($self->callback && ref($self->callback) eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->callback and ref $self->callback eq "CODE"
MC/DC0%0/2
$self->callback and ref $self->callback eq "CODE"
$self->callback
ref $self->callback eq "CODE"
Truth table33%1/3
A and B
A= $self->callbackB= ref $self->callback eq "CODE"
| |||||||||||||||||||||||||||||
| 33 | 2 | $self->callback->($curl, $req, $env); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | my $res = $self->app->($env); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | sub _build_curl_cmd { | ||||||||||||||||||||||||||
|
Subroutine
_build_curl_cmd: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 40 | 2 | my ($self, $req) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 2 | my @cmd = ('curl', $req->uri); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | ▶ | unless ($req->method eq 'GET') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 1 | push @cmd, '-X', $req->method; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | my $http_header_str = $req->headers->as_string; | |||||||||||||||||||||||||||
| 49 | 2 | my @headers = split "\n", $http_header_str; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | for my $h (@headers) { | |||||||||||||||||||||||||||
| 52 | 5 | my ($k, $v) = split /:\s+/, $h; | |||||||||||||||||||||||||||
| 53 | 5 | push @cmd, '-H', qq|$k: $v|; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | ▶ | if ($req->method eq 'POST') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 1 | push @cmd, '--data', $req->content; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | return shell_quote \@cmd; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | 1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||