in reply to Re^6: How can I call a Perl sub with an object from a sub name stored in a var?
in thread How can I call a Perl sub with an object from a sub name stored in a var?
It seems you are right. Any defined-but-non-coderef value is stringified if used as a method. You can even use an unblessed arrayref or hashref as a method name.
use strict; use warnings; use feature 'say'; my $method = []; { package Local::Class; sub new { my ( $class ) = ( shift ); bless {}, $class; } no strict 'refs'; *{"$method"} = sub { say for @$method }; }; my $object = 'Local::Class'->new(); @$method = ( "Hello", "world" ); $object->$method;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: How can I call a Perl sub with an object from a sub name stored in a var?
by LanX (Saint) on Dec 10, 2020 at 11:39 UTC | |
by tobyink (Canon) on Dec 10, 2020 at 12:05 UTC |