You know what would be nice? A built in log/trace option, something like
#!/usr/bin/perl --
use strict;
use warnings;
use autodie 2.01;
use autodie 'log'; # default logger
use autodie log => sub { # custom logger
no warnings 'uninitialized';
use POSIX();
use Carp();
use Scalar::Quote();
my ( $func, @args ) = @_;
(@_) = (
POSIX::strftime( '%Y-%m-%d %H:%M:%S ', localtime ),
"$func( ", join( ', ', map { Scalar::Quote::quote($_) } @args
+), " )"
);
goto &Carp::carp;
};
open my($in), '<', __FILE__;
close $in;
system $^X, qw[ -le print(66) ];
systemx $^X, qw[ -le die(66) ];
__END__
2009-07-02 01:45:45 main::open( undef, '<', 'test.pl' ) at test.pl lin
+e 23
2009-07-02 01:45:45 main::close( 'GLOB(0x182f970)' ) at test.pl line 2
+4
2009-07-02 01:45:45 main::system( "C:\\Perl\\bin\\perl.exe", '-le', 'p
+rint(66)' ) at test.pl line 25
2009-07-02 01:45:45 main::system( "C:\\Perl\\bin\\perl.exe", '-le', 'd
+ie(66)' ) at test.pl line 26
66 at -e line 1.
"C:\Perl\bin\perl.exe" unexpectedly returned exit value 255 at test.pl
+ line 26
For now I'm getting by with
use Devel::TraceMethods ( main => sub ... );
but would really love
use autodie 'log';
C:\perl\.cpanplus\5.8.9\build\autodie-2.03>perl -Mblib t\hints.t
# Sub::Identify is loaded
ok 1 - Id: copy
ok 2 - Id: cp
ok 3 - Id: move
ok 4 - Id: mv
ok 5 - Copying in scalar context should throw an error.
ok 6 - The object isa autodie::exception
ok 7 - Function should be original name
not ok 8 - File::Copy returns zero on failure
# Failed test 'File::Copy returns zero on failure'
# at t\hints.t line 64.
# got: ''
# expected: '0'
ok 9 - File::Copy called in scalar context
ok 10 - Copying in list context should throw an error.
ok 11 - The object isa autodie::exception
ok 12 - Function should be original name
not ok 13 - File::Copy returns zero on failure
# Failed test 'File::Copy returns zero on failure'
# at t\hints.t line 79.
# Structures begin differing at:
# $got->[0] = ''
# $expected->[0] = '0'
ok 14 - File::Copy called in list context
ok 15 - fail_on_undef(1)
ok 16 - fail_on_empty(undef)
ok 17 - fail_on_empty()
ok 18 - fail_on_false(1)
ok 19 - fail_on_false(0)
ok 20 - fail_on_empty(0)
ok 21 - fail_on_undef(undef)
ok 22 - fail_on_undef(0)
ok 23 - fail_on_undef()
ok 24 - fail_on_empty(1)
ok 25 - fail_on_false(undef)
ok 26 - fail_on_false()
1..26
# Looks like you failed 2 tests of 26.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.