[Rt-commit] [svn] r882 - in RTx-Atom: . html/Atom/0.3

autrijus at pallas.eruditorum.org autrijus at pallas.eruditorum.org
Wed May 12 22:00:29 EDT 2004


Author: autrijus
Date: Wed May 12 22:00:29 2004
New Revision: 882

Modified:
   RTx-Atom/   (props changed)
   RTx-Atom/html/Atom/0.3/dhandler
Log:
 ----------------------------------------------------------------------
 r4826 at not:  autrijus | 2004-05-13T02:00:20.091063Z
 
 * use WebPath, not absolute path.
 * redirect appended !METHOD too.
 * allow for by-name object reference.
 * allow for negatice indice, eg. /*-1.
 ----------------------------------------------------------------------


Modified: RTx-Atom/html/Atom/0.3/dhandler
==============================================================================
--- RTx-Atom/html/Atom/0.3/dhandler	(original)
+++ RTx-Atom/html/Atom/0.3/dhandler	Wed May 12 22:00:29 2004
@@ -186,7 +186,9 @@
 
 my $path = $m->dhandler_arg;
 $path =~ s{/+(?:index\.html)?$}{}g;
-$method = $1 if $path =~ s/!(\w+)$//;
+
+my $user_method;
+$method = $user_method = $1 if $path =~ s/!(\w+)$//;
 
 my ($type, @parts) = grep length, split('/', $path);
 $type =~ s{-}{::}g;
@@ -202,7 +204,7 @@
 my $map;
 $map = $m->comp('Elements/Introspect', Want => 'TopLevelCollections') if $type;
 
-my $BaseURI = $RT::WebURL."Atom/0.3";
+my $BaseURI = "$RT::WebPath/Atom/0.3";
 
 my $class;
 foreach my $key (@$map) {
@@ -221,6 +223,7 @@
 	$path = join('/', $type, @parts);
 	my $query = $m->comp('/Elements/QueryString', $m->request_args);
 	$query = "?$query" if length $query;
+	$path .= "!$user_method" if $user_method;
 	$r->header_out(Location => "$BaseURI/$path$query");
 	return $m->comp('Elements/Error', Status => 301);
     }
@@ -257,28 +260,30 @@
 $list->UnLimit;
 
 my $obj;
-$obj = $list if $property;
 
 foreach my $part (@parts) {
-    if ($part =~ /^(\*)?(\d+)(?:\.(\w+))?$/) {
-        my $id = $2;
-	$property = $3;
-
-	if ($1) {
-	    if ($2 > 0) {
-		$list->GotoItem($2-1);
-		$obj = $list->Next;
+    if ($part =~ /^(\*(-)?)?(\d+)(?:\.(\w+))?$/) {
+        my $id = $2 . $3;
+	$property = $4;
+
+	if ($1 and $id) {
+	    if ($id < 0) {
+		$obj = $list->ItemsArrayRef->[$id];
 	    }
 	    else {
-		undef $obj;
+		$list->GotoItem($id-1);
+		$obj = $list->Next;
 	    }
 	}
 	else {
 	    $obj = $list->NewItem;
 	    $obj->Load($id);
 	}
-
-	return $m->comp('Elements/Error', Status => 404) unless $obj and $obj->Id;
+    }
+    elsif ($part =~ /^(\w*)(?:\.(\w+))?$/ and !$obj) {
+	$property = $2;
+	$obj = $list->NewItem;
+	$obj->Load($1);
     }
     elsif ($part =~ /^([A-Z]\w*)(?:\.(\w+))?$/) {
 	$list = $obj->$1;
@@ -291,10 +296,16 @@
 	    $property = $obj = undef;
 	}
     }
+
+    return $m->comp('Elements/Error', Status => 404)
+	if $obj and $obj->can('Id') and !$obj->Id;
+
     # Can't allow cache to happen at all
     eval { $obj->_expire( $obj->_gen_primary_cache_key()) };
 }
 
+$obj ||= $list if $property;
+
 my $resource = ($obj ? $property ? 'Property' : 'Object' : 'Container');
 
 # Can't allow cache to happen at all


More information about the Rt-commit mailing list