switch translator hashref from public to protected
[catagits/catbook-code.git] / lib / LolCatalyst / Lite / Translator.pm
CommitLineData
bc61dfc2 1package LolCatalyst::Lite::Translator;
2
a9517e99 3use Module::Pluggable::Object;
63ed6b50 4
bc61dfc2 5use Moose;
80304984 6use namespace::clean -except => 'meta';
7
8has 'default_target' => (
9 is => 'ro', isa => 'Str', required => 1, default => 'LOLCAT'
10);
11
836279c9 12has '_translators' => (
80304984 13 is => 'ro', isa => 'HashRef', lazy_build => 1
14);
15
836279c9 16sub _build__translators {
80304984 17 my ($self) = @_;
a9517e99 18 my $base = __PACKAGE__;
19 my $mp = Module::Pluggable::Object->new(
20 search_path => [ $base ]
21 );
22 my @classes = $mp->plugins;
23 my %translators;
24 foreach my $class (@classes) {
25 Class::MOP::load_class($class);
26 (my $name = $class) =~ s/^\Q${base}::\E//;
27 $translators{$name} = $class->new;
28 }
29 return \%translators;
80304984 30}
31
32sub translate {
33 my ($self, $text) = @_;
34 $self->translate_to($self->default_target, $text);
35}
36
37sub translate_to {
38 my ($self, $target, $text) = @_;
836279c9 39 $self->_translators->{$target}->translate($text);
80304984 40}
41
42__PACKAGE__->meta->make_immutable;
43
bc61dfc2 441;