| 1 | package Mojolicious::Plugin::Ident; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 8 | ▶ | use v5.10; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 8 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 8 | ▶ | use AnyEvent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 8 | ▶ | use AnyEvent::Ident::Client; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 8 | ▶ | use Mojo::Exception; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 8 | ▶ | use Mojolicious::Plugin::Ident::Response; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | # ABSTRACT: Mojolicious plugin to interact with a remote ident service | ||||||||||||||||||||
| 13 | 8 | our $VERSION = '0.31'; # VERSION | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | sub register | ||||||||||||||||||||
| 17 | 7 | ▶ | { | ||||||||||||||||||
|
Subroutine
register: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 18 | 7 | my($self, $app, $conf) = @_; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 7 | Mojolicious::Plugin::Ident::Response->_setup; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 7 | ▶ | my $default_timeout = $conf->{timeout} // 2; | ||||||||||||||||||
|
Condition100%2/2
$conf->{"timeout"} // 2
MC/DC100%1/1
$conf->{"timeout"} // 2
$conf->{"timeout"}
Truth table100%2/2
A
A= $conf->{"timeout"}
| |||||||||||||||||||||
| 23 | 7 | ▶ | my $port = $conf->{port} // 113; | ||||||||||||||||||
|
Condition50%1/2
$conf->{"port"} // 113
MC/DC0%0/1
$conf->{"port"} // 113
$conf->{"port"}
Truth table50%1/2
A
A= $conf->{"port"}
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 13 | ▶ | $app->helper(ident => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||
| 26 | 13 | my $callback; | |||||||||||||||||||
| 27 | 13 | ▶ | $callback = pop if ref($_[-1]) eq 'CODE'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 13 | my($controller, $tx, $timeout) = @_; | |||||||||||||||||||
| 29 | 13 | ▶ | $tx //= $controller->tx; | ||||||||||||||||||
|
Condition66%2/3
$tx //= $controller->tx
MC/DC0%0/2
$tx //= $controller->tx
$tx
$controller->tx
Truth table66%2/3
A //= B
A= $txB= $controller->tx
| |||||||||||||||||||||
| 30 | 13 | ▶ | $timeout //= $default_timeout; | ||||||||||||||||||
|
Condition66%2/3
$timeout //= $default_timeout
MC/DC0%0/2
$timeout //= $default_timeout
$timeout
$default_timeout
Truth table66%2/3
A //= B
A= $timeoutB= $default_timeout
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 13 | ▶ | if($callback) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | { | ||||||||||||||||||||
| 34 | AnyEvent::Ident::Client | ||||||||||||||||||||
| 35 | ->new( response_class => 'Mojolicious::Plugin::Ident::Response', hostname => $tx->remote_address, port => $port ) | ||||||||||||||||||||
| 36 | 7 | ▶ | ->ident($tx->remote_port, $tx->local_port, sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | 7 | my $ident_response = shift; | |||||||||||||||||||
| 38 | 7 | $ident_response->{remote_address} = $tx->remote_address; | |||||||||||||||||||
| 39 | 7 | $callback->($ident_response) | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | 7 | ); | |||||||||||||||||||
| 42 | 7 | return; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 6 | my $done = AnyEvent->condvar; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 1 | ▶ | my $w = AnyEvent->timer(after => $timeout // $default_timeout, cb => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 48 | 1 | $done->croak("ident timeout"); | |||||||||||||||||||
| 49 | 6 | ▶ | }); | ||||||||||||||||||
|
Condition33%1/3
$timeout // $default_timeout
MC/DC0%0/2
$timeout // $default_timeout
$timeout
$default_timeout
Truth table33%1/3
A // B
A= $timeoutB= $default_timeout
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 6 | my $ident_response; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | AnyEvent::Ident::Client | ||||||||||||||||||||
| 54 | ->new( response_class => 'Mojolicious::Plugin::Ident::Response', hostname => $tx->remote_address, port => $port ) | ||||||||||||||||||||
| 55 | 5 | ▶ | ->ident($tx->remote_port, $tx->local_port, sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 56 | 5 | $ident_response = shift; | |||||||||||||||||||
| 57 | 5 | $ident_response->{remote_address} = $tx->remote_address; | |||||||||||||||||||
| 58 | 5 | $done->send(1); | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | 6 | ); | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 6 | $done->recv; | |||||||||||||||||||
| 63 | 5 | undef $w; | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 5 | ▶ | if($ident_response->is_success) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | { | ||||||||||||||||||||
| 67 | 3 | return $ident_response; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | else | ||||||||||||||||||||
| 70 | { | ||||||||||||||||||||
| 71 | 2 | my $error = 'ident error: ' . $ident_response->error_type; | |||||||||||||||||||
| 72 | 2 | $controller->app->log->error($error); | |||||||||||||||||||
| 73 | 2 | die Mojo::Exception->new($error); | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | 7 | }); | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 15 | ▶ | $app->helper(ident_same_user => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.9
| |||||||||||||||||||||
| 78 | 15 | my $callback; | |||||||||||||||||||
| 79 | 15 | ▶ | $callback = pop if ref($_[-1]) eq 'CODE'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | 15 | my $controller = shift; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 15 | ▶ | if($callback) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | { | ||||||||||||||||||||
| 84 | 10 | my($tx, $timeout) = @_; | |||||||||||||||||||
| 85 | 10 | ▶ | $tx //= $controller->tx; | ||||||||||||||||||
|
Condition33%1/3
$tx //= $controller->tx
MC/DC0%0/2
$tx //= $controller->tx
$tx
$controller->tx
Truth table33%1/3
A //= B
A= $txB= $controller->tx
| |||||||||||||||||||||
| 86 | 10 | ▶ | $timeout //= $default_timeout; | ||||||||||||||||||
|
Condition33%1/3
$timeout //= $default_timeout
MC/DC0%0/2
$timeout //= $default_timeout
$timeout
$default_timeout
Truth table33%1/3
A //= B
A= $timeoutB= $default_timeout
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 10 | ▶ | if(defined $controller->session('ident_same_user')) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | { | ||||||||||||||||||||
| 90 | 4 | ▶ | Mojo::IOLoop->timer(0 => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 91 | 4 | $callback->($controller->session('ident_same_user')); | |||||||||||||||||||
| 92 | 4 | }); | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | else | ||||||||||||||||||||
| 95 | { | ||||||||||||||||||||
| 96 | 6 | ▶ | $controller->ident($tx, $timeout, sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 97 | 6 | my $res = shift; | |||||||||||||||||||
| 98 | 6 | ▶ | if($res->is_success) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | { | ||||||||||||||||||||
| 100 | 4 | my $same_user = $res->same_user; | |||||||||||||||||||
| 101 | 4 | $controller->session('ident_same_user' => $same_user); | |||||||||||||||||||
| 102 | 4 | $callback->($same_user); | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | else | ||||||||||||||||||||
| 105 | { | ||||||||||||||||||||
| 106 | 2 | $callback->(0); | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | 6 | }); | |||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | else | ||||||||||||||||||||
| 112 | { | ||||||||||||||||||||
| 113 | 5 | ▶ | $controller->session('ident_same_user') // do { | ||||||||||||||||||
|
Condition100%3/3
$controller->session("ident_same_user") // do {
my $same_user = eval {
do {
$controller->ident(@_)->same_user
}
};
return if $@;
$controller->session("ident_same_user", $same_user);
$same_user
}
MC/DC0%0/2
$controller->session("ident_same_user") // do {
my $same_user = eval {
do {
$controller->ident(@_)->same_user
}
};
return if $@;
$controller->session("ident_same_user", $same_user);
$same_user
}
$controller->session("ident_same_user")
do {
my $same_user = eval {
do {
$controller->ident(@_)->same_user
}
};
return if $@;
$controller->session("ident_same_user", $same_user);
$same_user
}
Truth table66%2/3
A // B
A= $controller->session("ident_same_user")B= do {
my $same_user = eval {
do {
$controller->ident(@_)->same_user
}
};
return if $@;
$controller->session("ident_same_user", $same_user);
$same_user
}
| |||||||||||||||||||||
| 114 | 3 | my $same_user = eval { $controller->ident(@_)->same_user }; | |||||||||||||||||||
| 115 | 3 | ▶ | return if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | 2 | $controller->session('ident_same_user' => $same_user); | |||||||||||||||||||
| 117 | 2 | $same_user; | |||||||||||||||||||
| 118 | }; | ||||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | 7 | }); | |||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 8 | 1; | |||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||