Another option is to have a $self->{ERRORSTR} property that can be obtained via "sub errorstr{}" method.
It should default to the empty string.
Update: On second thoughts, it should also be available as a CLASS method - perhaps setup a private Class variable (our $ERRORSTR), that can be accessed via $ClassName::ERRORSTR
This would be necessary/useful in the event that the "new" method failed to instantiate an object.
I could see coding a method like this:
our $ERRORSTR="";
sub new{
... on failure, $ERRORSTR="*KAPUT*: Monkeywrench in our NEW method";
}
sub OtherMethod{
.. on error, $self->{ERRORSTR}="*KAPUT* I really hate that parameter
+ you tried to pass to me";
return -1;
}
sub errorstr{ # Both class, and Instance Method
my ($self)=@_;
ref $self or return $ERRORSTR; # Class call
return defined ($self->{ERRORSTR}) ? $self->{ERRORSTR} : $ERRORSTR;
}
Update> Add "ref" to sub errorstr, based on tobylink and polymorpheus's comments below.
I hope life isn't a big joke, because I don't get it.
-SNL
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|