in reply to Re: Best way to track an error string in module?
in thread Best way to track an error string in module?

To appease PErl::Critic I have to replace die with croak and I want to be sure that what I'm doing in the object is the best way to it and maintain the simplicity of the application. In the code below, I've calledping() without logging in so it will login for me. The auth tokens timeout so ping() will re-login if a token has timed out due to inactivity.
/usr/bin/perl-MObject -le 'my $cIn the past, I'd keep track of my = O +bject->new("192.168.1.63"); $c->ping() or die $c->errstr();' soap:Server, invalid login/password at -e line 1. at -e line 1.
The AUTOLOAD needs to go too. In the past I'd keep track of indention within each function. This is tedious and often forgotten, but indented debug trace makes reading easy for me. The debug id done simliar to this and this is mostly just pseudo:
# Print Debug output sub p_debug { my $self = shift; return unless $self->{'DEBUG'}; printf "DEBUG: [%04f] %s%s\n", delta_time($last), (' ' x $indent), s +printf(shift @_, @_); return } # Th old way of tracking indent forced me to make sure I was increment +ing and decrementing when required. I was looking for a way to autom +atically increment on entry and automatically decrement on return sub ping { my $self = shift; $self->{'INDENT'}++; .... $self->{'INDENT'}--; return $result; }
/usr/bin/perl-MObject -le 'my $cIn the past, I'd keep track of my = O +bject->new("192.168.1.63"); $c->ping() or die $c->errstr();' DEBUG: 0.0033 Object::echo(): sending data to soap server to be echoed + back. DEBUG: 0.0034 Object::ping(): pinging SOAP interface. DEBUG: 0.0275 Object::login(): authenticating on service. DEBUG: 1.5343 Object::login(): token 828609a7e43e4ce22131694bed3f6a7 +1. DEBUG: 1.5346 Object::login(): authenticated. DEBUG: 2.9340 Object::ping(): SOAP interface up. DEBUG: 3.1558 Object::echo(): complete.
echo() called ping() first, ping() logged in, and then echo() returned back to caller.

Replies are listed 'Best First'.
Re^3: Best way to track an error string in module?
by LanX (Saint) on Mar 04, 2021 at 21:40 UTC
    IMHO the already described technique of monkeypatching wrappers is the best general approach, it's also easily reservable with localized *globs.

    Concerning this special tracing Perl offers various approaches for that, like activating it in debugger-context.

    It should also be possible to tweak Carp to adjust intendation or to use an alternative Carp from CPAN.

    Changing your classes for that special need only looks like overkill to me and smells a lot like an XY Problem.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery