Skip to content

Instantly share code, notes, and snippets.

@hideo55
Created July 12, 2011 13:59
Show Gist options
  • Save hideo55/1078021 to your computer and use it in GitHub Desktop.
Save hideo55/1078021 to your computer and use it in GitHub Desktop.
モジュールの動的ロードとメソッドの呼び出し
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