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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 02 Nov 2004 22:13:13 -0000


albertel		Tue Nov  2 17:13:13 2004 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - add ability to (c)put/(e)get/(current)dump to handle perl data structures,
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.556 loncom/lonnet/perl/lonnet.pm:1.557
--- loncom/lonnet/perl/lonnet.pm:1.556	Tue Nov  2 15:48:02 2004
+++ loncom/lonnet/perl/lonnet.pm	Tue Nov  2 17:13:13 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.556 2004/11/02 20:48:02 albertel Exp $
+# $Id: lonnet.pm,v 1.557 2004/11/02 22:13:13 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -48,7 +48,7 @@
 use HTML::LCParser;
 use Fcntl qw(:flock);
 use Apache::lonlocal;
-use Storable qw(lock_store lock_nstore lock_retrieve freeze thaw);
+use Storable qw(lock_store lock_nstore lock_retrieve freeze thaw nfreeze);
 use Time::HiRes qw( gettimeofday tv_interval );
 my $readit;
 my $max_connection_retries = 10;     # Or some such value.
@@ -2515,7 +2515,7 @@
    my %returnhash=();
    my $i=0;
    foreach (@$storearr) {
-      $returnhash{$_}=unescape($pairs[$i]);
+      $returnhash{$_}=&thaw_unescape($pairs[$i]);
       $i++;
    }
    return %returnhash;
@@ -2554,7 +2554,7 @@
    my %returnhash=();
    foreach (@pairs) {
       my ($key,$value)=split(/=/,$_);
-      $returnhash{unescape($key)}=unescape($value);
+      $returnhash{unescape($key)}=&thaw_unescape($value);
    }
    return %returnhash;
 }
@@ -2600,7 +2600,7 @@
            my ($key,$value)=split(/=/,$_);
            my ($symb,$param) = split(/:/,$key);
            $returnhash{&unescape($symb)}->{&unescape($param)} = 
-                                                          &unescape($value);
+                                                        &thaw_unescape($value);
        }
    }
    return %returnhash;
@@ -2666,7 +2666,7 @@
    my $uhome=&homeserver($uname,$udomain);
    my $items='';
    foreach (keys %$storehash) {
-       $items.=&escape($_).'='.&escape($$storehash{$_}).'&';
+       $items.=&escape($_).'='.&freeze_escape($$storehash{$_}).'&';
    }
    $items=~s/\&$//;
    return &reply("put:$udomain:$uname:$namespace:$items",$uhome);
@@ -2705,7 +2705,7 @@
    my $uhome=&homeserver($uname,$udomain);
    my $items='';
    foreach (keys %$storehash) {
-       $items.=escape($_).'='.escape($$storehash{$_}).'&';
+       $items.=escape($_).'='.&freeze_escape($$storehash{$_}).'&';
    }
    $items=~s/\&$//;
    return &critical("put:$udomain:$uname:$namespace:$items",$uhome);
@@ -2728,7 +2728,7 @@
    my %returnhash=();
    my $i=0;
    foreach (@$storearr) {
-      $returnhash{$_}=unescape($pairs[$i]);
+      $returnhash{$_}=&thaw_unescape($pairs[$i]);
       $i++;
    }
    return %returnhash;
@@ -5254,6 +5254,15 @@
     return $thisfn;
 }
 
+sub freeze_escape {
+    my ($value)=@_;
+    if (ref($value)) {
+	$value=&nfreeze($value);
+	return '__FROZEN__'.&escape($value);
+    }
+    return &escape($value);
+}
+
 # -------------------------------------------------------- Escape Special Chars
 
 sub escape {
@@ -5270,6 +5279,16 @@
     return $str;
 }
 
+sub thaw_unescape {
+    my ($value)=@_;
+    if ($value =~ /^__FROZEN__/) {
+	substr($value,0,10,undef);
+	$value=&unescape($value);
+	return &thaw($value);
+    }
+    return &unescape($value);
+}
+
 sub mod_perl_version {
     if (defined($perlvar{'MODPERL2'})) {
 	return 2;