in reply to Re: Better syntax for dynamic method on internal object ?
in thread Better syntax for dynamic method on internal object ?

No - I did not mean that.

Your code would require a method NAME, not a subref, which is what I get from "can".

My query was about how to call the subref in an OO-esque way.

        Software efficiency halves every 18 months, thus compensating for Moore's Law.

  • Comment on Re^2: Better syntax for dynamic method on internal object ?

Replies are listed 'Best First'.
Re^3: Better syntax for dynamic method on internal object ?
by choroba (Cardinal) on Sep 24, 2015 at 08:14 UTC
    It works with a sub ref returned from can for me:
    #!/usr/bin/perl use warnings; use strict; use feature qw{ say }; { package My::Url; sub new { my $class = shift; bless {@_}, $class } sub url { my ($self, $node_id) = @_; $self->{url} . '?node_id=' . $node_id } } my $o = 'My::Url'->new(url => 'http://www.perlmonks.org/'); my $methodname = 'url'; my $methodref = $o->can($methodname); say $o->$methodref(1142751);

    But even if it didn't, you know the name, right? You used it as the argument to can.

    Update: It's documented.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ