----- Original Message ----

> From: Eric Wilhelm <enoba...@gmail.com>

> Or:
> 
>   define(bar => sub {...});
> 
> Yeah, that forces syntax to be rather widespread.
> 
> I always seem to want to be able to install something like a UNITCHECK 
> block into caller from import().  Alas.
> 
> And anyway, the attributes implementation can probably be made to do 
> wrapping for run-time checking and various other features.
> 
> How does Perl 6 (or some other language) do (or allow for) this?

Regrettably, no matter how much I play with the syntax, I can't get something 
that's really convenient short of attributes and those aren't terribly popular 
(and they're problematic since they aren't Perl code).  Schwern's 
Method::Signatures might work as users have already "drunk the Kool-Aid", but 
since Perl 5 doesn't offer us great support here, it's quite reasonable that 
he'll reject this, though I have added it as a Wishlist item:  
http://rt.cpan.org/Public/Bug/Display.html?id=43943

I could implement this with with INIT and using MRO::Compat and 
mro::get_pkg_gen() to determine when a method cache is invalid (that way, you 
can cache whether a method overrides something and refresh the cache as 
needed), but it fails with AUTOLOAD and other methods of delayed installation 
of methods into a symbol table. Also, INIT will fail with persistent code such 
as modperl.

C++ handles this by requiring methods which can be overridden to be declared as 
"virtual".  Unfortunately, it doesn't provide any syntax in the derived classes 
to make it clear you're overriding a method.  This is a huge pitfall in C++ 
because if Child and Parent both provide "munge" and "acquire" methods and the 
parent class only marks "munge" as virtual, you might accidentally call 
Parent::acquire if you have the wrong pointer type:

  http://developer.kde.org/~wheeler/cpp-pitfalls.html

 
C# is a bit more sane about this.  Parent classes must declare overrideable 
methods as virtual and child classes must mark methods as "override" or "new" 
(this hides the parent method even if it's not declared virtual):

  http://www.akadia.com/services/dotnet_polymorphism.html

C# is great in this respect because you can look at a definition of a method 
and get a lot more information about what's going on.

I suspect we'll have to wait until Perl 6 to get this handled cleanly.

Cheers,
Ovid
--
Buy the book         - http://www.oreilly.com/catalog/perlhks/
Tech blog            - http://use.perl.org/~Ovid/journal/
Twitter              - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6

Reply via email to