| 1 | package Plack::Middleware::Test::StashWarnings; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use 5.008_001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use parent qw(Plack::Middleware); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Storable 'nfreeze'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 3 | my $proto = shift; | |||||||||||||||||||||||||||
| 13 | 3 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 14 | 3 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||
| 15 | 3 | ▶ | $self->{verbose} = $ENV{TEST_VERBOSE} unless defined $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 3 | return $self; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 11 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 11 | my ($self, $env) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 11 | ▶ | if ($env->{PATH_INFO} eq '/__test_warnings') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | Carp::carp("Use a single process server like Standalone to run Test::StashWarnings middleware") | ||||||||||||||||||||||||||||
| 24 | 6 | ▶ | if $env->{'psgi.multiprocess'} && $self->{multiprocess_warn}++ == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$env->{"psgi.multiprocess"} and $self->{"multiprocess_warn"}++ == 0
MC/DC0%0/2
$env->{"psgi.multiprocess"} and $self->{"multiprocess_warn"}++ == 0
$env->{"psgi.multiprocess"}
$self->{"multiprocess_warn"}++ == 0
Truth table33%1/3
A and B
A= $env->{"psgi.multiprocess"}B= $self->{"multiprocess_warn"}++ == 0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 6 | return [ 200, ["Content-Type", "application/x-storable"], [ $self->dump_warnings ] ]; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 5 | my $ret = $self->_stash_warnings_for($self->app, $env); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # for the streaming API, we need to re-instate the dynamic sigwarn handler | ||||||||||||||||||||||||||||
| 32 | # around the streaming callback | ||||||||||||||||||||||||||||
| 33 | 5 | ▶ | if (ref($ret) eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 2 | ▶ | return sub { $self->_stash_warnings_for($ret, @_) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 3 | return $ret; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 7 | ▶ | sub _stash_warnings_for { | ||||||||||||||||||||||||||
|
Subroutine
_stash_warnings_for: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 41 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | 7 | my $code = shift; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $old_warn = $SIG{__WARN__} || sub { warn @_ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.6
Condition66%2/3
$SIG{'__WARN__'} || sub {
warn @_;
}
MC/DC0%0/2
$SIG{'__WARN__'} || sub {
warn @_;
}
$SIG{'__WARN__'}
sub {
warn @_;
}
Truth table66%2/3
A || B
A= $SIG{'__WARN__'}B= sub {
warn @_;
}
| |||||||||||||||||||||||||||||
| 45 | 3 | ▶ | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 46 | 3 | $self->add_warning(@_); | |||||||||||||||||||||||||||
| 47 | 3 | ▶ | $old_warn->(@_) if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 7 | }; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 7 | return $code->(@_); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 3 | ▶ | sub add_warning { | ||||||||||||||||||||||||||
|
Subroutine
add_warning: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 3 | push @{ $self->{stashed_warnings} }, @_; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 6 | ▶ | sub dump_warnings { | ||||||||||||||||||||||||||
|
Subroutine
dump_warnings: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 6 | return nfreeze([ splice @{ $self->{stashed_warnings} } ]); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 3 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 65 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 3 | for (splice @{ $self->{stashed_warnings} }) { | |||||||||||||||||||||||||||
| 67 | 1 | warn "Unhandled warning: $_"; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | 1; | |||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||