Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: die or croak

by Corion (Pope)
on Aug 09, 2013 at 19:28 UTC ( #1048830=note: print w/replies, xml ) Need Help??

in reply to Re: die or croak
in thread die or croak

Note that you can exempt your module from croak by setting up @CARP_NOT. That way, your module will be invisible to carp.

Replies are listed 'Best First'.
Re^3: die or croak
by McA (Priest) on Aug 09, 2013 at 19:32 UTC

    Ahh, that sounds intersting. Can you give some pointers or examples?


      I first had problems understanding the documentation in Carp, but basically the setup is:

      package Foo; use strict; use Carp qw( croak ); sub do_foo { croak "Please don't give arguments to do_foo(), got '@_'" unless 0 == @_; }; package Baz; use strict; sub do_baz { Foo::do_foo( @_ ); }; package Bar; use strict; use vars qw(@CARP_NOT); @CARP_NOT=('Foo'); # we are invisible to Foo sub do_bar { my( $first,@rest )= @_; print "Got '$first', Preparing for foo(@rest)\n"; Foo::do_foo(@rest); }; package main; print "Bar\n"; Bar::do_bar('one'); # does not croak print "do_foo\n"; eval { Foo::do_foo('one','two'); }; print $@; # Please don't give arguments to do_foo(), got 'one two' at lin +e 34. print "do_bar\n"; eval { Bar::do_bar('one','two'); }; print $@; # Please don't give arguments to do_foo(), got 'two' at line 37 +. print "do_baz\n"; eval { Baz::do_baz('one','two'); }; print $@; # Please don't give arguments to do_foo() at line 14.

      Here, the package Bar does not show up as an error location, because it sets itself up to be invisible for all errors raised by Foo. Baz does get raised as the error location in the last call, which may or may not be helpful to the user using Baz.

      For a more elaborate example of this, MozRepl::RemoteObject::Instance has some helper classes for tie-ing scalars, arrays and hashes. But all errors due to operations on these should be transparent to the user and show up in the user code, which is achieved by setting up @CARP_NOT in each of the tied classes so that errors raised in MozRepl::RemoteObject::Instance never show up as originating in the helper class.

        Thank you very much for that example (I can give only one ++, sorry). But this seems to be really a secret treasure...

        Best regards

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048830]
[corenth]: Cosmic, that sounds interesting. What is FANN (I could search it if I weren't so lazy about it)?
[Cosmic37]: how big was @stuff corenth?
[Cosmic37]: Fast Artificial Neural Network (FANN) is cross-platform open source programming library for developing multilayer feedforward Artificial Neural Networks
[corenth]: @stuff was pretty big. I think it grew to about 8000.
[corenth]: each element was several three + element references
[corenth]: That FANN thing sounds like something I
[Cosmic37]: When I say I like LGPL what I mean is that I like the GPL aspect. I am a fan of Rishard Stallman and the Free Software Foundation but I wish I could be more virtuous... self-flagellates
[corenth]: . . . I'd like to play with

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-02-20 18:21 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (274 votes). Check out past polls.