Last active
December 15, 2015 14:29
-
-
Save ichigotake/5274782 to your computer and use it in GitHub Desktop.
Yanchaプラグインのオートローダー
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
| package Yancha::Plugin::PluginAutoloader; | |
| use strict; | |
| use warnings; | |
| sub setup { | |
| my ($class, $sys) = @_; | |
| my %config; | |
| for my$plugin( @{$sys->config->{ plugins }} ) { | |
| my ($plugin_class, $plugin_args) = @{$plugin}; | |
| $config{ $plugin_class } = $plugin_args; | |
| } | |
| my $plugin_dir = 'lib/Yancha/Plugin'; | |
| my $autoload_plugins = []; | |
| for my$path( glob("$plugin_dir/*\.pm") ) { | |
| next unless $path =~ m|$plugin_dir/(.+)\.pm$|; | |
| my $plugin = "Yancha::Plugin::$1"; | |
| #自分自身を呼んでも意味無し | |
| next if $plugin eq $class; | |
| #configが存在するならコアで読み込み済みなはず | |
| next if exists $config{ $plugin }; | |
| push $autoload_plugins, [$plugin]; | |
| } | |
| $sys->load_plugins( $autoload_plugins ); | |
| } | |
| 1; | |
| __DATA__ | |
| =encoding utf8 | |
| =head1 NAME | |
| Yancha::Plugin::PluginAutoload - Yanchaプラグインのオートローダー | |
| =head1 SYNOPSIS | |
| #config.ini | |
| ... | |
| 'plugins' => [ | |
| [ 'Yancha::Plugin::PluginAutoloader' ], | |
| ... | |
| =head1 DESCRIPTION | |
| このプラグインを読み込むとI<lib/Yancha/Plugin/*.pm>のプラグインが(I<config.ini>に設定が無いものも含めて)全て自動で読み込まれます | |
| =head1 SEE ALSO | |
| https://github.com/uzulla/yancha | |
| =head1 AUTHOR | |
| @ichigotake |
Author
添削ありがとうございます!
指摘通りにリファクタしました
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
やっぱりダメだ。
とりあえず.pmのドットはすべにマッチの意味では使ってないはずなので、エスケープで。