refactor translator to driver based system
[catagits/catbook-code.git] / lib / LolCatalyst / Lite / Translator.pm
1 package LolCatalyst::Lite::Translator;
2
3 use Moose;
4 use namespace::clean -except => 'meta';
5
6 has 'default_target' => (
7   is => 'ro', isa => 'Str', required => 1, default => 'LOLCAT'
8 );
9
10 has 'translators' => (
11   is => 'ro', isa => 'HashRef', lazy_build => 1
12 );
13
14 sub _build_translators {
15   my ($self) = @_;
16   return { LOLCAT => LolCatalyst::Lite::Translator::LOLCAT->new };
17 }
18
19 sub translate {
20   my ($self, $text) = @_;
21   $self->translate_to($self->default_target, $text);
22 }
23
24 sub translate_to {
25   my ($self, $target, $text) = @_;
26   $self->translators->{$target}->translate($text);
27 }
28
29 __PACKAGE__->meta->make_immutable;
30
31 package LolCatalyst::Lite::Translator::LOLCAT;
32
33 use Moose;
34 use Acme::LOLCAT ();
35 use namespace::clean -except => 'meta';
36
37 sub translate {
38   my ($self, $text) = @_;
39   return Acme::LOLCAT::translate($text);
40 }
41
42 __PACKAGE__->meta->make_immutable;
43
44 1;