Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: RFC: User subroutine hinting interface for autodie

by Anonymous Monk
on Jul 02, 2009 at 09:02 UTC ( [id://776675]=note: print w/replies, xml ) Need Help??


in reply to RFC: User subroutine hinting interface for autodie

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.

Replies are listed 'Best First'.
Re^2: RFC: User subroutine hinting interface for autodie
by Anonymous Monk on Jul 02, 2009 at 14:17 UTC
    Devel::TraceMethods wraps too many calls, so trying to override with
    use Devel::TraceCalls { Subs => [ qw! system ! ] };
    fails with
    Subroutine main::system not defined CHECK failed--call queue aborted.
    Something to do with CHECK blocks. This use Devel::TraceCalls { Package => 'main'}; works, but its wraps too much. Managed to get it working with Sub::Prepend
    BEGIN{ use Sub::Prepend 'prepend'; BEGIN { for my $name( qw[ system ] ){ prepend "$name" => sub{_logzy($name,@_)}; } } }
    having this built into autodie would be so much easier for novices :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://776675]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found