in reply to Re: Should I use carp/croak or warn/die
in thread Should I use carp/croak or warn/die

> Sometimes I don't know how many levels up the user of my module called. Having an option to "carp" from the first caller in a different package would be nice. (This is more a nice to have)

Though I'm not sure if @CARP_NOT could be used for this ...

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

  • Comment on Re^2: Should I use carp/croak or warn/die (@CARP_NOT)

Replies are listed 'Best First'.
Re^3: Should I use carp/croak or warn/die (@CARP_NOT)
by stevieb (Canon) on May 30, 2018 at 22:36 UTC

    From my experience, mucking with the likes of caller and/or any aspect of such an undertaking of tracking and reporting from nested modules and subs is fraught with frustration, angst, head-desking and oftentimes throwing things... particularly when dealing with anony-subs and the like :)

      That's right. But sometimes caller is needed to implement nifty YAGNIs :)

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^3: Should I use carp/croak or warn/die (@CARP_NOT)
by Anonymous Monk on May 30, 2018 at 21:52 UTC
    Though I'm not sure if @CARP_NOT could be used for this ...
    How could it?

    I mean @CARP_NOT is a package variable that is (or so I suppose) evaluated at compile-time.

    How could that be used to implement the run-time feature of reporting the the first caller of a different package?

    I don't really know to be honest, you could be right, but my working hypothesis here is that you're simply blah-blahing here.

    So please enlighten us...

      I wouldn't ask if I knew.

      > evaluated at compile-time.

      nope that's obvious from the docs and from a simple test.

      > you're simply blah-blahing here.

      Look who's talking...

      Anyway carp() seems to already do by default what I wanted. \o/

      It doesn't report from the caller function but the caller package.

      use strict; use warnings; use Data::Dump qw/pp dd/; TEST::first(); # <- line 6 #push @main::CARP_NOT, qw(TEST); # uncomment to see dynamic behaviour #TEST::first(); package TEST; use Carp; sub first { second(); } sub second { carp "some warning"; }

      some warning at d:/Users/RolfLangsdorf/pm/carp_not.pl line 6.

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