blib/lib/CGI/Carp/StackTrace.pm

filter: Statementstmt 82.3% 28 / 34 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 1 totaltotal 77.5% 38 / 49 CC 2 SCAR 6.3
CC
2
Cov
78%
munge_error
6.0
__ANON__
2.0
BEGIN
1.3
CRAP 1.9
↑ Summary
1 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package CGI::Carp::StackTrace;
3 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 $CGI::Carp::StackTrace::AUTHORITY = 'cpan:RKITOVER';
5 }
6 {
7 1 $CGI::Carp::StackTrace::VERSION = '0.01';
8 }
9  
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use CGI::Carp 'fatalsToBrowser';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Devel::StackTrace::WithLexicals ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Devel::StackTrace::AsHTML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use HTML::Entities 'decode_entities';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 =encoding UTF-8
19  
20 =head1 NAME
21  
22 CGI::Carp::StackTrace - install a L<Devel::StackTrace::AsHTML> error screen for your CGI app
23  
24 =head1 SYNOPSIS
25  
26 use Sys::Hostname 'hostname';
27  
28 my $IS_PRODUCTION;
29  
30 BEGIN {
31 $IS_PRODUCTION = hostname() eq 'prod_server';
32  
33 require CGI::Carp::StackTrace if not $IS_PRODUCTION;
34 }
35  
36 =head1 DESCRIPTION
37  
38 Add a modern error screen to your CGI application, like L<Plack::Middleware::StackTrace>.
39  
40 Uses L<CGI::Carp> in conjunction with L<Devel::StackTrace::WithLexicals> and
41 L<Devel::StackTrace::AsHTML>.
42  
43 =cut
44  
45 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=2.6
46 0 ▶ CGI::Carp::set_message(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 my $stack_trace = Devel::StackTrace::WithLexicals->new(
48 message => munge_error(decode_entities(shift), [ caller(3) ]),
49 ignore_package => [__PACKAGE__, 'CGI::Carp'],
50 );
51 0 print $stack_trace->as_html;
52 1 });
53 }
54  
55 # stolen from Plack::Middleware::StackTrace
56 0 ▶sub munge_error {
Subroutine munge_error: not called CC=2 SCAR=17.9
Pod undocumented
57 0 my($err, $caller) = @_;
58 0 ▶ return $err if ref $err;
Branch: 1 branch
BranchTrueFalseTotal
if ref $err 0 0 0
59  
60 # Ugly hack to remove " at ... line ..." automatically appended by perl
61 # If there's a proper way to do this, please let me know.
62 0 $err =~ s/ at \Q$caller->[1]\E line $caller->[2]\.\n$//;
63  
64 0 return $err;
65 }
66  
67 =head1 SEE ALSO
68  
69 =over 4
70  
71 =item * L<Devel::StackTrace>
72  
73 =item * L<Devel::StackTrace::WithLexicals>
74  
75 =item * L<Devel::StackTrace::AsHTML>
76  
77 =item * L<CGI::Carp>
78  
79 =item * L<Plack::Middleware::StackTrace>
80  
81 =back
82  
83 =head1 AUTHOR
84  
85 Rafael Kitover <rkitover@cpan.org>
86  
87 =head1 ACKNOWLEDGEMENTS
88  
89 Thanks to Dave Rolsky for L<Devel::StackTrace> and Miyagawa for
90 L<Devel::StackTrace::AsHTML>.
91  
92 Some code in this module is stolen from Miyagawa's
93 L<Plack::Middleware::StackTrace>.
94  
95 =cut
96  
97 1 __PACKAGE__; # End of CGI::Carp::StackTrace
↑ Summary