I haven't used Carp all that much because I've generally rolled my own. However, in the spirit of keeping with Core modules, I'm using it now. However, it seems like it's barely better than warn/die.
Furthermore, what does cluck/confess/verbose even do? I've ran this short script to get an idea of the output looks like (because the Carp docs don't do it). It looks exactly the same on any run (besides the random strings).
#!/usr/bin/perl
package Warning;
sub warning {
warn "warn";
}
package CWarn;
use Carp qw(carp cluck);
sub cwarn {
int(rand(2)) ? carp "carp" : cluck "cluck";
}
package Fatal;
use Carp qw(confess croak);
sub fatal {
int(rand(2)) ? confess "confess" : croak "croak";
}
package Loop;
use v5.10;
sub loop {
say '=' x 80;
Warning::warning();
CWarn::cwarn();
loop() unless ($c++ > 10);
Fatal::fatal();
}
package main;
Warning::warning();
CWarn::cwarn();
Loop::loop();
UPDATE: Updated the script with package names and it does make a difference. However, Carp still seems to be very basic in terms of logging information, and it doesn't support web output. I guess I'll look at other ones like CGI::Carp, Log::Output, and Log::Log4Perl.
package
, you will findcarp
andcroak
handy. as pointed out by cmj. – ClaboThe Carp routines are useful in your own modules because they act like die() or warn(), but with a message which is more likely to be useful to a user of your module.
Not very useful unless you personally use packages and can see the difference. – Clabo