in reply to Re^3: Runtime introspection: What good is it?
in thread Runtime introspection: What good is it?

That's the reason why Perl 6 has a pluggable object model that allows introspection - if something is missing or gone wrong, it's relatively easy to add, fix or replace afterwards.

s/Perl 6/Perl/

Perl 5 may not be as sexy as Perl 6, but it has just as flexible an object model, otherwise I would have never been able to write Moose or prototype the p6 model in it, not to mention all the Class:: stuff on CPAN that others have written.

-stvn
  • Comment on Re^4: Runtime introspection: What good is it?

Replies are listed 'Best First'.
Re^5: Runtime introspection: What good is it?
by chromatic (Archbishop) on Jul 07, 2008 at 21:23 UTC
    Perl 5 may not be as sexy as Perl 6, but it has just as flexible an object model...

    I'm less convinced. The facts that SUPER:: is broken in Perl 5 (it doesn't respect dynamic scoping) and that you can't tell a method from a subroutine make Perl 5 OO slightly more difficult to manage.

      SUPER:: is broken in Perl

      Check out SUPER, it might help you there ;)

      you can't tell a method from a subroutine

      Yeah I agree that is annoying too, however it is possible to get some stuff. For instance, in Moose we differentiate between exported subs from another package and subs defined in that package. Then there is also stuff like MooseX::Method which make it easier to "tag" methods and therefore tell them apart.

      But yeah in the end I will agree there are some broken parts to Perl 5 OO model, but the fact that I can fix most of them and provide a decent hack to work around or at least minimize the others is a pretty good. Try that in Java/C#/etc.

      -stvn

      For your own code you can use attributes (experimental feature) to signal what's a method and what's not.

      sub foo :method { my $self = shift; # ... return; } sub bar { # ... return; } use attributes; sub is_a_method { scalar grep $_ eq 'method', attributes::get($_[0]); } for ([ foo => \&foo ], [ bar => \&bar ]) { print "$_->[0] is a " . (is_a_method($_->[1]) ? 'method' : 'function +') . "\n"; } __END__ foo is a method bar is a function

      lodin