« blib/lib/Amon2/Plugin/Web/FillInFormLite.pm
↑ Summary
blib/lib/auto/share/dist/Amon2/flavor/Basic/lib/__PATH__.pm »
| 1 | package Amon2::Web; | ||||||||||||||||||||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use Amon2::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use Amon2::Trigger qw/add_trigger call_trigger get_trigger_code/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use Encode (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Plack::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use URI::Escape (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Amon2::Web::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use Amon2::Web::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use Plack::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 15 | # Hook points: | ||||||||||||||||||||||||||||
| 16 | # You can override these methods. | ||||||||||||||||||||||||||||
| 17 | 4 | ▶ | sub create_request { Amon2::Web::Request->new($_[1], $_[0]) } | ||||||||||||||||||||||||||
|
Subroutine
create_request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 30 | ▶ | sub create_response { shift; Amon2::Web::Response->new(@_) } | ||||||||||||||||||||||||||
|
Subroutine
create_response: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub create_view { die "This is abstract method: create_view" } | ||||||||||||||||||||||||||
|
Subroutine
create_view: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub dispatch { die "This is abstract method: dispatch" } | ||||||||||||||||||||||||||
|
Subroutine
dispatch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub html_content_type { 'text/html; charset=UTF-8' } | ||||||||||||||||||||||||||
|
Subroutine
html_content_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 13 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 24 | 13 | ▶ | my $encoding = Encode::find_encoding('utf-8') || die; | ||||||||||||||||||||||||||
|
Condition50%1/2
&Encode::find_encoding('utf-8') || die()
MC/DC0%0/1
&Encode::find_encoding('utf-8') || die()
&Encode::find_encoding('utf-8')
Truth table50%1/2
A
A= &Encode::find_encoding('utf-8')
| |||||||||||||||||||||||||||||
| 25 | 26 | ▶ | sub encoding { $encoding } | ||||||||||||||||||||||||||
|
Subroutine
encoding: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub session { | ||||||||||||||||||||||||||
|
Subroutine
session: not called CC=2 SCAR=14.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $klass = ref $self || $self; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | require Plack::Session; | |||||||||||||||||||||||||||
| 33 | 13 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | *{"${klass}::session"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | $self->{session} ||= Plack::Session->new($self->request->env); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"session"} ||= "Plack::Session"->new($self->request->env)
MC/DC0%0/2
$self->{"session"} ||= "Plack::Session"->new($self->request->env)
$self->{"session"}
"Plack::Session"->new($self->request->env)
Truth table0%0/3
A ||= B
A= $self->{"session"}B= "Plack::Session"->new($self->request->env)
| |||||||||||||||||||||||||||||
| 37 | 0 | }; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | return $self->session(); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 43 | # Attributes: | ||||||||||||||||||||||||||||
| 44 | 21 | ▶ | sub request { $_[0]->{request} } | ||||||||||||||||||||||||||
|
Subroutine
request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 24 | ▶ | sub req { $_[0]->{request} } | ||||||||||||||||||||||||||
|
Subroutine
req: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 48 | # Methods: | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 9 | ▶ | sub redirect { | ||||||||||||||||||||||||||
|
Subroutine
redirect: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 9 | my ($self, $location, $params) = @_; | |||||||||||||||||||||||||||
| 52 | 9 | my $url = do { | |||||||||||||||||||||||||||
| 53 | 9 | ▶ | if ($location =~ m{^https?://}i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 7 | $location; | |||||||||||||||||||||||||||
| 55 | } else { | ||||||||||||||||||||||||||||
| 56 | 2 | my $url = $self->request->base; | |||||||||||||||||||||||||||
| 57 | 2 | $url =~ s{/+$}{}; | |||||||||||||||||||||||||||
| 58 | 2 | $location =~ s{^/+([^/])}{/$1}; | |||||||||||||||||||||||||||
| 59 | 2 | $url .= $location; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | }; | ||||||||||||||||||||||||||||
| 62 | 9 | ▶ | if (my $ref_params = ref $params) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 6 | ▶ | if ($ref_params eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 64 | 5 | my $uri = URI->new($url); | |||||||||||||||||||||||||||
| 65 | 5 | $uri->query_form($uri->query_form, map { Encode::encode($self->encoding, $_) } @$params); | |||||||||||||||||||||||||||
| 66 | 5 | $url = $uri->as_string; | |||||||||||||||||||||||||||
| 67 | } elsif ($ref_params eq 'HASH') { | ||||||||||||||||||||||||||||
| 68 | 1 | my @ary; | |||||||||||||||||||||||||||
| 69 | 1 | my $encoding = $self->encoding; | |||||||||||||||||||||||||||
| 70 | 1 | ▶ | while (my ($k, $v) = each %$params) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 1 | push @ary, Encode::encode($encoding, $k); | |||||||||||||||||||||||||||
| 72 | 1 | push @ary, Encode::encode($encoding, $v); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 1 | my $uri = URI->new($url); | |||||||||||||||||||||||||||
| 75 | 1 | $uri->query_form($uri->query_form, @ary); | |||||||||||||||||||||||||||
| 76 | 1 | $url = $uri->as_string; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 9 | return $self->create_response( | |||||||||||||||||||||||||||
| 80 | 302, | ||||||||||||||||||||||||||||
| 81 | ['Location' => $url], | ||||||||||||||||||||||||||||
| 82 | [] | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub create_simple_status_page { | ||||||||||||||||||||||||||
|
Subroutine
create_simple_status_page: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | my ($self, $code, $message) = @_; | |||||||||||||||||||||||||||
| 88 | 0 | my $codestr = Plack::Util::encode_html($code); | |||||||||||||||||||||||||||
| 89 | 0 | $message = Plack::Util::encode_html($message); | |||||||||||||||||||||||||||
| 90 | 0 | my $content = <<"..."; | |||||||||||||||||||||||||||
| 91 | <!doctype html> | ||||||||||||||||||||||||||||
| 92 | <html> | ||||||||||||||||||||||||||||
| 93 | <head> | ||||||||||||||||||||||||||||
| 94 | <meta charset=utf-8 /> | ||||||||||||||||||||||||||||
| 95 | <title>$codestr $message</title> | ||||||||||||||||||||||||||||
| 96 | <style type="text/css"> | ||||||||||||||||||||||||||||
| 97 | body { | ||||||||||||||||||||||||||||
| 98 | text-align: center; | ||||||||||||||||||||||||||||
| 99 | font-family: 'Menlo', 'Monaco', Courier, monospace; | ||||||||||||||||||||||||||||
| 100 | background-color: whitesmoke; | ||||||||||||||||||||||||||||
| 101 | padding-top: 10%; | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | .number { | ||||||||||||||||||||||||||||
| 104 | font-size: 800%; | ||||||||||||||||||||||||||||
| 105 | font-weight: bold; | ||||||||||||||||||||||||||||
| 106 | margin-bottom: 40px; | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | .message { | ||||||||||||||||||||||||||||
| 109 | font-size: 400%; | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | </style> | ||||||||||||||||||||||||||||
| 112 | </head> | ||||||||||||||||||||||||||||
| 113 | <body> | ||||||||||||||||||||||||||||
| 114 | <div class="number">$codestr</div> | ||||||||||||||||||||||||||||
| 115 | <div class="message">$message</div> | ||||||||||||||||||||||||||||
| 116 | </body> | ||||||||||||||||||||||||||||
| 117 | </html> | ||||||||||||||||||||||||||||
| 118 | ... | ||||||||||||||||||||||||||||
| 119 | 0 | $self->create_response( | |||||||||||||||||||||||||||
| 120 | $code, | ||||||||||||||||||||||||||||
| 121 | [ | ||||||||||||||||||||||||||||
| 122 | 'Content-Type' => 'text/html; charset=utf-8', | ||||||||||||||||||||||||||||
| 123 | 'Content-Length' => length($content), | ||||||||||||||||||||||||||||
| 124 | ], | ||||||||||||||||||||||||||||
| 125 | [$content] | ||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub res_403 { | ||||||||||||||||||||||||||
|
Subroutine
res_403: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 131 | 0 | return $self->create_simple_status_page(403, 'Forbidden'); | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub res_404 { | ||||||||||||||||||||||||||
|
Subroutine
res_404: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 136 | 0 | return $self->create_simple_status_page(404, 'File Not Found'); | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | sub res_405 { | ||||||||||||||||||||||||||
|
Subroutine
res_405: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 140 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 141 | 0 | return $self->create_simple_status_page(405, 'Method Not Allowed'); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub res_500 { | ||||||||||||||||||||||||||
|
Subroutine
res_500: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 146 | 0 | return $self->create_simple_status_page(500, 'Internal Server Error'); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 4 | ▶ | sub to_app { | ||||||||||||||||||||||||||
|
Subroutine
to_app: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | 4 | my ($class, ) = @_; | |||||||||||||||||||||||||||
| 151 | 4 | ▶ | return sub { $class->handle_request(shift) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 4 | ▶ | sub handle_request { | ||||||||||||||||||||||||||
|
Subroutine
handle_request: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 155 | 4 | my ($class, $env) = @_; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 4 | my $req = $class->create_request($env); | |||||||||||||||||||||||||||
| 158 | 4 | my $self = $class->new( | |||||||||||||||||||||||||||
| 159 | request => $req, | ||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||
| 161 | 4 | my $guard = $self->context_guard(); | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 4 | my $response; | |||||||||||||||||||||||||||
| 164 | 4 | for my $code ($self->get_trigger_code('BEFORE_DISPATCH')) { | |||||||||||||||||||||||||||
| 165 | 4 | $response = $code->($self); | |||||||||||||||||||||||||||
| 166 | 4 | ▶ | goto PROCESS_END if Scalar::Util::blessed($response) && $response->isa('Plack::Response'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($response) and $response->isa("Plack::Response")
MC/DC50%1/2
builtin::blessed($response) and $response->isa("Plack::Response")
builtin::blessed($response)
$response->isa("Plack::Response")
Truth table66%2/3
A and B
A= builtin::blessed($response)B= $response->isa("Plack::Response")
| |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 2 | ▶ | $response = $self->dispatch() or die "cannot get any response"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 4 | PROCESS_END: | |||||||||||||||||||||||||||
| 170 | $self->call_trigger('AFTER_DISPATCH' => $response); | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 4 | return $response->finalize; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 1 | ▶ | sub uri_for { | ||||||||||||||||||||||||||
|
Subroutine
uri_for: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 176 | 1 | my ($self, $path, $query) = @_; | |||||||||||||||||||||||||||
| 177 | 1 | ▶ | my $root = $self->req->{env}->{SCRIPT_NAME} || '/'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->req->{'env'}{'SCRIPT_NAME'} || '/'
MC/DC0%0/1
$self->req->{'env'}{'SCRIPT_NAME'} || '/'
$self->req->{'env'}{'SCRIPT_NAME'}
Truth table50%1/2
A
A= $self->req->{'env'}{'SCRIPT_NAME'}
| |||||||||||||||||||||||||||||
| 178 | 1 | $root =~ s{([^/])$}{$1/}; | |||||||||||||||||||||||||||
| 179 | 1 | $path =~ s{^/}{}; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 1 | my @q; | |||||||||||||||||||||||||||
| 182 | 1 | ▶ | while (my ($key, $val) = each %$query) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 1 | $val = URI::Escape::uri_escape(Encode::encode($self->encoding, $val)); | |||||||||||||||||||||||||||
| 184 | 1 | push @q, "${key}=${val}"; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | 1 | ▶ | $root . $path . (scalar @q ? '?' . join('&', @q) : ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub render { | ||||||||||||||||||||||||||
|
Subroutine
render: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 190 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 191 | 0 | my $html = $self->create_view()->render(@_); | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | for my $code ($self->get_trigger_code('HTML_FILTER')) { | |||||||||||||||||||||||||||
| 194 | 0 | $html = $code->($self, $html); | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | $html = $self->encode_html($html); | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | return $self->create_response( | |||||||||||||||||||||||||||
| 200 | 200, | ||||||||||||||||||||||||||||
| 201 | [ | ||||||||||||||||||||||||||||
| 202 | 'Content-Type' => $self->html_content_type, | ||||||||||||||||||||||||||||
| 203 | 'Content-Length' => length($html) | ||||||||||||||||||||||||||||
| 204 | ], | ||||||||||||||||||||||||||||
| 205 | $html, | ||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | # You can override this method on your application. | ||||||||||||||||||||||||||||
| 210 | 0 | ▶ | sub encode_html { | ||||||||||||||||||||||||||
|
Subroutine
encode_html: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 211 | 0 | my ($self, $html) = @_; | |||||||||||||||||||||||||||
| 212 | 0 | return Encode::encode($self->encoding, $html); | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 13 | 1; | |||||||||||||||||||||||||||
| 216 | __END__ | ||||||||||||||||||||||||||||