introspection (and Perl 6)

Ovid publiustemp-londonpm at
Sun Jan 20 20:04:14 GMT 2008

--- jesse <jesse at> wrote:

 > > features as any other modern programming language.
> > 
> > *cough*introspection*cough* :)
> You can certainly introspect Perl, if you're willing to sweet-talk
> her enough.

Introspection isn't build into Perl is, at best, heuristic in nature.
You can take a look inside namespaces, but that's only part of it.  For

  my $method = $class->can('foo');
There are several problems with that (some of which the current Perl 6
specification shares).  With the following code:

  if ( my $method = $class->can('foo') ) {
      my $hashref = $class->$method($arrayref);

You have no way of knowing:

  1.  If that's a method or a function.
  2.  If that's a class or an instance method.
  3.  If it really returns a hash reference.
  4.  The number and type of arguments it accepts.

So let's say you have this:

  package My::Class;
  use HTML::Entities 'encode_entities';

With that code, My::Class->can('encode_entities') returns a reference
to the encode_entities subroutine.  You can't call it like a method,
nor can you determine its signature.  Perl's introspective capabilities
are virtually non-existent.

Of course, if we don't ignore AUTOLOAD, then we're faced with the
problem of needing to override 'can' ...

The fact that Perl 6's introspection model is also broken is also
worrisome for me (

  if my $method = $class.^can('foo') {

Now we at least are guaranteed that it's a method, but none of the
other problems are solved (actually, the class versus instance one
might, but I can't tell from the docs).  Meta-programming seems broken
in Perl 6 :(


Buy the book  -
Perl and CGI  -
Personal blog -
Tech blog     -

More information about the mailing list