On Mon, Feb 04, 2002 at 08:02:10PM -0500, Ilya Zakharevich wrote:
> > > What about extending $class->can( qr// )?
> >
> > That would require significant alterations to the AUTOLOAD protocol.
> > perl6-language is down the hall, third door on your right.
>
> Hmm? All it requires is to change UNIVERSAL::can() to check for a
> REx, and scan the symbol table if needed.
Oh, I thought you ment it as a solution to the "how do you figure out
what methods are available when there's an AUTOLOAD around" issue.
Sure, you could write a little module to do that.
> Then if a module wants run-time conscience in presense of run-time
> effects, it would just define its own ->can().
I've done things like that. The situtation was where I wanted to make
delegation look like inheritence to the outside world.
package BBoard::Post;
sub new {
...
# So BBoard::Post hasa BBoard::Message
$self->{message} = BBoard::Message->new(...);
...
}
sub AUTOLOAD {
...
# Hand off anything we can't handle to the BBoard::Message
$self->{message}->$method(@args);
...
}
# Fake it so if someone asks $post->isa('BBoard::Message')
# we say yes.
sub isa {
my($self, $class) = @_;
$self->SUPER::isa($class) || $self->{message}->isa($class);
}
# Fake it so if someone asks for $post->can('some_message_meth')
# we say yes.
sub can {
my($self, $meth) = @_;
$self->SUPER::can($meth) || $self->{message}->can($meth);
}
--
Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/
Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One
Lord of Kwalitee! Wearer of the CPANTS and Slayer of Pseudo-hashes!