From: Matt S Trout Date: Fri, 6 Feb 2009 18:18:58 +0000 (+0000) Subject: refactor translator to use Module::Pluggable to find child classes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2Fcatbook-code.git;a=commitdiff_plain;h=a9517e99fba6d832252e46ba7d6c1ec3724e9314;hp=63ed6b503b569a6b146f746ebf8fde02488b2edf refactor translator to use Module::Pluggable to find child classes --- diff --git a/lib/LolCatalyst/Lite/Translator.pm b/lib/LolCatalyst/Lite/Translator.pm index 7dd978e..ca6c22b 100644 --- a/lib/LolCatalyst/Lite/Translator.pm +++ b/lib/LolCatalyst/Lite/Translator.pm @@ -1,6 +1,6 @@ package LolCatalyst::Lite::Translator; -use LolCatalyst::Lite::Translator::LOLCAT; +use Module::Pluggable::Object; use Moose; use namespace::clean -except => 'meta'; @@ -15,7 +15,18 @@ has 'translators' => ( sub _build_translators { my ($self) = @_; - return { LOLCAT => LolCatalyst::Lite::Translator::LOLCAT->new }; + my $base = __PACKAGE__; + my $mp = Module::Pluggable::Object->new( + search_path => [ $base ] + ); + my @classes = $mp->plugins; + my %translators; + foreach my $class (@classes) { + Class::MOP::load_class($class); + (my $name = $class) =~ s/^\Q${base}::\E//; + $translators{$name} = $class->new; + } + return \%translators; } sub translate {