If you do this, you may want to provide a new
can() method for people to use:
# can - Help UNIVERSAL::can() cope with our AUTOLOADed methods
sub can
{
my ($self, $method) = @_;
my $subref = $self->SUPER::can($method);
return $subref if $subref; # can found it; it's a real method
# Method doesn't currently exist; should it, though?
return unless exists $self->{$method};
# Return an anon sub that will work when it's eventually called
sub {
my $self = $_[0];
# The method is being called. The real method may have been
# created in the meantime; if so, don't call AUTOLOAD again
my $subref = $self->SUPER::can($method);
goto &$subref if $subref;
$AUTOLOAD=$method;
goto &AUTOLOAD
};
}
(This one assumes that people will often call can()
without intending to use the method ref it returns,
and so it defers calling AUTOLOAD until someone goes
to use it. Because of this, it needs a second
check to see if someone else has already AUTOLOADed
the desired method in the meantime.)
-
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.
|