in reply to
Advice for moving forward with modules
When you call die from inside a module, you should
probably be using croak instead (and carp
instead of warn). These two methods are available
from Carp.pm. Try this little exercise, save the following
as Foo.pm:
package Foo;
use Carp qw(croak);
use base qw(Exporter);
our @EXPORT_OK = qw(gonna_croak gonna_die);
sub gonna_die { die "ya got me!" }
sub gonna_croak { croak "ya got me!" }
1;
Now use that module with the following one-liners:
$ perl -MFoo=gonna_die -le gonna_die
ya got me! at Foo.pm line 7.
$ perl -MFoo=gonna_croak -le gonna_croak
ya got me! at -e line 1
die reports the error from the actual line it was
executed on, which might be many packages deep.
croak, on the other hand, reports the error from
the perpestive of the caller, which is usually more useful
to the end user. The end user usually cares more about which
line of
their code caused the problem, not which line
in the module it affected.
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)