blib/lib/Plack/Middleware/StackTrace/LinkedSource.pm

filter: Statementstmt 98.2% 55 / 56 Branchbran 66.6% 12 / 18 Conditioncond 66.6% 6 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 87.0% 87 / 100 CC 14 SCAR 15.0
CC
14
Cov
88%
prepare_app
7.8
call
5.0
_add_link
4.0
CRAP 4.5
↑ Summary
1 package Plack::Middleware::StackTrace::LinkedSource;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use parent 'Plack::Middleware::StackTrace';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Plack::App::SourceViewer;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Plack::Util::Accessor qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
8 lib
9 viewer
10 view_root
11 force
12 2 /;
13  
14 2 our $VERSION = '0.14';
15  
16 6 ▶sub prepare_app {
Subroutine prepare_app: called CC=7 SCAR=20.5
Pod documented
17 6 my ($self) = @_;
18  
19 6 ▶ if (!$self->lib) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->lib) { } 6 0 6
elsif (ref $self->lib ne 'ARRAY') { } 0 0 0
20 6 $self->lib([@INC]);
21 }
22 elsif (ref $self->lib ne 'ARRAY') {
23 0 $self->lib([$self->lib]);
24 }
25  
26 6 ▶ unless ($self->viewer) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->viewer) 6 0 6
27 6 my $source_viewer = Plack::App::SourceViewer->new(root => $self->lib);
28 6 $source_viewer->prepare_app;
29 6 $self->viewer($source_viewer);
30 }
31  
32 $self->view_root
33 6 ▶ or $self->view_root('/source');
Branch: 1 branch
BranchTrueFalseTotal
$self->view_root or $self->view_root("/source") 2 4 6
34  
35 6 ▶ $self->{_enabled} = ($self->force || !$ENV{PLACK_ENV} || $ENV{PLACK_ENV} eq 'development');
Condition83%5/6
$self->force || !$ENV{'PLACK_ENV'} || $ENV{'PLACK_ENV'} eq 'development'
l!l&&r!l&&!r
501
$self->force or not $ENV{"PLACK_ENV"}
l!l&&r!l&&!r
141
MC/DC66%2/3
$self->force || !$ENV{'PLACK_ENV'} || $ENV{'PLACK_ENV'} eq 'development'
$self->force not $ENV{"PLACK_ENV"} $ENV{'PLACK_ENV'} eq 'development'
Truth table75%3/4
A or not(B) || C
A= $self->forceB= not $ENV{"PLACK_ENV"}C= $ENV{'PLACK_ENV'} eq 'development'
ABCresult
1XX1
01X1
0011
0000
36 }
37  
38 6 ▶sub call {
Subroutine call: called CC=5 SCAR=16.2
Pod documented
39 6 my($self, $env) = @_;
40  
41 6 ▶ unless ($self->{_enabled}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_enabled"}) 1 5 6
42 1 return $self->app->($env);
43 }
44  
45 5 my $path = $self->view_root;
46  
47 5 ▶ if ($env->{PATH_INFO} =~ m!^$path!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env->{"PATH_INFO"} =~ /^$path/) 2 3 5
48 2 my $path_info = $env->{PATH_INFO};
49 2 $path_info =~ s!^$path/!!;
50 2 local $env->{PATH_INFO} = $path_info;
51 2 return $self->viewer->call($env);
52 }
53  
54 3 my $res = $self->SUPER::call($env);
55  
56 3 ▶ if ($res->[0] == 500 && Plack::Util::header_get($res->[1], 'content-type') =~ m!text/html!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->[0] == 500 and Plack::Util::header_get($res->[1], "content-type") =~ m[text/html]) 3 0 3
Condition33%1/3
$res->[0] == 500 and Plack::Util::header_get($res->[1], "content-type") =~ m[text/html]
!ll&&!rl&&r
003
MC/DC0%0/2
$res->[0] == 500 and Plack::Util::header_get($res->[1], "content-type") =~ m[text/html]
$res->[0] == 500 Plack::Util::header_get($res->[1], "content-type") =~ m[text/html]
Truth table33%1/3
A and B
A= $res->[0] == 500B= Plack::Util::header_get($res->[1], "content-type") =~ m[text/html]
ABresult
0X0
100
111
57 3 my $body = $res->[2][0];
58 3 $self->_add_link(\$body);
59 3 $res->[2][0] = $body;
60 }
61  
62 3 return $res;
63 }
64  
65 3 ▶sub _add_link {
Subroutine _add_link: called CC=4 SCAR=13.9
66 3 my ($self, $body_ref) = @_;
67  
68 3 for my $lib_path (@{$self->lib}) {
69 30 ▶ next if $lib_path eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $lib_path eq "." 6 24 30
70 24 ▶ $lib_path =~ s!/!\\!g if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 24 24
71 24 ${$body_ref} =~ s!(\Q$lib_path\E[/\\]+([^\.]+\.[^\s]+)\s+line\s+(\d+))[^<]?!$self->_link_html($1, $2, $3)!eg;
72 }
73 }
74  
75 33 ▶sub _link_html {
Subroutine _link_html: called CC=1 SCAR=0.0
76 33 my ($self, $matched, $path, $line_count) = @_;
77  
78 33 $path =~ s!\\!/!g; # for win
79  
80 33 return qq|<a href="|. $self->view_root. qq|/$path#L$line_count">$matched</a>|;
81 }
82  
83 2 1;
84  
85  
86 __END__
↑ Summary