| 1 | package Punk::Plugin::RequestId; | ||||||||||||
| 2 | |||||||||||||
| 3 | 10 | ▶ | use 5.010; | ||||||||||
|
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 | 10 | ▶ | use parent 'Punk::Plugin'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 10 | ▶ | use Carp (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 10 | ▶ | use Punk (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 10 | our $VERSION = '0.70'; | |||||||||||
| 11 | |||||||||||||
| 12 | # The id path itself is C - include/punk/punk_reqid.h and xs/reqid.xs. | ||||||||||||
| 13 | |||||||||||||
| 14 | 51 | ▶ | sub register { | ||||||||||
|
Subroutine
register: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||
| 15 | 51 | my ($self, $app, $opts) = @_; | |||||||||||
| 16 | # uncoverable condition right | ||||||||||||
| 17 | 51 | ▶ | $opts ||= {}; | ||||||||||
|
Condition100%1/2
$opts ||= {}
MC/DC100%0/1
$opts ||= {}
$opts
Truth table100%1/2
A
A= $opts
| |||||||||||||
| 18 | |||||||||||||
| 19 | 51 | ▶ | my $header = exists $opts->{header} ? $opts->{header} : 'X-Request-Id'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | 51 | ▶ | $header = undef unless $header; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | 51 | ▶ | if (defined $header) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | 44 | ▶ | Carp::croak("Punk::Plugin::RequestId: header '$header' is not a " | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | . 'usable header name') | ||||||||||||
| 24 | if $header =~ /[^A-Za-z0-9_-]/; | ||||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | 46 | my $envkey; | |||||||||||
| 28 | 46 | ▶ | if ($opts->{trust_header}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | my $from = defined $header ? $header | ||||||||||||
| 30 | 5 | ▶ | : do { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 2 | Carp::croak('Punk::Plugin::RequestId: trust_header needs ' | |||||||||||
| 32 | . 'a header to read; it cannot be used with ' | ||||||||||||
| 33 | . 'header => 0'); | ||||||||||||
| 34 | }; | ||||||||||||
| 35 | 3 | ($envkey = uc $from) =~ tr/-/_/; | |||||||||||
| 36 | 3 | $envkey = "HTTP_$envkey"; | |||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | 44 | __PACKAGE__->_enable($app, $header, $envkey); | |||||||||||
| 40 | |||||||||||||
| 41 | 44 | $app->helper(request_id => \&_id); | |||||||||||
| 42 | |||||||||||||
| 43 | 44 | return; | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | 10 | 1; | |||||||||||
| 47 | |||||||||||||
| 48 | __END__ | ||||||||||||