in reply to Calling $function from $module

The equivalent of
$invocant->$method_name( @args )
is
($module.'::'.$function_name)->( @args ) # Perl 5.6+
or
&{ $module.'::'.$function_name }( @args )

use strict qw( refs ); forbids these (as it should), so you can use the following:

my $ref = do { no strict qw( refs ); \&{ $module.'::'.$function_name } }; $ref->( @args )

Except it turns out that \&{...} is exempt from strict reference enforcement, so you can simply use

my $ref = \&{ $module.'::'.$function_name }; $ref->( @args )

or even

( \&{ $module.'::'.$function_name } )->( @args )

This trick to bypass strict reference enforcement is not documented.

Replies are listed 'Best First'.
Re^2: Calling $function from $module
by stevieb (Canon) on Aug 05, 2015 at 23:11 UTC
    "These tricks to by pass strict reference enforcement are not documented."

    Nor should they be, imho.

      These aren't tricks and they are documented

      Also Symbol::qualify_to_ref

        I stand corrected. However, I still feel there are better ways than working around no strict 'refs';
        Fixed the claim that it's not documented, but I still think that "trick" is an appropriate description of "contortion performed to do something you requested to be prevented from doing".
Re^2: Calling $function from $module
by Anonymous Monk on Aug 06, 2015 at 00:13 UTC
    Thank you so much -- this is great!