Updating my email address
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / Data / Serializer.pm
index 138fd36..71690f3 100644 (file)
@@ -1,6 +1,6 @@
 #
 # Catalyst::Action::Serialize::Data::Serializer
-# Created by: Adam Jacob, Marchex, <adam@marchex.com>
+# Created by: Adam Jacob, Marchex, <adam@hjksolutions.com>
 #
 # $Id$
 
@@ -16,9 +16,30 @@ sub execute {
     my $self = shift;
     my ( $controller, $c, $serializer ) = @_;
 
-    my $stash_key = $controller->serialize->{'stash_key'} || 'rest';
+    my $stash_key = (
+            $controller->config->{'serialize'} ?
+                $controller->config->{'serialize'}->{'stash_key'} :
+                $controller->config->{'stash_key'} 
+        ) || 'rest';
+    my $sp = $serializer;
+    $sp =~ s/::/\//g;
+    $sp .= ".pm";
+    eval {
+        require $sp
+    };
+    if ($@) {
+        $c->log->info("Could not load $serializer, refusing to serialize: $@");
+        return 0;
+    }
     my $dso = Data::Serializer->new( serializer => $serializer );
-    $c->response->output( $dso->raw_serialize( $c->stash->{$stash_key} ) );
+    my $data;
+    eval {
+       $data = $dso->raw_serialize($c->stash->{$stash_key});
+    };
+    if ($@) {
+        return $@;
+    } 
+    $c->response->output( $data );
     return 1;
 }