Skip to content

Commit

Permalink
resolve #165 - add FULL_PATH option to CGI::Carp
Browse files Browse the repository at this point in the history
for more specific error messages, set this to 1 and CGI::Carp will
show the full path in the timestamp added to the message (full path
being that returned by caller, it will not be the abs_path so if
you are running the scripts from within their directories then it
won't make a difference)
  • Loading branch information
leejo committed Mar 1, 2015
1 parent 284fe50 commit cee9974
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

- References: GH #162, GH #137, GH #164

[ FEATURES ]
- CGI::Carp now has $CGI::Carp::FULL_PATH for displaying the full path to the
offending script in error messages

[ SPEC / BUG FIXES ]
- Add the multi_param method to :cgi export (thanks to xblitz for the patch
and tests. GH #167)
Expand Down
3 changes: 2 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ WriteMakefile(
VERSION_FROM => 'lib/CGI.pm',
MIN_PERL_VERSION => '5.8.1',
PREREQ_PM => {
'Carp' => 0, # Carp was first released with perl 6
'Cwd' => 0, # Cwd was first released with perl 5
'Carp' => 0, # Carp was first released with perl 5
'Exporter' => 0, # Exporter was first released with perl 5
'base' => 0, # base was first released with perl 5.00405
'overload' => 0, # overload was first released with perl 5.002
Expand Down
10 changes: 8 additions & 2 deletions lib/CGI/Carp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ Alternatively you can set C<$CGI::Carp::NO_TIMESTAMP> to 1.
Note that the name of the program is still automatically included in
the message.
=head1 GETTING THE FULL PATH OF THE SCRIPT IN MESSAGES
Set C<$CGI::Carp::FULL_PATH> to 1.
=head1 AUTHOR INFORMATION
The CGI.pm distribution is copyright 1995-2007, Lincoln D. Stein. It is
Expand Down Expand Up @@ -323,7 +327,7 @@ $CGI::Carp::CUSTOM_MSG = undef;
$CGI::Carp::DIE_HANDLER = undef;
$CGI::Carp::TO_BROWSER = 1;
$CGI::Carp::NO_TIMESTAMP= 0;

$CGI::Carp::FULL_PATH = 0;

# fancy import routine detects and handles 'errorWrap' specially.
sub import {
Expand Down Expand Up @@ -370,7 +374,9 @@ sub stamp {
($pack,$file) = caller($frame++);
} until !$file;
}
($dev,$dirs,$id) = File::Spec->splitpath($id);
if (! $CGI::Carp::FULL_PATH) {
($dev,$dirs,$id) = File::Spec->splitpath($id);
}
return "$id: " if $CGI::Carp::NO_TIMESTAMP;
my $time = scalar(localtime);
return "[$time] $id: ";
Expand Down
15 changes: 14 additions & 1 deletion t/carp.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

use strict;

use Test::More tests => 63;
use Test::More tests => 64;
use IO::Handle;

use CGI::Carp;
use Cwd;

#-----------------------------------------------------------------------------
# Test id
Expand Down Expand Up @@ -56,6 +57,18 @@ sub stamp2 {return stamp1()};

like(stamp2(), $stamp, "Time in correct format");

$CGI::Carp::FULL_PATH = 1;
# really should test the full path here, but platform differnces
# will make the regexp hideous. this may well fail if anything
# using it chdirs into t/ so using Cwd to dry to catch this
my $cwd = getcwd;
if ( $cwd !~ /t$/ ) {
unlike(stamp2(), $stamp, "Time in correct format (FULL_PATH)");
} else {
pass( "Can't run FULL_PATH test when cwd is t/" );
}
$CGI::Carp::FULL_PATH = 0;

#-----------------------------------------------------------------------------
# Test warn and _warn
#-----------------------------------------------------------------------------
Expand Down

0 comments on commit cee9974

Please sign in to comment.