fix up code to 404
[catagits/catbook-code.git] / lib / LolCatalyst / Lite / Translator.pm
index ca6c22b..8832943 100644 (file)
@@ -3,19 +3,20 @@ package LolCatalyst::Lite::Translator;
 use Module::Pluggable::Object;
 
 use Moose;
+use aliased 'LolCatalyst::Lite::Interface::TranslationDriver';
 use namespace::clean -except => 'meta';
 
 has 'default_target' => (
   is => 'ro', isa => 'Str', required => 1, default => 'LOLCAT'
 );
 
-has 'translators' => (
+has '_translators' => (
   is => 'ro', isa => 'HashRef', lazy_build => 1
 );
 
-sub _build_translators {
+sub _build__translators {
   my ($self) = @_;
-  my $base = __PACKAGE__;
+  my $base = __PACKAGE__.'::Driver';
   my $mp = Module::Pluggable::Object->new(
     search_path => [ $base ]
   );
@@ -23,6 +24,9 @@ sub _build_translators {
   my %translators;
   foreach my $class (@classes) {
     Class::MOP::load_class($class);
+    unless ($class->does(TranslationDriver)) {
+      confess "Class ${class} in ${base}:: namespace does not implement Translation Driver interface";
+    }
     (my $name = $class) =~ s/^\Q${base}::\E//;
     $translators{$name} = $class->new;
   }
@@ -34,9 +38,14 @@ sub translate {
   $self->translate_to($self->default_target, $text);
 }
 
+sub can_translate_to {
+  my ($self, $target) = @_;
+  return exists $self->_translators->{$target};
+}
+
 sub translate_to {
   my ($self, $target, $text) = @_;
-  $self->translators->{$target}->translate($text);
+  $self->_translators->{$target}->translate($text);
 }
 
 __PACKAGE__->meta->make_immutable;