refactor translator to driver based system
Matt S Trout [Fri, 6 Feb 2009 17:33:22 +0000 (17:33 +0000)]
lib/LolCatalyst/Lite/Translator.pm

index 3aeb7de..3088d8d 100644 (file)
@@ -1,6 +1,36 @@
 package LolCatalyst::Lite::Translator;
 
 use Moose;
+use namespace::clean -except => 'meta';
+
+has 'default_target' => (
+  is => 'ro', isa => 'Str', required => 1, default => 'LOLCAT'
+);
+
+has 'translators' => (
+  is => 'ro', isa => 'HashRef', lazy_build => 1
+);
+
+sub _build_translators {
+  my ($self) = @_;
+  return { LOLCAT => LolCatalyst::Lite::Translator::LOLCAT->new };
+}
+
+sub translate {
+  my ($self, $text) = @_;
+  $self->translate_to($self->default_target, $text);
+}
+
+sub translate_to {
+  my ($self, $target, $text) = @_;
+  $self->translators->{$target}->translate($text);
+}
+
+__PACKAGE__->meta->make_immutable;
+
+package LolCatalyst::Lite::Translator::LOLCAT;
+
+use Moose;
 use Acme::LOLCAT ();
 use namespace::clean -except => 'meta';