| 1 | package POE::Component::Server::JSONUnix::BlockingClient; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Socket qw(SOCK_STREAM); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use IO::Socket::UNIX (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use IO::Select (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use File::Temp 0.2310 (); # 0.2310 for tempfile's PERMS option | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use JSON::MaybeXS (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | our $VERSION = '0.2.0'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | POE::Component::Server::JSONUnix::BlockingClient - simple blocking (non-POE) client for POE::Component::Server::JSONUnix | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | use POE::Component::Server::JSONUnix::BlockingClient; | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | my $client = POE::Component::Server::JSONUnix::BlockingClient->new( | ||||||||||||||||||||||||||||||||||||||||||
| 25 | socket_path => '/tmp/app.sock', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | my $auth = $client->authenticate; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | die $auth->{error} if $auth->{status} ne 'ok'; | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | my $response = $client->call( | ||||||||||||||||||||||||||||||||||||||||||
| 32 | command => 'add', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | args => { numbers => [ 1, 2, 3 ] }, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | die $response->{error} if $response->{status} ne 'ok'; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | print "sum is $response->{result}{sum}\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | $client->disconnect; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | A minimal synchronous client for L<POE::Component::Server::JSONUnix>. Unlike | ||||||||||||||||||||||||||||||||||||||||||
| 43 | L<POE::Component::Server::JSONUnix::Client> it does not use POE at all: each | ||||||||||||||||||||||||||||||||||||||||||
| 44 | L</call> writes one newline-delimited JSON request to the server's Unix domain | ||||||||||||||||||||||||||||||||||||||||||
| 45 | socket and blocks until the matching response arrives (or a timeout expires). | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | This is the right tool for command-line utilities, cron jobs, and other | ||||||||||||||||||||||||||||||||||||||||||
| 48 | plain-procedural programs that just want to ask a running daemon a question. | ||||||||||||||||||||||||||||||||||||||||||
| 49 | If you need concurrent requests, callbacks, or to live inside an event loop, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | use the POE client instead. | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | It also knows how to complete the server's Unix-ownership authentication | ||||||||||||||||||||||||||||||||||||||||||
| 53 | challenge (see L</authenticate>). | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | my $client = POE::Component::Server::JSONUnix::BlockingClient->new(%args); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | Creates the client and (by default) connects. Recognised arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =head3 socket_path | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | Required. Filesystem path of the server's Unix domain socket. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | =head3 auto_connect | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | Connect immediately from C<new>, croaking on failure. Defaults to true. When | ||||||||||||||||||||||||||||||||||||||||||
| 70 | false, call L</connect> yourself. | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | =head3 timeout | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | Default per-request timeout in seconds (fractional values are fine). A | ||||||||||||||||||||||||||||||||||||||||||
| 75 | request that receives no response in time returns | ||||||||||||||||||||||||||||||||||||||||||
| 76 | C<< {status => 'error', error => 'request timed out'} >>. No timeout by | ||||||||||||||||||||||||||||||||||||||||||
| 77 | default: L</call> blocks until the server answers or hangs up. Can be | ||||||||||||||||||||||||||||||||||||||||||
| 78 | overridden per request. | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | =head3 on_notice | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | Code reference called as C<< $cb->($client, $response) >> for any server | ||||||||||||||||||||||||||||||||||||||||||
| 83 | message that cannot be matched to the request currently being waited on: a | ||||||||||||||||||||||||||||||||||||||||||
| 84 | message with no C<id>, or one whose C<id> is not the awaited one (most | ||||||||||||||||||||||||||||||||||||||||||
| 85 | notably a response arriving I<after> its request already timed out locally). | ||||||||||||||||||||||||||||||||||||||||||
| 86 | Unmatched messages are dropped silently if this is not set. | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 7 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | my $path = delete $args{socket_path} | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 7 | ▶ | or croak "new() requires a 'socket_path' argument"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | socket_path => $path, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | timeout => delete $args{timeout}, # seconds (optional) | ||||||||||||||||||||||||||||||||||||||||||
| 99 | on_notice => delete $args{on_notice}, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 7 | json => JSON::MaybeXS->new( | |||||||||||||||||||||||||||||||||||||||||
| 101 | utf8 => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | canonical => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | allow_nonref => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 105 | next_request_id => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | socket => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 107 | read_buffer => '', | ||||||||||||||||||||||||||||||||||||||||||
| 108 | auth => undef, # {uid, username} after a successful handshake | ||||||||||||||||||||||||||||||||||||||||||
| 109 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 7 | ▶ | my $auto_connect = ( delete $args{auto_connect} ) // 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{"auto_connect"} // 1
MC/DC0%0/1
delete $args{"auto_connect"} // 1
delete $args{"auto_connect"}
Truth table50%1/2
A
A= delete $args{"auto_connect"}
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 7 | ▶ | $self->connect if $auto_connect; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } ## end sub new | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | =head2 connect | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | $client->connect; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | Connect to the server. A no-op if already connected. Croaks if the connection | ||||||||||||||||||||||||||||||||||||||||||
| 124 | cannot be made. Returns the client object. May be called again after a | ||||||||||||||||||||||||||||||||||||||||||
| 125 | disconnect. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 8 | ▶ | sub connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | ▶ | return $self if $self->{socket}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | my $socket = IO::Socket::UNIX->new( | ||||||||||||||||||||||||||||||||||||||||||
| 135 | Type => SOCK_STREAM, | ||||||||||||||||||||||||||||||||||||||||||
| 136 | Peer => $self->{socket_path}, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 8 | ▶ | ) or croak "cannot connect to '$self->{socket_path}': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | $socket->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 7 | $self->{socket} = $socket; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 7 | $self->{read_buffer} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } ## end sub connect | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =head2 disconnect | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | $client->disconnect; | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | Close the connection. A no-op if not connected. Authentication state lives on | ||||||||||||||||||||||||||||||||||||||||||
| 150 | the connection, so it is cleared here; after a reconnect the handshake must be | ||||||||||||||||||||||||||||||||||||||||||
| 151 | performed again. | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | ▶ | sub disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 4 | ▶ | close delete $self->{socket} if $self->{socket}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | $self->{read_buffer} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 4 | $self->{auth} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | =head2 call | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | my $response = $client->call( | ||||||||||||||||||||||||||||||||||||||||||
| 166 | command => 'add', | ||||||||||||||||||||||||||||||||||||||||||
| 167 | args => { numbers => [ 1, 2, 3 ] }, | ||||||||||||||||||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | Send a request and block until its response arrives. Returns the full decoded | ||||||||||||||||||||||||||||||||||||||||||
| 171 | response envelope, e.g. C<< {id => 7, status => 'ok', result => {...}} >>. | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | Failures are reported in-band, as C<< {status => 'error', error => ...} >> | ||||||||||||||||||||||||||||||||||||||||||
| 174 | envelopes just as server-side errors are -- a timeout, a connection that is | ||||||||||||||||||||||||||||||||||||||||||
| 175 | (or comes) down mid-request, or an unserialisable request all produce one, so | ||||||||||||||||||||||||||||||||||||||||||
| 176 | checking C<< $response->{status} >> covers everything. Note that a timeout is | ||||||||||||||||||||||||||||||||||||||||||
| 177 | a local judgement only: the server may still be working on the request, and | ||||||||||||||||||||||||||||||||||||||||||
| 178 | its late response is routed to C<on_notice> (or dropped) when it eventually | ||||||||||||||||||||||||||||||||||||||||||
| 179 | arrives during a later C<call>. | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | Croaks only on usage errors (a missing C<command>). | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | Arguments: | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | =head3 command | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | Required. The command name. C<cmd> is accepted as an alias. | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | =head3 args | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | Arbitrary payload for the command's handler. | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | =head3 timeout | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | Per-request timeout in seconds, overriding the constructor's C<timeout>. | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 49 | ▶ | sub call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=17 SCAR=31.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 49 | my ( $self, %req ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 49 | ▶ | my $command = delete $req{command} // delete $req{cmd}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
delete $req{"command"} // delete $req{"cmd"}
MC/DC0%0/2
delete $req{"command"} // delete $req{"cmd"}
delete $req{"command"}
delete $req{"cmd"}
Truth table66%2/3
A // B
A= delete $req{"command"}B= delete $req{"cmd"}
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 49 | ▶ | croak "call() requires a 'command' argument" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | unless defined $command; | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 49 | my $args = delete $req{args}; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 49 | ▶ | my $timeout = ( delete $req{timeout} ) // $self->{timeout}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
delete $req{"timeout"} // $self->{"timeout"}
MC/DC0%0/2
delete $req{"timeout"} // $self->{"timeout"}
delete $req{"timeout"}
$self->{"timeout"}
Truth table66%2/3
A // B
A= delete $req{"timeout"}B= $self->{"timeout"}
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 49 | my $request_id = $self->{next_request_id}++; | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 49 | ▶ | unless ( $self->{socket} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | return { status => 'error', error => 'not connected', id => $request_id }; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 48 | my $json = eval { | |||||||||||||||||||||||||||||||||||||||||
| 216 | $self->{json}->encode( | ||||||||||||||||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 48 | ▶ | command => $command, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | id => $request_id, | ||||||||||||||||||||||||||||||||||||||||||
| 220 | ( defined $args ? ( args => $args ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 223 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 48 | ▶ | unless ( defined $json ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | status => 'error', | |||||||||||||||||||||||||||||||||||||||||
| 227 | error => 'request could not be serialised as JSON', | ||||||||||||||||||||||||||||||||||||||||||
| 228 | id => $request_id, | ||||||||||||||||||||||||||||||||||||||||||
| 229 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 48 | ▶ | unless ( print { $self->{socket} } $json, "\n" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my $error = "could not send request: $!"; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return { status => 'error', error => $error, id => $request_id }; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 48 | ▶ | my $deadline = defined $timeout ? time() + $timeout : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 48 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 241 | 49 | my $line = $self->_read_line($deadline); | |||||||||||||||||||||||||||||||||||||||||
| 242 | 49 | ▶ | unless ( defined $line ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | my $error = delete $self->{read_error}; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | ▶ | if ( $error eq 'timeout' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | return { status => 'error', error => 'request timed out', id => $request_id }; | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | return { status => 'error', error => $error, id => $request_id }; | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 47 | ▶ | next unless $line =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 47 | my $response; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 47 | ▶ | unless ( eval { $response = $self->{json}->decode($line); 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
eval {
do {
$response = $self->{"json"}->decode($line);
1
}
} and ref $response eq "HASH"
MC/DC0%0/2
eval {
do {
$response = $self->{"json"}->decode($line);
1
}
} and ref $response eq "HASH"
eval {
do {
$response = $self->{"json"}->decode($line);
1
}
}
ref $response eq "HASH"
Truth table33%1/3
A and B
A= eval {
do {
$response = $self->{"json"}->decode($line);
1
}
}B= ref $response eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | && ref $response eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||
| 256 | { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | # Unparsable server output cannot be correlated to anything; | ||||||||||||||||||||||||||||||||||||||||||
| 258 | # treat it like an id-less message. | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | return $response | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 47 | ▶ | if defined $response->{id} && $response->{id} eq $request_id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $response->{"id"} and $response->{"id"} eq $request_id
MC/DC50%1/2
defined $response->{"id"} and $response->{"id"} eq $request_id
defined $response->{"id"}
$response->{"id"} eq $request_id
Truth table66%2/3
A and B
A= defined $response->{"id"}B= $response->{"id"} eq $request_id
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | # No id, or an id we are not waiting on (e.g. a response that arrived | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # after its request already timed out). | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | ▶ | $self->{on_notice}->( $self, $response ) if $self->{on_notice}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | } ## end while (1) | ||||||||||||||||||||||||||||||||||||||||||
| 269 | } ## end sub call | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | # Return the next newline-terminated line from the socket (without its | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # newline), or undef with $self->{read_error} set to 'timeout', 'server | ||||||||||||||||||||||||||||||||||||||||||
| 273 | # closed connection', or a read error description. | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 49 | ▶ | sub _read_line { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_line: called CC=7 SCAR=20.7
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 49 | my ( $self, $deadline ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 49 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 278 | 96 | ▶ | return $1 if $self->{read_buffer} =~ s/\A(.*?)\n//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 49 | ▶ | if ( defined $deadline ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 49 | my $remaining = $deadline - time(); | |||||||||||||||||||||||||||||||||||||||||
| 282 | 49 | ▶ | if ( $remaining <= 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$remaining <= 0 or not "IO::Select"->new($self->{"socket"})->can_read($remaining)
MC/DC50%1/2
$remaining <= 0 or not "IO::Select"->new($self->{"socket"})->can_read($remaining)
$remaining <= 0
not "IO::Select"->new($self->{"socket"})->can_read($remaining)
Truth table66%2/3
A or not(B)
A= $remaining <= 0B= not "IO::Select"->new($self->{"socket"})->can_read($remaining)
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | || !IO::Select->new( $self->{socket} )->can_read($remaining) ) | ||||||||||||||||||||||||||||||||||||||||||
| 284 | { | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 2 | $self->{read_error} = 'timeout'; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 47 | my $read = sysread( $self->{socket}, my $chunk, 65536 ); | |||||||||||||||||||||||||||||||||||||||||
| 291 | 47 | ▶ | unless ($read) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | $self->{read_error} = | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | defined $read | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | ? 'server closed connection' | ||||||||||||||||||||||||||||||||||||||||||
| 295 | : "read error: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 47 | $self->{read_buffer} .= $chunk; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } ## end while (1) | ||||||||||||||||||||||||||||||||||||||||||
| 300 | } ## end sub _read_line | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | =head2 authenticate | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | my $response = $client->authenticate; | ||||||||||||||||||||||||||||||||||||||||||
| 305 | die $response->{error} if $response->{status} ne 'ok'; | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | Authenticate to the server. If the server advertises kernel peer-credential | ||||||||||||||||||||||||||||||||||||||||||
| 308 | authentication (C<< peercred => 1 >> in its C<auth_start> reply), this calls | ||||||||||||||||||||||||||||||||||||||||||
| 309 | C<auth_verify> with no arguments -- no file is created, the OS proves the UID. | ||||||||||||||||||||||||||||||||||||||||||
| 310 | Otherwise it performs the Unix-ownership challenge: call C<auth_start>, write | ||||||||||||||||||||||||||||||||||||||||||
| 311 | the returned cookie to a fresh file in the server's C<temp_dir> (the OS stamps | ||||||||||||||||||||||||||||||||||||||||||
| 312 | the file with this process's effective UID, which is the proof the server | ||||||||||||||||||||||||||||||||||||||||||
| 313 | checks), then call C<auth_verify> and clean the file up. See | ||||||||||||||||||||||||||||||||||||||||||
| 314 | L<POE::Component::Server::JSONUnix/"KERNEL PEER-CREDENTIAL AUTHENTICATION">. | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | Accepts an optional C<timeout>, applied to each of the two requests. Returns | ||||||||||||||||||||||||||||||||||||||||||
| 317 | the C<auth_verify> response envelope on success, or a synthesised | ||||||||||||||||||||||||||||||||||||||||||
| 318 | C<< {status => 'error', ...} >> envelope if any step fails. After success, | ||||||||||||||||||||||||||||||||||||||||||
| 319 | L</authenticated>, L</uid> and L</username> reflect the verified identity. | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 4 | ▶ | sub authenticate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authenticate: called CC=21 SCAR=52.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 4 | my ( $self, %opt ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 4 | my $timeout = delete $opt{timeout}; | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 4 | ▶ | my $challenge = $self->call( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | command => 'auth_start', | ||||||||||||||||||||||||||||||||||||||||||
| 330 | ( defined $timeout ? ( timeout => $timeout ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 331 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 4 | ▶ | unless ( ( $challenge->{status} // '' ) eq 'ok' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$challenge->{"status"} // ""
MC/DC0%0/1
$challenge->{"status"} // ""
$challenge->{"status"}
Truth table50%1/2
A
A= $challenge->{"status"}
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 334 | status => 'error', | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | error => 'auth_start failed: ' . ( $challenge->{error} // 'unknown error' ), | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$challenge->{"error"} // "unknown error"
MC/DC0%0/1
$challenge->{"error"} // "unknown error"
$challenge->{"error"}
Truth table0%0/2
A
A= $challenge->{"error"}
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | # When the server advertises kernel peer-credential auth, skip the file | ||||||||||||||||||||||||||||||||||||||||||
| 340 | # entirely: the uid is proven by the OS, so auth_verify needs no path. | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 4 | ▶ | if ( $challenge->{result}{peercred} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 4 | ▶ | my $verdict = $self->call( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | command => 'auth_verify', | ||||||||||||||||||||||||||||||||||||||||||
| 344 | ( defined $timeout ? ( timeout => $timeout ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 345 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | ▶ | if ( ( $verdict->{status} // '' ) eq 'ok' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$verdict->{"status"} // ""
MC/DC0%0/1
$verdict->{"status"} // ""
$verdict->{"status"}
Truth table50%1/2
A
A= $verdict->{"status"}
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | $self->{auth} = { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | uid => $verdict->{result}{uid}, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | username => $verdict->{result}{username}, | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 4 | ▶ | groups => $verdict->{result}{groups} // [], | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$verdict->{"result"}{"groups"} // []
MC/DC100%1/1
$verdict->{"result"}{"groups"} // []
$verdict->{"result"}{"groups"}
Truth table100%2/2
A
A= $verdict->{"result"}{"groups"}
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 4 | return $verdict; | |||||||||||||||||||||||||||||||||||||||||
| 354 | } ## end if ( $challenge->{result}...) | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | my $cookie = $challenge->{result}{cookie} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$challenge->{"result"}{"cookie"} // ""
MC/DC0%0/1
$challenge->{"result"}{"cookie"} // ""
$challenge->{"result"}{"cookie"}
Truth table0%0/2
A
A= $challenge->{"result"}{"cookie"}
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | my $temp_dir = $challenge->{result}{temp_dir} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$challenge->{"result"}{"temp_dir"} // ""
MC/DC0%0/1
$challenge->{"result"}{"temp_dir"} // ""
$challenge->{"result"}{"temp_dir"}
Truth table0%0/2
A
A= $challenge->{"result"}{"temp_dir"}
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | unless ( length $cookie && length $temp_dir && -d $temp_dir ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
length $cookie and length $temp_dir and -d $temp_dir
length $cookie and length $temp_dir
MC/DC0%0/3
length $cookie and length $temp_dir and -d $temp_dir
length $cookie
length $temp_dir
-d $temp_dir
Truth table0%0/4
A and B and C
A= length $cookieB= length $temp_dirC= -d $temp_dir
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | status => 'error', | |||||||||||||||||||||||||||||||||||||||||
| 361 | error => 'auth_start returned an unusable cookie or temp_dir', | ||||||||||||||||||||||||||||||||||||||||||
| 362 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | # PERMS creates the file as 0644 from the start rather than File::Temp's | ||||||||||||||||||||||||||||||||||||||||||
| 366 | # 0600 default: the server may run as another unprivileged user and must | ||||||||||||||||||||||||||||||||||||||||||
| 367 | # be able to read it. The proof is the file's ownership, not its secrecy | ||||||||||||||||||||||||||||||||||||||||||
| 368 | # -- the cookie is single-use and the file is unlinked on verify -- so | ||||||||||||||||||||||||||||||||||||||||||
| 369 | # world-readable is acceptable and there is no window where the file | ||||||||||||||||||||||||||||||||||||||||||
| 370 | # exists with the wrong mode. | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my ( $fh, $cookie_path ) = eval { | |||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | File::Temp::tempfile( | |||||||||||||||||||||||||||||||||||||||||
| 373 | 'jsonunix_auth_XXXXXX', | ||||||||||||||||||||||||||||||||||||||||||
| 374 | DIR => $temp_dir, | ||||||||||||||||||||||||||||||||||||||||||
| 375 | UNLINK => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 376 | PERMS => 0644, | ||||||||||||||||||||||||||||||||||||||||||
| 377 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 378 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | unless ($fh) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | status => 'error', | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$@ || $!
MC/DC0%0/2
$@ || $!
$@
$!
Truth table0%0/3
A || B
A= $@B= $!
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | error => "could not create cookie file in $temp_dir: " . ( $@ || $! ), | ||||||||||||||||||||||||||||||||||||||||||
| 383 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | print {$fh} $cookie; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | my $verdict = $self->call( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | command => 'auth_verify', | ||||||||||||||||||||||||||||||||||||||||||
| 390 | args => { path => $cookie_path }, | ||||||||||||||||||||||||||||||||||||||||||
| 391 | ( defined $timeout ? ( timeout => $timeout ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 392 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | unlink $cookie_path; # server unlinks it; clean up if it did not | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | if ( ( $verdict->{status} // '' ) eq 'ok' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$verdict->{"status"} // ""
MC/DC0%0/1
$verdict->{"status"} // ""
$verdict->{"status"}
Truth table0%0/2
A
A= $verdict->{"status"}
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | $self->{auth} = { | ||||||||||||||||||||||||||||||||||||||||||
| 397 | uid => $verdict->{result}{uid}, | ||||||||||||||||||||||||||||||||||||||||||
| 398 | username => $verdict->{result}{username}, | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | groups => $verdict->{result}{groups} // [], | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$verdict->{"result"}{"groups"} // []
MC/DC0%0/1
$verdict->{"result"}{"groups"} // []
$verdict->{"result"}{"groups"}
Truth table0%0/2
A
A= $verdict->{"result"}{"groups"}
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | return $verdict; | |||||||||||||||||||||||||||||||||||||||||
| 403 | } ## end sub authenticate | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | =head2 connected | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | True while a connection to the server is up. | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | =head2 authenticated | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | True after a successful L</authenticate> on the current connection. | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | =head2 uid | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | =head2 username | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | The verified identity, or C<undef> before authentication. Cleared on | ||||||||||||||||||||||||||||||||||||||||||
| 418 | disconnect. | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | =head2 groups | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | Array reference of the verified user's group names, or C<undef> before | ||||||||||||||||||||||||||||||||||||||||||
| 423 | authentication. Empty unless the server has a permission policy configured | ||||||||||||||||||||||||||||||||||||||||||
| 424 | (only then does its C<auth_verify> report groups). Cleared on disconnect. | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 3 | ▶ | sub connected { return defined $_[0]{socket} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connected: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | sub authenticated { return defined $_[0]{auth} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authenticated: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | ▶ | sub uid { return $_[0]{auth} ? $_[0]{auth}{uid} : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uid: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | sub username { return $_[0]{auth} ? $_[0]{auth}{username} : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
username: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | ▶ | sub groups { return $_[0]{auth} ? $_[0]{auth}{groups} : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
groups: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 7 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 7 | ▶ | close delete $self->{socket} if $self->{socket}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | __END__ | ||||||||||||||||||||||||||||||||||||||||||