--- loncom/lonnet/perl/lonnet.pm	2001/11/16 06:21:39	1.169
+++ loncom/lonnet/perl/lonnet.pm	2001/11/20 22:30:20	1.174
@@ -35,8 +35,10 @@
 # 8/4,8/7,8/8,8/9,8/11,8/16,8/17,8/18,8/20,8/23,9/20,9/21,9/26,
 # 10/2 Gerd Kortemeyer
 # 10/5,10/10,11/13,11/15 Scott Harrison
+# 11/17 Gerd Kortemeyer
+#
+# $Id: lonnet.pm,v 1.174 2001/11/20 22:30:20 www Exp $
 #
-# $Id: lonnet.pm,v 1.169 2001/11/16 06:21:39 harris41 Exp $
 ###
 
 # Functions for use by content handlers:
@@ -1660,7 +1662,6 @@ sub definerole {
 
 sub metadata_query {
     my ($query,$custom,$customshow)=@_;
-    # need to put in a library server loop here and return a hash
     my %rhash;
     for my $server (keys %libserv) {
 	unless ($custom or $customshow) {
@@ -1746,6 +1747,7 @@ sub modifyuserauth {
     unless ($reply eq 'ok') {
 	return 'error: '.$reply;
     }   
+    return 'ok';
 }
 
 # --------------------------------------------------------------- Modify a user
@@ -2230,12 +2232,24 @@ sub EXT {
 # ---------------------------------------------------------------- Get metadata
 
 sub metadata {
-    my ($uri,$what)=@_;
+    my ($uri,$what,$liburi,$prefix)=@_;
 
     $uri=&declutter($uri);
     my $filename=$uri;
     $uri=~s/\.meta$//;
-    unless ($metacache{$uri.':keys'}) {
+#
+# Is the metadata already cached?
+# If "keys" are set, the assumption is that everything is already cached.
+# Everything is cached by the main uri, libraries are never directly cached
+#
+    unless (abs($metacache{$uri.':cachedtimestamp'}-time)<600) {
+#
+# Is this a recursive call for a library?
+#
+        if ($liburi) {
+	    $liburi=&declutter($liburi);
+            $filename=$liburi;
+        }
         my %metathesekeys=();
         unless ($filename=~/\.meta$/) { $filename.='.meta'; }
 	my $metastring=&getfile($perlvar{'lonDocRoot'}.'/res/'.$filename);
@@ -2245,10 +2259,17 @@ sub metadata {
         while ($token=$parser->get_token) {
            if ($token->[0] eq 'S') {
 	     if (defined($token->[2]->{'package'})) {
+#
+# This is a package - get package info
+#
 	      my $package=$token->[2]->{'package'};
 	      my $keyroot='';
-              if (defined($token->[2]->{'part'})) { 
-                 $keyroot.='_'.$token->[2]->{'part'}; 
+              if ($prefix) {
+		  $keyroot.='_'.$prefix;
+              } else {
+                if (defined($token->[2]->{'part'})) { 
+                   $keyroot.='_'.$token->[2]->{'part'}; 
+	        }
 	      }
               if (defined($token->[2]->{'id'})) { 
                  $keyroot.='_'.$token->[2]->{'id'}; 
@@ -2277,10 +2298,25 @@ sub metadata {
                   }
               } keys %packagetab;
              } else {
-	      my $entry=$token->[1];
+#
+# This is not a package - some other kind of start tag
+# 
+	     my $entry=$token->[1];
+             if ($entry eq 'import') {
+#
+# Importing a library here
+#
+                my $libid=$token->[2]->{'id'};
+
+              
+             } else { 
               my $unikey=$entry;
-              if (defined($token->[2]->{'part'})) { 
-                 $unikey.='_'.$token->[2]->{'part'}; 
+              if ($prefix) {
+		  $unikey.='_'.$prefix;
+              } else {
+                if (defined($token->[2]->{'part'})) { 
+                   $unikey.='_'.$token->[2]->{'part'}; 
+	        }
 	      }
               if (defined($token->[2]->{'id'})) { 
                  $unikey.='_'.$token->[2]->{'id'}; 
@@ -2297,10 +2333,15 @@ sub metadata {
 		      ) { $metacache{$uri.':'.$unikey}=
 			      $metacache{$uri.':'.$unikey.'.default'};
 		      }
-	    }
+# end of not-a-package not-a-library import
+	     }
+# end of not-a-package start tag
+	  }
+# the next is the end of "start tag"
 	 }
        }
        $metacache{$uri.':keys'}=join(',',keys %metathesekeys);
+       $metacache{$uri.':cachedtimestamp'}=time;
     }
     return $metacache{$uri.':'.$what};
 }