[Jifty-commit] r7033 - jifty/branches/webservices-in-td/lib/Jifty/Web

Jifty commits jifty-commit at lists.jifty.org
Wed May 13 14:48:05 EDT 2009


Author: alexmv
Date: Wed May 13 14:48:05 2009
New Revision: 7033

Modified:
   jifty/branches/webservices-in-td/lib/Jifty/Web/Services.pm

Log:
Refactor common code

Modified: jifty/branches/webservices-in-td/lib/Jifty/Web/Services.pm
==============================================================================
--- jifty/branches/webservices-in-td/lib/Jifty/Web/Services.pm	(original)
+++ jifty/branches/webservices-in-td/lib/Jifty/Web/Services.pm	Wed May 13 14:48:05 2009
@@ -10,11 +10,9 @@
 use Jifty::JSON;
 use Jifty::YAML;
 
-sub json {
+sub _results {
     my $self = shift;
 
-    Jifty->handler->apache->content_type("text/x-json");
-
     my %results = Jifty->web->response->results;
     for (values %results) {
         $_ = $_->as_hash;
@@ -22,22 +20,19 @@
         # backwards compatibility :(
         $_->{_content} = delete $_->{content};
     }
-    Jifty->web->out( Jifty::JSON::objToJson(\%results) );
+    return \%results;
 }
 
-sub yaml {
+sub json {
     my $self = shift;
+    Jifty->handler->apache->content_type("text/x-json");
+    Jifty->web->out( Jifty::JSON::objToJson( $self->_results ) );
+}
 
+sub yaml {
+    my $self = shift;
     Jifty->handler->apache->content_type("text/x-yaml");
-
-    my %results = Jifty->web->response->results;
-    for (values %results) {
-        $_ = $_->as_hash;
-
-        # backwards compatibility :(
-        $_->{_content} = delete $_->{content};
-    }
-    Jifty->web->out( Jifty::YAML::Dump(\%results) );
+    Jifty->web->out( Jifty::YAML::Dump( $self->_results ) );
 }
 
 sub xml {


More information about the Jifty-commit mailing list