Created
July 12, 2011 13:59
-
-
Save hideo55/1078021 to your computer and use it in GitHub Desktop.
モジュールの動的ロードとメソッドの呼び出し
This file contains 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
use strict; | |
use warnings; | |
use Class::Load qw(load_class); | |
my $module_name = 'MY::MODULE::NAME'; | |
#Moose::Util::load_class()とほぼ同等、ロードに失敗すると例外を投げる | |
load_class($module_name); | |
#can()はCodeRefを返す | |
if( my $method = $module->can('method1') ){ | |
#この方が安全 | |
$method->($arg1,$arg2, ... ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment