factor LOLCAT translator out into its own file
[catagits/catbook-code.git] / lib / LolCatalyst / Lite / Translator.pm
1 package LolCatalyst::Lite::Translator;
2
3 use LolCatalyst::Lite::Translator::LOLCAT;
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   return { LOLCAT => LolCatalyst::Lite::Translator::LOLCAT->new };
19 }
20
21 sub translate {
22   my ($self, $text) = @_;
23   $self->translate_to($self->default_target, $text);
24 }
25
26 sub translate_to {
27   my ($self, $target, $text) = @_;
28   $self->translators->{$target}->translate($text);
29 }
30
31 __PACKAGE__->meta->make_immutable;
32
33 1;