[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Wed Mar 5 17:38:19 UTC 2008


kawas
Wed Mar  5 12:38:19 EST 2008
Update of /home/repository/moby/moby-live/Perl/MOBY-Server/lib/MOBY/RDF
In directory dev.open-bio.org:/tmp/cvs-serv16210/Perl/MOBY-Server/lib/MOBY/RDF

Modified Files:
	Utils.pm 
Log Message:
helper method for downloading from a url
moby-live/Perl/MOBY-Server/lib/MOBY/RDF Utils.pm,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY-Server/lib/MOBY/RDF/Utils.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Perl/MOBY-Server/lib/MOBY/RDF/Utils.pm	2008/02/21 17:15:41	1.2
+++ /home/repository/moby/moby-live/Perl/MOBY-Server/lib/MOBY/RDF/Utils.pm	2008/03/05 17:38:19	1.3
@@ -91,19 +91,19 @@
 
 sub prettyPrintXML {
 	my ( $self, $hash ) = @_;
-	my $xml        = $hash->{xml};
-	unless ( $xml ) {
+	my $xml = $hash->{xml};
+	unless ($xml) {
 		$xml = <<END;
 	<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF>
 END
 	}
-	
+
 	eval "require XML::LibXSLT";
 	if ($@) {
-		my $parser     = XML::LibXML->new();
-		my $source     = $parser->parse_string($xml);
+		my $parser = XML::LibXML->new();
+		my $source = $parser->parse_string($xml);
 		$xml = $source->toString(0);
-		return $xml;    
+		return $xml;
 	} else {
 		my $parser     = XML::LibXML->new();
 		my $xslt       = XML::LibXSLT->new();
@@ -112,9 +112,42 @@
 		my $stylesheet = $xslt->parse_stylesheet($style_doc);
 		my $results    = $stylesheet->transform($source);
 		$xml = $stylesheet->output_string($results);
-		return  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>". $xml;
+		return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . $xml;
 	}
 }
 
+=head2 getHttpRequestByURL
+
+returns a scalar of text obtained from the url or dies if there was no success
+
+=cut
+
+sub getHttpRequestByURL {
+	my ( $self, $url ) = @_;
+	my $ua = LWP::UserAgent->new;
+	$ua->agent( "pMOBY/Central/1.0");
+
+	my $req =
+	  HTTP::Request->new( GET =>
+		  $url );
+
+	# accept gzip encoding
+	$req->header( 'Accept-Encoding' => 'gzip' );
+
+	# send request
+	my $res = $ua->request($req);
+
+	# check the outcome
+	if ( $res->is_success ) {
+		if ( $res->header('content-encoding') and $res->header('content-encoding') eq 'gzip' ) {
+			return $res->decoded_content;
+		} else {
+			return $res->content;
+		}
+	} else {
+		die "Error getting data from URL:\n\t" . $res->status_line;
+	}    
+}
+
 1;
 __END__




More information about the MOBY-guts mailing list