blib/lib/Plack/Middleware/Test/StashWarnings.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 80.0% 8 / 10 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 92.8% 13 / 14 Podpod 50.0% 2 / 4 totaltotal 81.3% 74 / 91 CC 10 SCAR 9.0
CC
10
Cov
88%
call
5.1
new
3.2
_stash_warnings_for
2.0
CRAP 2.5
↑ Summary
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
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
14 3 my $self = $class->SUPER::new(@_);
15 3 ▶ $self->{verbose} = $ENV{TEST_VERBOSE} unless defined $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"verbose"} 3 0 3
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
BranchTrueFalseTotal
if ($env->{"PATH_INFO"} eq "/__test_warnings") 6 5 11
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
BranchTrueFalseTotal
if $env->{"psgi.multiprocess"} and $self->{"multiprocess_warn"}++ == 0 0 6 6
Condition33%1/3
$env->{"psgi.multiprocess"} and $self->{"multiprocess_warn"}++ == 0
!ll&&!rl&&r
600
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (ref $ret eq "CODE") 2 3 5
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 @_; }
l!l&&r!l&&!r
160
MC/DC0%0/2
$SIG{'__WARN__'} || sub { warn @_; }
$SIG{'__WARN__'} sub { warn @_; }
Truth table66%2/3
A || B
A= $SIG{'__WARN__'}B= sub { warn @_; }
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $self->{"verbose"} 1 2 3
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__
↑ Summary