[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

foxr lon-capa-cvs-allow@mail.lon-capa.org
Tue, 26 Feb 2008 10:39:46 -0000


foxr		Tue Feb 26 05:39:46 2008 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  BZ 5631: If ssi is called in array context, then return a 2 element list
  consisting of the content and the full response so the caller can analyze
  status and implement a retry/error-recovery policy of it's choice.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.943 loncom/lonnet/perl/lonnet.pm:1.944
--- loncom/lonnet/perl/lonnet.pm:1.943	Sun Feb 24 17:59:17 2008
+++ loncom/lonnet/perl/lonnet.pm	Tue Feb 26 05:39:44 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.943 2008/02/24 22:59:17 raeburn Exp $
+# $Id: lonnet.pm,v 1.944 2008/02/26 10:39:44 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1692,15 +1692,17 @@
 #  fn     Possibly encrypted resource name/id.
 #  form   Hash that describes how the rendering should be done
 #         and other things.
-#  r      Optional reference that will be given the response.
-#         This is mostly provided so that the caller can implement
-#         error detection, recovery and retry policies.
+# Returns:
+#   Scalar context: The content of the reply.
+#   Array context:  2 element list of the content and the full response variable.
 #     
 # Returns:
 #    The content of the response.
 sub ssi {
 
-    my ($fn,%form, $r)=@_;
+    my ($fn,%form)=@_;
+    my $count = scalar(@_);
+    
 
     my $ua=new LWP::UserAgent;
     
@@ -1717,12 +1719,13 @@
 
     $request->header(Cookie => $ENV{'HTTP_COOKIE'});
     my $response=$ua->request($request);
+    my $status = $response->code;
 
-    if ($r) {
-	$$r = $response;
+    if (wantarray) {
+	return ($response->content, $response);
+    } else {
+	return $response->content;
     }
-
-    return $response->content;
 }
 
 sub externalssi {