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

Do you mean
$self->{RESPONSE} = $self->{UA}->$methodref( $url, $att{VALUE} ? (Content => + to_json($att{VALUE})) : (), );
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Better syntax for dynamic method on internal object ?
by NetWallah (Canon) on Sep 24, 2015 at 02:48 UTC
    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.

      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.

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