| 1 | package Mojolicious::Plugin::Narada; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = 'v1.0.1'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use MojoX::Log::Fast; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Narada::Config qw( get_config get_config_line ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Narada::Lock qw( unlock ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Scalar::Util qw( weaken ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | my ($Log, $Ident); | |||||||||||||||||||||||||||
| 13 | 2 | our $IN_CB = 0; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ($self, $app, $conf) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | $Log = MojoX::Log::Fast->new($conf->{log}); | |||||||||||||||||||||||||||
| 20 | 0 | $Ident = $Log->ident(); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # Replace default logger with Log::Fast. | ||||||||||||||||||||||||||||
| 23 | 0 | $app->log($Log); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # Load Mojo-specific config files. | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ($app->can('secrets')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | $app->secrets([split /\n/ms, get_config('cookie.secret')]); | |||||||||||||||||||||||||||
| 28 | } else { | ||||||||||||||||||||||||||||
| 29 | 0 | $app->secret(get_config_line('cookie.secret')); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 0 | $app->config(hypnotoad => { | |||||||||||||||||||||||||||
| 32 | listen => [split /\n/ms, get_config('hypnotoad/listen')], | ||||||||||||||||||||||||||||
| 33 | proxy => get_config_line('hypnotoad/proxy'), | ||||||||||||||||||||||||||||
| 34 | accepts => get_config_line('hypnotoad/accepts'), | ||||||||||||||||||||||||||||
| 35 | workers => get_config_line('hypnotoad/workers'), | ||||||||||||||||||||||||||||
| 36 | pid_file => 'var/hypnotoad.pid', | ||||||||||||||||||||||||||||
| 37 | }); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # * Fix url->path and url->base->path. | ||||||||||||||||||||||||||||
| 40 | # * Set correct ident while handler runs. | ||||||||||||||||||||||||||||
| 41 | # * unlock() if handler died. | ||||||||||||||||||||||||||||
| 42 | 0 | my $realbase = Mojo::Path->new( get_config_line('basepath') ) | |||||||||||||||||||||||||||
| 43 | ->trailing_slash(0) | ||||||||||||||||||||||||||||
| 44 | ->leading_slash(1) | ||||||||||||||||||||||||||||
| 45 | ->to_string; | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $app->hook(around_dispatch => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 47 | 0 | my ($next, $c) = @_; | |||||||||||||||||||||||||||
| 48 | 0 | my $url = $c->req->url; | |||||||||||||||||||||||||||
| 49 | 0 | my $base = $url->base->path; | |||||||||||||||||||||||||||
| 50 | 0 | my $path = $url->path; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($base eq q{} && $path =~ m{\A\Q$realbase\E(.*)\z}mso) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$base eq "" and $path =~ /\A\Q$realbase\E(.*)\z/mosu
MC/DC0%0/2
$base eq "" and $path =~ /\A\Q$realbase\E(.*)\z/mosu
$base eq ""
$path =~ /\A\Q$realbase\E(.*)\z/mosu
Truth table0%0/3
A and B
A= $base eq ""B= $path =~ /\A\Q$realbase\E(.*)\z/mosu
| |||||||||||||||||||||||||||||
| 52 | 0 | $path->parse($1); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | $base->parse($realbase); | |||||||||||||||||||||||||||
| 55 | 0 | $path->leading_slash(1); | |||||||||||||||||||||||||||
| 56 | 0 | $Log->ident($url->path); | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $err = eval { $next->(); 1 } ? undef : $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | unlock(); | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | die $err if defined $err; ## no critic(RequireCarping) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | }); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $app->helper(proxy => sub { return _proxy(0, @_) }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $app->helper(weak_proxy => sub { return _proxy(1, @_) }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | return; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub _proxy { | ||||||||||||||||||||||||||
|
Subroutine
_proxy: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 69 | 0 | my ($is_weak, $this, $cb, @p) = @_; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($is_weak) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | weaken($this); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 0 | my $is_global_cb= ref $this eq 'Mojolicious::Controller'; | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | my $ident = $is_global_cb ? $Ident : $Log->ident; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | my $__warn__ = $SIG{__WARN__}; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return if !$this; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | my $cur_ident = $Log->ident($ident); | |||||||||||||||||||||||||||
| 79 | 0 | local $SIG{__WARN__} = $__warn__; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | my $err = eval { local $IN_CB=1; $cb->($this, @p, @_); 1 } ? undef : $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if (defined $err) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $Log->ident($ident); | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | if (!$IN_CB) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | unlock() | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($is_global_cb || $is_weak) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$is_global_cb or $is_weak
MC/DC0%0/2
$is_global_cb or $is_weak
$is_global_cb
$is_weak
Truth table0%0/3
A or B
A= $is_global_cbB= $is_weak
| |||||||||||||||||||||||||||||
| 87 | 0 | die $err; ## no critic(RequireCarping) | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||
| 90 | 0 | $this->reply->exception($err); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 0 | $Log->ident($cur_ident); | |||||||||||||||||||||||||||
| 94 | 0 | }; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 2 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||