| 1 | package Web::API::Mock; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use 5.008005; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Plack::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Web::API::Mock::Parser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Web::API::Mock::Resource; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | use Class::Accessor::Lite ( | ||||||||||||||||||||||||||||
| 10 | 3 | new => 1, | |||||||||||||||||||||||||||
| 11 | rw => [ qw/config files not_implemented_urls map/ ], | ||||||||||||||||||||||||||||
| 12 | 3 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | our $VERSION = "0.01"; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub setup { | ||||||||||||||||||||||||||||
| 17 | 1 | ▶ | my ($self, $files, $not_implemented_url_file) = @_; | ||||||||||||||||||||||||||
|
Subroutine
setup: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 1 | my $markdown; | |||||||||||||||||||||||||||
| 19 | 1 | for my $file (@{$files}) { | |||||||||||||||||||||||||||
| 20 | 2 | ▶ | open my $fh, "<:encoding(utf8)", $file or die "cannot open file. $file:$!"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 150 | $markdown .= $line; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 2 | close($fh); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | 1 | my $parser = Web::API::Mock::Parser->new(); | |||||||||||||||||||||||||||
| 27 | 1 | $parser->md($markdown); | |||||||||||||||||||||||||||
| 28 | 1 | $self->map($parser->create_map()); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | $self->not_implemented_urls([]); | |||||||||||||||||||||||||||
| 31 | 1 | ▶ | if ($not_implemented_url_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | open my $fh, "<:encoding(utf8)", $not_implemented_url_file or die "cannot open file. $not_implemented_url_file:$!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 1 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 2 | chomp $line; | |||||||||||||||||||||||||||
| 35 | 2 | $line =~ s/\ //g; | |||||||||||||||||||||||||||
| 36 | 2 | push @{$self->not_implemented_urls}, $line; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 1 | close($fh); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub psgi { | ||||||||||||||||||||||||||||
| 43 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
psgi: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | sub { | ||||||||||||||||||||||||||||
| 45 | 13 | ▶ | my $env = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 13 | my $req = Plack::Request->new($env); | |||||||||||||||||||||||||||
| 48 | 13 | my $plack_response = $req->new_response(404); | |||||||||||||||||||||||||||
| 49 | 13 | my $response = Web::API::Mock::Resource->status_404; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 13 | ▶ | if ($self->check_implemented_url($req->method, $req->path_info)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 2 | $response = Web::API::Mock::Resource->status_501; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | else { | ||||||||||||||||||||||||||||
| 55 | 11 | $response = $self->map->request($req->method, $req->path_info); | |||||||||||||||||||||||||||
| 56 | 11 | ▶ | if (!$response || !$response->{status}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$response and $response->{"status"}
MC/DC50%1/2
$response and $response->{"status"}
$response
$response->{"status"}
Truth table66%2/3
A and B
A= $responseB= $response->{"status"}
| |||||||||||||||||||||||||||||
| 57 | 3 | $response = Web::API::Mock::Resource->status_404; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 13 | $plack_response->headers($response->{header}); | |||||||||||||||||||||||||||
| 62 | 13 | $plack_response->content_type($response->{content_type}); | |||||||||||||||||||||||||||
| 63 | 13 | $plack_response->status($response->{status}); | |||||||||||||||||||||||||||
| 64 | 13 | $plack_response->body($response->{body}); | |||||||||||||||||||||||||||
| 65 | 13 | $plack_response->finalize; | |||||||||||||||||||||||||||
| 66 | 2 | }; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | sub check_implemented_url { | ||||||||||||||||||||||||||||
| 70 | 13 | ▶ | my ($self, $method, $path) = @_; | ||||||||||||||||||||||||||
|
Subroutine
check_implemented_url: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 13 | ▶ | return if ( ref $self->not_implemented_urls ne 'ARRAY'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 8 | my $target = join(',', $method,$path); | |||||||||||||||||||||||||||
| 75 | 8 | my ($url) = grep { m!^$target$! } @{$self->not_implemented_urls}; | |||||||||||||||||||||||||||
| 76 | # TODO 再帰 | ||||||||||||||||||||||||||||
| 77 | 8 | ▶ | unless ($url) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 7 | $target =~ s!^(.+\/).+?$!$1\{.+?}!; | |||||||||||||||||||||||||||
| 79 | 7 | ($url) = grep { m!^$target$! } @{$self->not_implemented_urls}; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 8 | return $url; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 3 | 1; | |||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||