factor LOLCAT translator out into its own file
[catagits/catbook-code.git] / lib / LolCatalyst / Lite / Translator.pm
CommitLineData
bc61dfc2 1package LolCatalyst::Lite::Translator;
2
63ed6b50 3use LolCatalyst::Lite::Translator::LOLCAT;
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
12has 'translators' => (
13 is => 'ro', isa => 'HashRef', lazy_build => 1
14);
15
16sub _build_translators {
17 my ($self) = @_;
18 return { LOLCAT => LolCatalyst::Lite::Translator::LOLCAT->new };
19}
20
21sub translate {
22 my ($self, $text) = @_;
23 $self->translate_to($self->default_target, $text);
24}
25
26sub translate_to {
27 my ($self, $target, $text) = @_;
28 $self->translators->{$target}->translate($text);
29}
30
31__PACKAGE__->meta->make_immutable;
32
bc61dfc2 331;