| 1 | package Plack::Middleware::OIDC::Logger; | ||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use 5.020; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 10 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =encoding utf8 | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Plack::Middleware::OIDC::Logger - Minimal default logger for Plack::Middleware::OIDC | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | L<OIDC::Client> and L<OIDC::Client::Plugin> require a logger object that | ||||||||||||||||||||||||||||
| 19 | implements the C<debug>, C<info>, C<error> and (C<warning> or C<warn>) | ||||||||||||||||||||||||||||
| 20 | methods (see L<OIDC::Client::Role::LoggerWrapper>). | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | Unlike Mojolicious, Catalyst or Dancer2, Plack does not provide a logger | ||||||||||||||||||||||||||||
| 23 | out of the box, so this small class is used by default, writing to | ||||||||||||||||||||||||||||
| 24 | C<STDERR> (or to C<$env->{'psgix.logger'}> if available). You can | ||||||||||||||||||||||||||||
| 25 | provide your own logger object instead via the C<log> option of | ||||||||||||||||||||||||||||
| 26 | L<Plack::Middleware::OIDC>, as long as it implements the same interface. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 METHODS | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head2 new( %args ) | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | Optional C<env> argument: if given and C<$env->{'psgix.logger'}> is | ||||||||||||||||||||||||||||
| 33 | set, messages are sent there instead of C<STDERR>. | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 14 | ▶ | sub new ($class, %args) { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 14 | return bless { env => $args{env} }, $class; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head2 set_env($env) | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Sets the PSGI environment attribute. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | The environment is used to access the C<psgix.logger> callback, when | ||||||||||||||||||||||||||||
| 47 | available, so that log messages can be forwarded to the logging | ||||||||||||||||||||||||||||
| 48 | mechanism provided by the PSGI application server. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 29 | ▶ | sub set_env ($self, $env) { | ||||||||||||||||||||||||||
|
Subroutine
set_env: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 29 | $self->{env} = $env; | |||||||||||||||||||||||||||
| 54 | 29 | return $self; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 16 | ▶ | sub _log ($self, $level, $message) { | ||||||||||||||||||||||||||
|
Subroutine
_log: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 16 | my $env = $self->{env}; | |||||||||||||||||||||||||||
| 61 | 16 | ▶ | if ($env && $env->{'psgix.logger'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$env and $env->{"psgix.logger"}
MC/DC50%1/2
$env and $env->{"psgix.logger"}
$env
$env->{"psgix.logger"}
Truth table66%2/3
A and B
A= $envB= $env->{"psgix.logger"}
| |||||||||||||||||||||||||||||
| 62 | 15 | $env->{'psgix.logger'}->({ level => $level, message => $message }); | |||||||||||||||||||||||||||
| 63 | 15 | return; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | print STDERR "[$level] $message\n"; | |||||||||||||||||||||||||||
| 67 | 1 | return; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =head2 debug($message) | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | Logs a message at the C<debug> level. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head2 info($message) | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Logs a message at the C<info> level. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head2 warning($message) | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Logs a message at the C<warn> level. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head2 warn($message) | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Logs a message at the C<warn> level. | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head2 error($message) | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Logs a message at the C<error> level. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =cut | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 14 | ▶ | sub debug ($self, $message) { $self->_log('debug', $message); return; } | ||||||||||||||||||||||||||
|
Subroutine
debug: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 2 | ▶ | sub info ($self, $message) { $self->_log('info', $message); return; } | ||||||||||||||||||||||||||
|
Subroutine
info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub warning ($self, $message) { $self->_log('warn', $message); return; } | ||||||||||||||||||||||||||
|
Subroutine
warning: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub warn ($self, $message) { $self->_log('warn', $message); return; } | ||||||||||||||||||||||||||
|
Subroutine
warn: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub error ($self, $message) { $self->_log('error', $message); return; } | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 10 | 1; | |||||||||||||||||||||||||||