| 1 | package Shodo::Suzuri; | ||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use Carp qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use JSON qw/from_json to_json/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Data::Validator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Clone qw/clone/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 5 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 12 | my $self = bless { | ||||||||||||||||||||||||||||
| 13 | hanshi => $args{hanshi} | ||||||||||||||||||||||||||||
| 14 | 5 | }, $class; | |||||||||||||||||||||||||||
| 15 | 5 | ▶ | $self->stash->{description} = $args{description} || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args{'description'} || ''
MC/DC100%1/1
$args{'description'} || ''
$args{'description'}
Truth table100%2/2
A
A= $args{'description'}
| |||||||||||||||||||||||||||||
| 16 | 5 | $self; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 4 | ▶ | sub hanshi { | ||||||||||||||||||||||||||
|
Subroutine
hanshi: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 4 | shift->{hanshi}; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 48 | ▶ | sub stash { | ||||||||||||||||||||||||||
|
Subroutine
stash: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 48 | my $self = shift; | |||||||||||||||||||||||||||
| 25 | 48 | ▶ | $self->{stash} ||= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"stash"} ||= {}
MC/DC100%1/1
$self->{"stash"} ||= {}
$self->{"stash"}
Truth table100%2/2
A
A= $self->{"stash"}
| |||||||||||||||||||||||||||||
| 26 | 48 | return $self->{stash}; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 4 | ▶ | sub request { | ||||||||||||||||||||||||||
|
Subroutine
request: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 4 | my ($self, $req) = @_; | |||||||||||||||||||||||||||
| 31 | 4 | ▶ | unless (try { $req->isa('HTTP::Request') }) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | Carp::croak("Request is not HTTP::Request: $req"); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 4 | $self->stash->{method} = $req->method; | |||||||||||||||||||||||||||
| 35 | 4 | $self->stash->{path} = $req->uri->path; | |||||||||||||||||||||||||||
| 36 | 4 | $self->stash->{query} = $req->uri->query; | |||||||||||||||||||||||||||
| 37 | 4 | $self->stash->{request_body} = $req->decoded_content; | |||||||||||||||||||||||||||
| 38 | 4 | ▶ | if($req->content_type =~ m!^application/json!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 3 | my $json_body = to_json(from_json($self->stash->{request_body}, { utf8 => 1 }), { pretty => 1 }); | |||||||||||||||||||||||||||
| 40 | 3 | $self->stash->{request_body} = $json_body; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 4 | return $req; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 3 | ▶ | sub response { | ||||||||||||||||||||||||||
|
Subroutine
response: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 3 | my ($self, $res) = @_; | |||||||||||||||||||||||||||
| 47 | 3 | ▶ | unless (try { $res->isa('HTTP::Response') }) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | Carp::croak("Response is not HTTP::Response: $res"); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 3 | $self->stash->{code} = $res->code; | |||||||||||||||||||||||||||
| 51 | 3 | $self->stash->{status_line} = $res->status_line; | |||||||||||||||||||||||||||
| 52 | 3 | $self->stash->{response_body} = $res->decoded_content; | |||||||||||||||||||||||||||
| 53 | 3 | ▶ | if($res->content_type =~ m!^application/json!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 2 | my $json_body = to_json(from_json($self->stash->{response_body}, { utf8 => 1}), { pretty => 1 }); | |||||||||||||||||||||||||||
| 55 | 2 | $self->stash->{response_body} = $json_body; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 3 | return $res; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 4 | ▶ | sub document { | ||||||||||||||||||||||||||
|
Subroutine
document: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 4 | return $self->hanshi->render( $self->stash ); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 4 | ▶ | sub params { | ||||||||||||||||||||||||||
|
Subroutine
params: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 4 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 67 | 4 | $self->stash->{rule} = clone(\%args); | |||||||||||||||||||||||||||
| 68 | 4 | my $validator = Data::Validator->new( %args )->with('NoThrow'); | |||||||||||||||||||||||||||
| 69 | 4 | $self->{validator} = $validator; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 4 | ▶ | sub validate { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=5 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 4 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 74 | 4 | ▶ | Carp::croak "Rule is not set on Suzuri instance" unless $self->{validator}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 4 | my $result; | |||||||||||||||||||||||||||
| 76 | 4 | ▶ | if( ref $args[0] && ref $args[0] eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $args[0] and ref $args[0] eq "HASH"
MC/DC0%0/2
ref $args[0] and ref $args[0] eq "HASH"
ref $args[0]
ref $args[0] eq "HASH"
Truth table33%1/3
A and B
A= ref $args[0]B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 77 | 4 | $result = $self->{validator}->validate($args[0]); | |||||||||||||||||||||||||||
| 78 | }else{ | ||||||||||||||||||||||||||||
| 79 | 0 | $result = $self->{validator}->validate(@args); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 4 | ▶ | if($self->{validator}->has_errors()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 2 | return; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 2 | return $result; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 5 | *req = \&request; | |||||||||||||||||||||||||||
| 88 | 5 | *res = \&response; | |||||||||||||||||||||||||||
| 89 | 5 | *doc = \&document; | |||||||||||||||||||||||||||
| 90 | 5 | *rule = \¶ms; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 5 | 1; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||