Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
If you're writing object-oriented code, you should not be exporting anything. And you should sure as hell not be exporting new ever. Don't use the one argument form of bless - use the two argument form. It's more friendly to people wanting to subclass your classes...
Don't return undef to indicate a terminal failure. Just die with an error message. (Or better, Carp::croak or Carp::confess.)
Why? Mostly because it forces your caller to not ignore your error message. Right now you say you're calling your code like this...
... but really the caller shouldn't have to remember to detect errors and die. The die should just happen. (For this reason the default behaviour of many Perl built-ins, such as open, is pretty dumb. The autodie pragma fixes them.) If the caller is really sure they want to ignore coolobject failures, then they can always wrap the object construction in eval like this:
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
In reply to Re: How do I report an error back to the user of my object?
by tobyink
|
|