| 1 | package Kossy; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use 5.008004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Carp qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Cwd qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use File::Basename qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Text::Xslate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use HTML::FillInForm::Lite qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use Router::Boom; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | use Class::Accessor::Lite ( | ||||||||||||||||||||||||||||
| 16 | 7 | new => 0, | |||||||||||||||||||||||||||
| 17 | rw => [qw/root_dir/] | ||||||||||||||||||||||||||||
| 18 | 7 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use base qw/Exporter/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use Kossy::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use Kossy::Connection; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 7 | ▶ | use Kossy::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use Kossy::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 7 | ▶ | use HTTP::Headers::Fast; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 7 | our $VERSION = '0.50'; | |||||||||||||||||||||||||||
| 27 | 7 | our @EXPORT = qw/new root_dir psgi build_app _router _connect get post router filter _wrap_filter/; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 7 | our $XSLATE_CACHE = 1; | |||||||||||||||||||||||||||
| 30 | 7 | our $XSLATE_CACHE_DIR; | |||||||||||||||||||||||||||
| 31 | 7 | our $SECURITY_HEADER = 1; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # cache underscore translation | ||||||||||||||||||||||||||||
| 34 | 7 | HTTP::Headers::Fast::_standardize_field_name('X-Frame-Options'); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub new { | ||||||||||||||||||||||||||||
| 37 | 5 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 5 | my %args; | |||||||||||||||||||||||||||
| 39 | 5 | ▶ | if ( @_ < 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 2 | my $root_dir = shift; | |||||||||||||||||||||||||||
| 41 | 2 | my @caller = caller; | |||||||||||||||||||||||||||
| 42 | 2 | ▶ | $root_dir ||= File::Basename::dirname( Cwd::realpath($caller[1]) ); | ||||||||||||||||||||||||||
|
Condition66%2/3
$root_dir ||= File::Basename::dirname(Cwd::realpath($caller[1]))
MC/DC0%0/2
$root_dir ||= File::Basename::dirname(Cwd::realpath($caller[1]))
$root_dir
File::Basename::dirname(Cwd::realpath($caller[1]))
Truth table66%2/3
A ||= B
A= $root_dirB= File::Basename::dirname(Cwd::realpath($caller[1]))
| |||||||||||||||||||||||||||||
| 43 | 2 | $args{root_dir} = $root_dir; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | else { | ||||||||||||||||||||||||||||
| 46 | 3 | %args = @_; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 5 | bless \%args, $class; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | sub psgi { | ||||||||||||||||||||||||||||
| 53 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
psgi: called CC=4 SCAR=14.7
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | if ( ! ref $self ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 2 | my %args; | |||||||||||||||||||||||||||
| 56 | 2 | ▶ | if ( @_ < 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 2 | my $root_dir = shift; | |||||||||||||||||||||||||||
| 58 | 2 | my @caller = caller; | |||||||||||||||||||||||||||
| 59 | 2 | ▶ | $root_dir ||= File::Basename::dirname( Cwd::realpath($caller[1]) ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$root_dir ||= File::Basename::dirname(Cwd::realpath($caller[1]))
MC/DC0%0/2
$root_dir ||= File::Basename::dirname(Cwd::realpath($caller[1]))
$root_dir
File::Basename::dirname(Cwd::realpath($caller[1]))
Truth table33%1/3
A ||= B
A= $root_dirB= File::Basename::dirname(Cwd::realpath($caller[1]))
| |||||||||||||||||||||||||||||
| 60 | 2 | $args{root_dir} = $root_dir; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||
| 63 | 0 | %args = @_; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 2 | $self = $self->new(%args); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | $self->build_app; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub build_app { | ||||||||||||||||||||||||||||
| 72 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
build_app: called CC=3 SCAR=11.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | #router | ||||||||||||||||||||||||||||
| 75 | 2 | my $router = Router::Boom->new; | |||||||||||||||||||||||||||
| 76 | 2 | $router->add($_ => $self->_router->{$_} ) for keys %{$self->_router}; | |||||||||||||||||||||||||||
| 77 | 2 | my $xslate_cache_local = $XSLATE_CACHE; | |||||||||||||||||||||||||||
| 78 | 2 | my $xslate_cache_dir_local = $XSLATE_CACHE_DIR; | |||||||||||||||||||||||||||
| 79 | 2 | my $security_header_local = $SECURITY_HEADER; | |||||||||||||||||||||||||||
| 80 | 2 | my %match_cache; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | #xslate | ||||||||||||||||||||||||||||
| 83 | 2 | my $fif = HTML::FillInForm::Lite->new(); | |||||||||||||||||||||||||||
| 84 | my $tx = Text::Xslate->new( | ||||||||||||||||||||||||||||
| 85 | path => [ $self->root_dir . '/views' ], | ||||||||||||||||||||||||||||
| 86 | input_layer => ':utf8', | ||||||||||||||||||||||||||||
| 87 | module => ['Text::Xslate::Bridge::TT2Like','Number::Format' => [':subs']], | ||||||||||||||||||||||||||||
| 88 | function => { | ||||||||||||||||||||||||||||
| 89 | fillinform => sub { | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $q = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 91 | return sub { | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my ($html) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 93 | 0 | return Text::Xslate::mark_raw( $fif->fill( \$html, $q ) ); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 0 | } | |||||||||||||||||||||||||||
| 96 | }, | ||||||||||||||||||||||||||||
| 97 | 2 | ▶ | cache => $xslate_cache_local, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | defined $xslate_cache_dir_local ? ( cache_dir => $xslate_cache_dir_local ) : (), | ||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | sub { | ||||||||||||||||||||||||||||
| 102 | 18 | ▶ | my $env = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 103 | 18 | $Kossy::Response::SECURITY_HEADER = $security_header_local; | |||||||||||||||||||||||||||
| 104 | try { | ||||||||||||||||||||||||||||
| 105 | 18 | ▶ | my $header = bless { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.7
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 'content-type' => 'text/html; charset=UTF-8', | ||||||||||||||||||||||||||||
| 107 | $security_header_local ? ('x-frame-options' => 'DENY') : (), | ||||||||||||||||||||||||||||
| 108 | }, 'HTTP::Headers::Fast'; | ||||||||||||||||||||||||||||
| 109 | 18 | my $c = Kossy::Connection->new({ | |||||||||||||||||||||||||||
| 110 | tx => $tx, | ||||||||||||||||||||||||||||
| 111 | req => Kossy::Request->new($env), | ||||||||||||||||||||||||||||
| 112 | res => Kossy::Response->new(200, $header), | ||||||||||||||||||||||||||||
| 113 | stash => {}, | ||||||||||||||||||||||||||||
| 114 | }); | ||||||||||||||||||||||||||||
| 115 | 18 | my $method = uc($env->{REQUEST_METHOD}); | |||||||||||||||||||||||||||
| 116 | 18 | my $cache_key = $method . '-' . $env->{PATH_INFO}; | |||||||||||||||||||||||||||
| 117 | my ($match,$args) = try { | ||||||||||||||||||||||||||||
| 118 | 18 | ▶ | if ( exists $match_cache{$cache_key} ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 2 | return @{$match_cache{$cache_key}}; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 16 | my $path_info = Encode::decode_utf8( $env->{PATH_INFO}, Encode::FB_CROAK | Encode::LEAVE_SRC ); | |||||||||||||||||||||||||||
| 122 | 16 | my @match = $router->match($path_info); | |||||||||||||||||||||||||||
| 123 | 16 | ▶ | if ( !@match ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 2 | $c->halt(404); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 14 | ▶ | if ( !exists $match[0]->{$method}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 2 | $c->halt(405); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | $match_cache{$cache_key} = [$match[0]->{$method},$match[1]] | ||||||||||||||||||||||||||||
| 131 | 12 | ▶ | if ! scalar keys %{$match[1]}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 12 | return ($match[0]->{$method},$match[1]); | |||||||||||||||||||||||||||
| 133 | } catch { | ||||||||||||||||||||||||||||
| 134 | 4 | ▶ | if ( ref $_ && ref $_ eq 'Kossy::Exception' ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
Condition33%1/3
ref $_ and ref $_ eq "Kossy::Exception"
MC/DC0%0/2
ref $_ and ref $_ eq "Kossy::Exception"
ref $_
ref $_ eq "Kossy::Exception"
Truth table33%1/3
A and B
A= ref $_B= ref $_ eq "Kossy::Exception"
| |||||||||||||||||||||||||||||
| 135 | 4 | die $_; #rethrow | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 0 | $c->halt(400,'unexpected character in request'); | |||||||||||||||||||||||||||
| 138 | 18 | }; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 14 | my $code = $match->{__action__}; | |||||||||||||||||||||||||||
| 141 | 14 | ▶ | my $filters = $match->{__filter__} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$match->{'__filter__'} || []
MC/DC0%0/1
$match->{'__filter__'} || []
$match->{'__filter__'}
Truth table50%1/2
A
A= $match->{'__filter__'}
| |||||||||||||||||||||||||||||
| 142 | 14 | ▶ | if ( $] == 5.020000 || $] == 5.020100 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$] == "5.02" or $] == "5.0201"
MC/DC0%0/2
$] == "5.02" or $] == "5.0201"
$] == "5.02"
$] == "5.0201"
Truth table33%1/3
A or B
A= $] == "5.02"B= $] == "5.0201"
| |||||||||||||||||||||||||||||
| 143 | # workaround for 5.20.0 or 5.20.1 https://github.com/kazeburo/Kossy/pull/10 | ||||||||||||||||||||||||||||
| 144 | 0 | my %args = map { $_ => Encode::decode_utf8($args->{$_}) } keys %$args; | |||||||||||||||||||||||||||
| 145 | 0 | $c->args(\%args); | |||||||||||||||||||||||||||
| 146 | } else { | ||||||||||||||||||||||||||||
| 147 | 14 | $c->args({%$args}); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | my $app = sub { | ||||||||||||||||||||||||||||
| 150 | 14 | ▶ | my ($self, $c) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=20.9
| |||||||||||||||||||||||||||||
| 151 | 14 | my $response; | |||||||||||||||||||||||||||
| 152 | 14 | my $res = $code->($self, $c); | |||||||||||||||||||||||||||
| 153 | 14 | ▶ | Carp::croak "Undefined Response" if ! defined $res; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 14 | ▶ | my $res_t = ref($res) || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
ref $res || ''
MC/DC100%1/1
ref $res || ''
ref $res
Truth table100%2/2
A
A= ref $res
| |||||||||||||||||||||||||||||
| 155 | 14 | ▶ | if ( $res_t eq 'Kossy::Response' ) { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 156 | 1 | $response = $res; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | elsif ( $res_t eq 'Plack::Response' ) { | ||||||||||||||||||||||||||||
| 159 | 0 | $response = bless $res, 'Kossy::Response'; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | elsif ( $res_t eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 162 | 0 | $response = Kossy::Response->new(@$res); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | elsif ( !$res_t ) { | ||||||||||||||||||||||||||||
| 165 | 13 | $c->res->body($res); | |||||||||||||||||||||||||||
| 166 | 13 | $response = $c->res; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | else { | ||||||||||||||||||||||||||||
| 169 | 0 | Carp::croak sprintf "Unknown Response: %s", $res_t; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | 14 | $response; | |||||||||||||||||||||||||||
| 172 | 14 | }; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 14 | for my $filter ( reverse @$filters ) { | |||||||||||||||||||||||||||
| 175 | 0 | $app = $self->_wrap_filter($filter,$app); | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | # do all | ||||||||||||||||||||||||||||
| 178 | 14 | local $Kossy::Response::DIRECT; | |||||||||||||||||||||||||||
| 179 | 14 | $app->($self, $c)->finalize; | |||||||||||||||||||||||||||
| 180 | } catch { | ||||||||||||||||||||||||||||
| 181 | 4 | ▶ | if ( ref $_ && ref $_ eq 'Kossy::Exception' ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
Condition33%1/3
ref $_ and ref $_ eq "Kossy::Exception"
MC/DC0%0/2
ref $_ and ref $_ eq "Kossy::Exception"
ref $_
ref $_ eq "Kossy::Exception"
Truth table33%1/3
A and B
A= ref $_B= ref $_ eq "Kossy::Exception"
| |||||||||||||||||||||||||||||
| 182 | 4 | return $_->response; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | 0 | die $_; | |||||||||||||||||||||||||||
| 185 | 18 | }; | |||||||||||||||||||||||||||
| 186 | 2 | }; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 7 | my $_ROUTER={}; | |||||||||||||||||||||||||||
| 192 | sub _router { | ||||||||||||||||||||||||||||
| 193 | 71 | ▶ | my $klass = shift; | ||||||||||||||||||||||||||
|
Subroutine
_router: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 194 | 71 | ▶ | my $class = ref $klass ? ref $klass : $klass; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 71 | ▶ | if ( !$_ROUTER->{$class} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 3 | $_ROUTER->{$class} = {}; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | 71 | $_ROUTER->{$class}; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | sub _connect { | ||||||||||||||||||||||||||||
| 202 | 27 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
_connect: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 203 | 27 | my ( $methods, $pattern, $filter, $code ) = @_; | |||||||||||||||||||||||||||
| 204 | 27 | ▶ | $methods = ref($methods) ? $methods : [$methods]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 27 | ▶ | if (!$code) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 27 | $code = $filter; | |||||||||||||||||||||||||||
| 207 | 27 | $filter = []; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | 27 | for my $method ( @$methods ) { | |||||||||||||||||||||||||||
| 210 | 51 | $class->_router->{$pattern}->{$method} = { | |||||||||||||||||||||||||||
| 211 | __action__ => $code, | ||||||||||||||||||||||||||||
| 212 | __filter__ => $filter | ||||||||||||||||||||||||||||
| 213 | }; | ||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | sub get { | ||||||||||||||||||||||||||||
| 218 | 21 | ▶ | my $class = caller; | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 219 | 21 | $class->_connect( ['GET','HEAD'], @_ ); | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | sub post { | ||||||||||||||||||||||||||||
| 223 | 3 | ▶ | my $class = caller; | ||||||||||||||||||||||||||
|
Subroutine
post: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 224 | 3 | $class->_connect( ['POST'], @_ ); | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | sub router { | ||||||||||||||||||||||||||||
| 228 | 3 | ▶ | my $class = caller; | ||||||||||||||||||||||||||
|
Subroutine
router: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 229 | 3 | $class->_connect( @_ ); | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 7 | my $_FILTER={}; | |||||||||||||||||||||||||||
| 233 | sub filter { | ||||||||||||||||||||||||||||
| 234 | 0 | ▶ | my $class = caller; | ||||||||||||||||||||||||||
|
Subroutine
filter: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ( !$_FILTER->{$class} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 0 | $_FILTER->{$class} = {}; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | 0 | $_FILTER->{$class}->{$_[0]} = $_[1]; | |||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | 0 | $_FILTER->{$class}; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | sub _wrap_filter { | ||||||||||||||||||||||||||||
| 245 | 0 | ▶ | my $klass = shift; | ||||||||||||||||||||||||||
|
Subroutine
_wrap_filter: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 246 | 0 | ▶ | my $class = ref $klass ? ref $klass : $klass; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if ( !$_FILTER->{$class} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | 0 | $_FILTER->{$class} = {}; | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | 0 | my ($filter,$app) = @_; | |||||||||||||||||||||||||||
| 251 | 0 | my $filter_subref = $_FILTER->{$class}->{$filter}; | |||||||||||||||||||||||||||
| 252 | 0 | ▶ | Carp::croak sprintf("Filter:%s is not exists", $filter) unless $filter_subref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | 0 | return $filter_subref->($app); | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 7 | 1; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | __END__ | ||||||||||||||||||||||||||||