switch translator hashref from public to protected
[catagits/catbook-code.git] / lib / LolCatalyst / Lite / Translator.pm
1 package LolCatalyst::Lite::Translator;
2
3 use Module::Pluggable::Object;
4
5 use Moose;
6 use namespace::clean -except => 'meta';
7
8 has 'default_target' => (
9   is => 'ro', isa => 'Str', required => 1, default => 'LOLCAT'
10 );
11
12 has '_translators' => (
13   is => 'ro', isa => 'HashRef', lazy_build => 1
14 );
15
16 sub _build__translators {
17   my ($self) = @_;
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;
30 }
31
32 sub translate {
33   my ($self, $text) = @_;
34   $self->translate_to($self->default_target, $text);
35 }
36
37 sub translate_to {
38   my ($self, $target, $text) = @_;
39   $self->_translators->{$target}->translate($text);
40 }
41
42 __PACKAGE__->meta->make_immutable;
43
44 1;