Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^5: Runtime introspection: What good is it?

by chromatic (Archbishop)
on Jul 07, 2008 at 21:23 UTC ( [id://696105]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^6: Runtime introspection: What good is it?
by stvn (Monsignor) on Jul 08, 2008 at 06:18 UTC
    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
Re^6: Runtime introspection: What good is it?
by lodin (Hermit) on Jul 08, 2008 at 19:35 UTC

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://696105]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found