in reply to Should a constructor ever return undef?

Mail::Sender (the newest version) allows you to specify what kind of error reporting do you want. It can either throw an exception (die), return an undef or return a negative error number. This of course affects all methods of the created object as well. Therefore the caller can use whatever feels best for him:

eval { my $sender = Mail::Sender->new({on_errors => 'die', ...}); $sender->Open({...}); ... $sender->Close(); }; die "Failed to send the email: $@\n" if $@; #or my $sender = Mail::Sender->new({on_errors => 'undef', ...}) or die "Failed to send the email: failed creating the object - $Mail +::Sender::Error\n" $sender->Open({...}) or die "Failed to send the email: $Mail::Sender::Error\n" ... $sender->Close() or die "Failed to send the email: $Mail::Sender::Error\n"; #or ...
You can do something similar.

Anyway ... I would not want some object to print whetever error messages it pleases into the STDOUT. I would not want them in the STDERR either, but even that would be better.

Jenda
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
   -- Rick Osborne

Edit by castaway: Closed small tag in signature