in reply to Re^3: requiring pm modules
in thread requiring pm modules
Using the class method syntax will allow the symbolic reference even with strict, but it's still a symbolic reference. Instead, I would use can, as follows:
require Value; my $x = 'getValue'; if (my $coderef = Value->can($x)) { $coderef->(); }
This has several benefits. It does not add "Value" to the argument list, it does not use a symbolic reference, and it checks that the subroutine actually exists before trying to run it.
PS: for the curious, can is documented in UNIVERSAL.
|
|---|