| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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'
$self->force or not $ENV{"PLACK_ENV"}
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'
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$res->[0] == 500 and Plack::Util::header_get($res->[1], "content-type") =~ m[text/html]
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]
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 70 | 24 | ▶ | $lib_path =~ s!/!\\!g if $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||