Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Carp croak not working when used in an imported function

by mreece (Friar)
on Sep 29, 2006 at 22:49 UTC ( #575616=note: print w/replies, xml ) Need Help??


in reply to Carp croak not working when used in an imported function

try this?
sub errmsg { local $Carp::CarpLevel = 1; Carp::croak "$_[0]"; }

update: i understand this is a rather contentious 'feature'! some suggest +=1 instead, or consider Carp::Clan..
again: +=1 doesn't work as i expected on a local, use local $Carp::CarpLevel = $Carp::CarpLevel + 1; as shenme suggested below!

Replies are listed 'Best First'.
Re^2: Carp croak not working when used in an imported function
by shenme (Priest) on Sep 29, 2006 at 23:04 UTC
    Quick, before tilly notices, change that to
    local $Carp::CarpLevel = $Carp::CarpLevel + 1;
Re^2: Carp croak not working when used in an imported function
by fmerges (Chaplain) on Sep 29, 2006 at 23:25 UTC

    Hi,

    Why quoting the parameter to croak? "$_[0]" -> $_[0]

    I don't see the problem:

    cucu.pm
    package cucu; use strict; use Carp (); sub error { Carp::croak @_; } 1;
    t.pl
    use strict; use cucu; ty(); sub ty { cucu::error('blabla'); }

    Regards,

    fmerges at irc.freenode.net
Re^2: Carp croak not working when used in an imported function
by Anonymous Monk on Sep 29, 2006 at 23:12 UTC
    That did it! Thanks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2021-02-27 19:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?