Created
November 3, 2012 22:18
-
-
Save xenoterracide/4009088 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # this works | |
| use Class::Load 0.20 'load_class'; | |
| my $var = 'baz'; | |
| my $class = 'Foo::Bar'; | |
| my $result = load_class( $class )->class_method( $var ); # works wonders with ->new | |
| # sometimes this will work, but not always. Try this with the various Dumper functions and see which ones work. | |
| use Module::Load 'load'; | |
| my $package = 'Foo::Bar'; | |
| load $package, 'function'; | |
| my $result = function( $var ); # seems to only work if Foo::Bar's exporter works right, many packages have to be exported at compile time not runtime | |
| # perl doesn't like stuff like this or really anything where I've tried substituting the package name into calling a function. at least not with strict on. This is a large reason I'd avoid functional interfaces. They are hard to substitute at runtime. Maybe I just don't know a good way to do it, without disabling strict, feel free to enlighten me. | |
| load( $package ); | |
| my $function = $package . '::' . 'function'; | |
| $function->( $var ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment