| 1 | package Open::API::UI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use File::Raw::JSON (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Open::API; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Template::Stencil; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Markdown::Simple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | our $VERSION = '0.13'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | my @HEADERS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 'Content-Security-Policy' => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | "default-src 'none'; script-src 'self'; style-src 'self'; " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | . "connect-src 'self'; img-src 'self' data:; frame-ancestors 'none'; " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | . "base-uri 'none'; form-action 'self'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 'X-Content-Type-Options' => 'nosniff', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 'X-Frame-Options' => 'DENY', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 'Referrer-Policy' => 'no-referrer', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 'Cache-Control' => 'no-cache', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | my %ASSETS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 'app.css' => 'text/css; charset=utf-8', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 'app.js' => 'application/javascript; charset=utf-8', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 44 | ▶ | sub _base_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_base_dir: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 44 | ▶ | my $pm = $INC{'Open/API/UI.pm'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | or Carp::croak("Open::API::UI: cannot locate my own installation"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 44 | (my $dir = $pm) =~ s/\.pm\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 44 | return $dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 24 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=22 SCAR=31.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 24 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my %opts = @_ == 1 && ref $_[0] eq 'HASH' ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 24 | my $api = delete $opts{api}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 24 | ▶ | Carp::croak("Open::API::UI->new: 'api' must be an Open::API") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($api) and $api->isa("Open::API")
MC/DC50%1/2
builtin::blessed($api) and $api->isa("Open::API")
builtin::blessed($api)
$api->isa("Open::API")
Truth table66%2/3
A and B
A= builtin::blessed($api)B= $api->isa("Open::API")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | unless Scalar::Util::blessed($api) && $api->isa('Open::API'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 23 | my $self = bless { api => $api }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 23 | for my $k (qw(path spec_path title try_it csrf headers)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 138 | ▶ | $self->{$k} = delete $opts{$k} if exists $opts{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 23 | ▶ | Carp::croak("Open::API::UI->new: unknown option(s) " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | . join(', ', map "'$_'", sort keys %opts)) if %opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 22 | ▶ | $self->{path} = '/docs' unless defined $self->{path}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 22 | ▶ | $self->{spec_path} = '/openapi.json' unless defined $self->{spec_path}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 22 | ▶ | $self->{try_it} = 1 unless defined $self->{try_it}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | $self->{csrf} = { header => 'X-CSRF-Token', cookie => 'csrf' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 22 | ▶ | unless exists $self->{csrf}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 22 | for my $k (qw(path spec_path)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | Carp::croak("Open::API::UI->new: '$k' must start with '/'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 43 | ▶ | unless $self->{$k} =~ m{\A/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 42 | ▶ | $self->{$k} =~ s{/\z}{} if length $self->{$k} > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | Carp::croak("Open::API::UI->new: 'path' and 'spec_path' must differ") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 21 | ▶ | if $self->{path} eq $self->{spec_path}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 20 | ▶ | if (my $c = $self->{csrf}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 11 | ▶ | Carp::croak("Open::API::UI->new: 'csrf' must be a hashref or false") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | unless ref $c eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 11 | ▶ | $c->{header} = 'X-CSRF-Token' unless defined $c->{header}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 11 | ▶ | $c->{cookie} = 'csrf' unless defined $c->{cookie}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 20 | ▶ | if (defined $self->{headers} && ref $self->{headers} ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"headers"} and ref $self->{"headers"} ne "HASH"
MC/DC0%0/2
defined $self->{"headers"} and ref $self->{"headers"} ne "HASH"
defined $self->{"headers"}
ref $self->{"headers"} ne "HASH"
Truth table66%2/3
A and B
A= defined $self->{"headers"}B= ref $self->{"headers"} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | Carp::croak("Open::API::UI->new: 'headers' must be a hashref"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 20 | $self->{header_pairs} = _merge_headers($self->{headers}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # Render eagerly: a template problem is a configuration error and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # belongs at startup, like everything else in this stack. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 20 | $self->{html} = $self->_render; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 20 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 20 | ▶ | sub _merge_headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_headers: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 20 | my ($over) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 20 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | my %ov; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 20 | ▶ | if ($over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | $ov{lc $_} = [ $_, $over->{$_} ] for keys %$over; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 20 | ▶ | for (my $i = 0; $i < @HEADERS; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 100 | my ($k, $v) = @HEADERS[$i, $i + 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 100 | ▶ | if (my $o = delete $ov{lc $k}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | push @out, $k, $o->[1] if defined $o->[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 98 | push @out, $k, $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 20 | for my $k (sort keys %ov) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | ▶ | push @out, $ov{$k}[0], $ov{$k}[1] if defined $ov{$k}[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 20 | return \@out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 20 | ▶ | sub _build_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_data: called CC=35 SCAR=45.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 20 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 20 | my $spec = $self->{api}->spec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 20 | ▶ | my $info = $spec->{info} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$spec->{'info'} || {}
MC/DC0%0/1
$spec->{'info'} || {}
$spec->{'info'}
Truth table50%1/2
A
A= $spec->{'info'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # OpenAPI descriptions are CommonMark; render the ones the shell owns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # (info, tags, operations) once, at boot. Markdown::Simple's GFM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # defaults strip raw HTML and dangerous URLs, so the output is safe to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # inject with {% raw %}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 20 | my $md = Markdown::Simple->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 111 | ▶ | my $mdh = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 111 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 111 | ▶ | return '' unless defined $text && length $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $text and length $text
MC/DC50%1/2
defined $text and length $text
defined $text
length $text
Truth table66%2/3
A and B
A= defined $textB= length $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 8 | return $md->render($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 20 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | my %tag_desc = map { ($_->{name} // '') => ($_->{description} // '') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$_->{"name"} // ""
$_->{"description"} // ""
MC/DC0%0/1
$_->{"name"} // ""
$_->{"name"}
MC/DC0%0/1
$_->{"description"} // ""
$_->{"description"}
Truth table50%1/2
A
A= $_->{"name"}
Truth table50%1/2
A
A= $_->{"description"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 20 | ▶ | grep { ref $_ eq 'HASH' } @{ $spec->{tags} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$spec->{'tags'} || []
MC/DC100%1/1
$spec->{'tags'} || []
$spec->{'tags'}
Truth table100%2/2
A
A= $spec->{'tags'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 20 | my (@tags, %tag_by_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 20 | for my $o (@{ $self->{api}->operations }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 71 | ▶ | my $raw = $spec->{paths}{ $o->{path} }{ lc $o->{method} } || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$spec->{'paths'}{$o->{'path'}}{lc $o->{'method'}} || {}
MC/DC0%0/1
$spec->{'paths'}{$o->{'path'}}{lc $o->{'method'}} || {}
$spec->{'paths'}{$o->{'path'}}{lc $o->{'method'}}
Truth table50%1/2
A
A= $spec->{'paths'}{$o->{'path'}}{lc $o->{'method'}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | my $tname = (ref $raw->{tags} eq 'ARRAY' && @{ $raw->{tags} }) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 71 | ▶ | ? $raw->{tags}[0] : 'default'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $raw->{"tags"} eq "ARRAY" and @{$raw->{"tags"};}
MC/DC50%1/2
ref $raw->{"tags"} eq "ARRAY" and @{$raw->{"tags"};}
ref $raw->{"tags"} eq "ARRAY"
@{$raw->{"tags"};}
Truth table66%2/3
A and B
A= ref $raw->{"tags"} eq "ARRAY"B= @{$raw->{"tags"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 71 | ▶ | my $tag = $tag_by_name{$tname} ||= do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$tag_by_name{$tname} ||= do {
(my $slug = lc $tname) =~ s/[^a-z0-9]+/-/g;
$slug =~ s/\A-+|-+\z//g;
my $t = {"name", $tname, "slug", $slug || "default", "description_html", &$mdh($tag_desc{$tname}), "ops", []};
push @tags, $t;
$t
}
MC/DC0%0/2
$tag_by_name{$tname} ||= do {
(my $slug = lc $tname) =~ s/[^a-z0-9]+/-/g;
$slug =~ s/\A-+|-+\z//g;
my $t = {"name", $tname, "slug", $slug || "default", "description_html", &$mdh($tag_desc{$tname}), "ops", []};
push @tags, $t;
$t
}
$tag_by_name{$tname}
do {
(my $slug = lc $tname) =~ s/[^a-z0-9]+/-/g;
$slug =~ s/\A-+|-+\z//g;
my $t = {"name", $tname, "slug", $slug || "default", "description_html", &$mdh($tag_desc{$tname}), "ops", []};
push @tags, $t;
$t
}
Truth table66%2/3
A ||= B
A= $tag_by_name{$tname}B= do {
(my $slug = lc $tname) =~ s/[^a-z0-9]+/-/g;
$slug =~ s/\A-+|-+\z//g;
my $t = {"name", $tname, "slug", $slug || "default", "description_html", &$mdh($tag_desc{$tname}), "ops", []};
push @tags, $t;
$t
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 20 | (my $slug = lc $tname) =~ s/[^a-z0-9]+/-/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 20 | $slug =~ s/\A-+|-+\z//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | my $t = { name => $tname, slug => ($slug || 'default'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 20 | ▶ | description_html => $mdh->($tag_desc{$tname}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$slug || 'default'
MC/DC0%0/1
$slug || 'default'
$slug
Truth table50%1/2
A
A= $slug
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ops => [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 20 | push @tags, $t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 20 | $t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 71 | ▶ | push @{ $tag->{ops} }, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$raw->{"summary"} // ""
MC/DC0%0/1
$raw->{"summary"} // ""
$raw->{"summary"}
Truth table50%1/2
A
A= $raw->{"summary"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | id => $o->{operationId}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | method => uc $o->{method}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | method_lc => lc $o->{method}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | path => $o->{path}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | summary => $raw->{summary} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | deprecated => $raw->{deprecated} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 71 | description_html => $mdh->($raw->{description}), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | my @servers = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | { url => $_->{url} // '', description => $_->{description} // '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$_->{"url"} // ""
$_->{"description"} // ""
MC/DC0%0/1
$_->{"url"} // ""
$_->{"url"}
MC/DC0%0/1
$_->{"description"} // ""
$_->{"description"}
Truth table50%1/2
A
A= $_->{"url"}
Truth table50%1/2
A
A= $_->{"description"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 20 | ▶ | } grep { ref $_ eq 'HASH' } @{ $spec->{servers} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$spec->{'servers'} || []
MC/DC100%1/1
$spec->{'servers'} || []
$spec->{'servers'}
Truth table100%2/2
A
A= $spec->{'servers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 20 | my @schemes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 20 | ▶ | my $ss = ($spec->{components} || {})->{securitySchemes} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
+($spec->{'components'} || {})->{'securitySchemes'} || {}
$spec->{'components'} || {}
MC/DC100%1/1
+($spec->{'components'} || {})->{'securitySchemes'} || {}
$spec->{'components'}
Truth table100%2/2
A
A= $spec->{'components'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 20 | for my $name (sort keys %$ss) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $s = $ss->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | next unless ref $s eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $type = $s->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$s->{"type"} // ""
MC/DC0%0/1
$s->{"type"} // ""
$s->{"type"}
Truth table0%0/2
A
A= $s->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | my $label = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | $type eq 'apiKey' ? "apiKey in $s->{in} ($s->{name})" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | : $type eq 'http' ? "http " . ($s->{scheme} // '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/2
$s->{"scheme"} // ""
MC/DC0%0/1
$s->{"scheme"} // ""
$s->{"scheme"}
Truth table0%0/2
A
A= $s->{"scheme"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | : $type eq 'oauth2' ? 'oauth2 (paste a bearer token)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | : $type eq 'openIdConnect' ? 'openIdConnect (paste a bearer token)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | : $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | push @schemes, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | scheme => $s->{scheme} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | in => $s->{in} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | key => $s->{name} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$s->{"scheme"} // ""
$s->{"in"} // ""
$s->{"name"} // ""
MC/DC0%0/1
$s->{"scheme"} // ""
$s->{"scheme"}
MC/DC0%0/1
$s->{"in"} // ""
$s->{"in"}
MC/DC0%0/1
$s->{"name"} // ""
$s->{"name"}
Truth table0%0/2
A
A= $s->{"scheme"}
Truth table0%0/2
A
A= $s->{"in"}
Truth table0%0/2
A
A= $s->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | label => $label, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | my $config_json = File::Raw::JSON::file_json_encode({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | basePath => $self->{path}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | specPath => $self->{spec_path}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | tryIt => $self->{try_it} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 20 | ▶ | csrf => $self->{csrf} ? { %{ $self->{csrf} } } : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # The config rides inside a <script type="application/json"> block; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # a '<' in any value must never be able to close it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 20 | $config_json =~ s/</\\u003c/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | title => $self->{title} // $info->{title} // 'API', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | base => $self->{path}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | config_json => $config_json, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | info => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | title => $info->{title} // 'API', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | version => $info->{version} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 20 | ▶ | description_html => $mdh->($info->{description}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition55%5/9
($self->{"title"} // $info->{"title"}) // "API"
$self->{"title"} // $info->{"title"}
$info->{"title"} // "API"
$info->{"version"} // ""
MC/DC0%0/2
($self->{"title"} // $info->{"title"}) // "API"
$self->{"title"}
$info->{"title"}
MC/DC0%0/1
$info->{"title"} // "API"
$info->{"title"}
MC/DC0%0/1
$info->{"version"} // ""
$info->{"version"}
Truth table66%2/3
A // B
A= $self->{"title"}B= $info->{"title"}
Truth table50%1/2
A
A= $info->{"title"}
Truth table50%1/2
A
A= $info->{"version"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | servers => \@servers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | schemes => \@schemes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | tags => \@tags, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 20 | ▶ | sub _render { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_render: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 20 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 20 | my $stencil = Template::Stencil->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | template_dir => _base_dir() . '/templates', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | wrapper => 'wrapper.tmpl', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 20 | return $stencil->render('index', $self->_build_data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 17 | ▶ | sub index_html { $_[0]{html} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
index_html: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # The same page as a fragment, for a host page that already has a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # <head> of its own - a product page showing the docs for a spec | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # somebody just pasted, rather than a documentation site. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # It carries the config block, because app.js reads its settings from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # there and a fragment without it is inert. It does not carry the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # stylesheet or script tags: the host is serving those assets from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # wherever it serves assets, and only the host knows where that is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | sub embed_html { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
embed_html: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | return $self->{embed} if defined $self->{embed}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my $data = $self->_build_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $stencil = Template::Stencil->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | template_dir => _base_dir() . '/templates', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | return $self->{embed} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | qq{<script type="application/json" id="oa-config">} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | . $data->{config_json} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | . qq{</script>\n} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | . $stencil->render('index', $data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 13 | ▶ | sub spec_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spec_json: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | $self->{spec_json} //= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 13 | ▶ | File::Raw::JSON::file_json_encode($self->{api}->spec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"spec_json"} //= File::Raw::JSON::file_json_encode($self->{"api"}->spec)
MC/DC0%0/2
$self->{"spec_json"} //= File::Raw::JSON::file_json_encode($self->{"api"}->spec)
$self->{"spec_json"}
File::Raw::JSON::file_json_encode($self->{"api"}->spec)
Truth table33%1/3
A //= B
A= $self->{"spec_json"}B= File::Raw::JSON::file_json_encode($self->{"api"}->spec)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 26 | ▶ | sub asset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
asset: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 26 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 26 | ▶ | return unless defined $name && $ASSETS{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $name and $ASSETS{$name}
MC/DC50%1/2
defined $name and $ASSETS{$name}
defined $name
$ASSETS{$name}
Truth table66%2/3
A and B
A= defined $nameB= $ASSETS{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 24 | ▶ | unless (defined $self->{assets}{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 24 | my $file = _base_dir() . "/static/$name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 24 | ▶ | open my $fh, '<:raw', $file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | or Carp::croak("Open::API::UI: cannot read $file: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 24 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 24 | $self->{assets}{$name} = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 24 | return ($ASSETS{$name}, $self->{assets}{$name}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | ▶ | sub headers { [ @{ $_[0]{header_pairs} } ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
headers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 19 | ▶ | sub routes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
routes: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 19 | ▶ | return $self->{routes} if $self->{routes}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 11 | my $hdrs = $self->{header_pairs}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 44 | ▶ | my $static = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 44 | my ($ct, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 23 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 23 | [ 200, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | [ 'Content-Type' => $ct, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 'Content-Length' => length $bytes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | @$hdrs ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | [ $bytes ] ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 44 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 11 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 11 | my $html = $static->('text/html; charset=utf-8', $self->index_html); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 11 | my ($css_ct, $css) = $self->asset('app.css'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 11 | my ($js_ct, $js) = $self->asset('app.js'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 11 | my $p = $self->{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | return $self->{routes} = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | { method => 'GET', path => $p, response => $html }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | { method => 'GET', path => "$p/", response => $html }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | { method => 'GET', path => "$p/app.js", response => $static->($js_ct, $js) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | { method => 'GET', path => "$p/app.css", response => $static->($css_ct, $css) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | { method => 'GET', path => $self->{spec_path}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 11 | response => $static->('application/json', $self->spec_json) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 9 | ▶ | sub _table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_table: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 9 | return { map { $_->{path} => $_->{response} } @{ $self->routes } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | ▶ | sub to_app { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_app: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | my $table = $self->_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 4 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 4 | my $env = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 4 | ▶ | my $m = $env->{REQUEST_METHOD} || 'GET'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$env->{'REQUEST_METHOD'} || 'GET'
MC/DC0%0/1
$env->{'REQUEST_METHOD'} || 'GET'
$env->{'REQUEST_METHOD'}
Truth table50%1/2
A
A= $env->{'REQUEST_METHOD'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 4 | ▶ | if (($m eq 'GET' || $m eq 'HEAD') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition87%7/8
$m eq "GET" || $m eq "HEAD" and my $r = $$table{$env->{"PATH_INFO"} or "/"}
$m eq "GET" or $m eq "HEAD"
$env->{'PATH_INFO'} || '/'
MC/DC100%3/3
$m eq "GET" || $m eq "HEAD" and my $r = $$table{$env->{"PATH_INFO"} or "/"}
$m eq "GET"
$m eq "HEAD"
my $r = $$table{$env->{"PATH_INFO"} or "/"}
MC/DC0%0/1
$env->{'PATH_INFO'} || '/'
$env->{'PATH_INFO'}
Truth table80%4/5
A or B and C
A= $m eq "GET"B= $m eq "HEAD"C= my $r = $$table{$env->{"PATH_INFO"} or "/"}
Truth table50%1/2
A
A= $env->{'PATH_INFO'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | and my $r = $table->{ $env->{PATH_INFO} || '/' }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 2 | my $resp = $r->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 2 | ▶ | $resp->[2] = [''] if $m eq 'HEAD'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 2 | return $resp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 2 | return [ 404, [ 'Content-Type' => 'text/plain' ], ['Not Found'] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 9 | ▶ | sub _wrap_psgi { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap_psgi: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 9 | my ($plack, $app) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 9 | my $ui_opt = $plack->ui; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 9 | ▶ | my %opts = ref $ui_opt eq 'HASH' ? %$ui_opt : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 9 | ▶ | my $api = $plack->api | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | or Carp::croak("Open::API::UI: the Plack object has no api"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # The JS must speak the server's actual CSRF dialect, so the names come | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # from the Plack csrf option, never from ui options. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 9 | my $csrf = $plack->csrf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 9 | ▶ | if (ref $csrf eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | $opts{csrf} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | header => defined $csrf->{header} ? $csrf->{header} : 'X-CSRF-Token', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | ▶ | cookie => defined $csrf->{cookie} ? $csrf->{cookie} : 'csrf', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 8 | $opts{csrf} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 9 | my $ui = Open::API::UI->new(api => $api, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 9 | for my $r (@{ $ui->routes }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 41 | my @m = $api->match($r->{method}, $r->{path}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 41 | ▶ | next unless @m; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | ▶ | Carp::croak(defined $m[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ? "Open::API::UI: path '$r->{path}' is declared by spec " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | . "operation '$m[0]'; choose another ui path" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | : "Open::API::UI: path '$r->{path}' is declared by the spec; " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | . "choose another ui path"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 8 | my $table = $ui->_table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 20 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 20 | my $env = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 20 | ▶ | my $m = $env->{REQUEST_METHOD} || 'GET'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$env->{'REQUEST_METHOD'} || 'GET'
MC/DC0%0/1
$env->{'REQUEST_METHOD'} || 'GET'
$env->{'REQUEST_METHOD'}
Truth table50%1/2
A
A= $env->{'REQUEST_METHOD'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 20 | ▶ | if (($m eq 'GET' || $m eq 'HEAD') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition87%7/8
$m eq "GET" || $m eq "HEAD" and my $r = $$table{$env->{"PATH_INFO"} or "/"}
$m eq "GET" or $m eq "HEAD"
$env->{'PATH_INFO'} || '/'
MC/DC100%3/3
$m eq "GET" || $m eq "HEAD" and my $r = $$table{$env->{"PATH_INFO"} or "/"}
$m eq "GET"
$m eq "HEAD"
my $r = $$table{$env->{"PATH_INFO"} or "/"}
MC/DC0%0/1
$env->{'PATH_INFO'} || '/'
$env->{'PATH_INFO'}
Truth table80%4/5
A or B and C
A= $m eq "GET"B= $m eq "HEAD"C= my $r = $$table{$env->{"PATH_INFO"} or "/"}
Truth table50%1/2
A
A= $env->{'PATH_INFO'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | and my $r = $table->{ $env->{PATH_INFO} || '/' }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 14 | my $resp = $r->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 14 | ▶ | $resp->[2] = [''] if $m eq 'HEAD'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 14 | return $resp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 6 | return $app->($env); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||