[pve-devel] r5056 - pve-common/trunk

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Aug 26 08:52:37 CEST 2010


Author: dietmar
Date: 2010-08-26 06:52:37 +0000 (Thu, 26 Aug 2010)
New Revision: 5056

Modified:
   pve-common/trunk/ChangeLog
   pve-common/trunk/README.dev
   pve-common/trunk/RESTHandler.pm
Log:
	* README.dev: update docu about find_handler() 

	* RESTHandler.pm (find_handler): use '$path' instead of strange
	'$stack' parameter.



Modified: pve-common/trunk/ChangeLog
===================================================================
--- pve-common/trunk/ChangeLog	2010-08-25 13:37:21 UTC (rev 5055)
+++ pve-common/trunk/ChangeLog	2010-08-26 06:52:37 UTC (rev 5056)
@@ -1,3 +1,10 @@
+2010-08-26  Proxmox Support Team  <support at proxmox.com>
+
+	* README.dev: update docu about find_handler() 
+
+	* RESTHandler.pm (find_handler): use '$path' instead of strange
+	'$stack' parameter.
+
 2010-08-25  Proxmox Support Team  <support at proxmox.com>
 
 	* Exception.pm (raise_param_exc): allow to specify usage information.

Modified: pve-common/trunk/README.dev
===================================================================
--- pve-common/trunk/README.dev	2010-08-25 13:37:21 UTC (rev 5055)
+++ pve-common/trunk/README.dev	2010-08-26 06:52:37 UTC (rev 5056)
@@ -97,8 +97,46 @@
 
 Note:: This uses Getopt::Long to parse parameters.
 
-The 'path' property is used by the HTTP servers to setup the URL.
+There is a second way to map names to methods - using the 'path'
+property.  And you can register subclasses. That way you can set up a
+filesystem like hierarchy to access methods. 
 
+Here is an example:
+----------------------------
+package C1;
+
+__PACKAGE__->register_method ({
+    subclass => "C2",  
+    path => 'sub2',
+});
+
+
+__PACKAGE__->register_method ({
+    name => 'list1',    
+    path => 'index',
+    method => 'GET',
+    ...
+});
+
+package C2;
+
+__PACKAGE__->register_method ({
+    name => 'list2',    
+    path => 'index',
+    method => 'GET',
+    ...
+});
+-------------------------------
+
+The utily method find_handler (in PVE::RESTHandler) can be use to do
+'path' related method lookups.
+
+C1->find_handler('GET', "/index")      => C1::list1
+C1->find_handler('GET', "/sub2/index") => C2::list2
+
+The HTTP server use the URL (a path) to find the corresponding method. 
+
+
 References
 ==========
 [1] RESTful Web Services

Modified: pve-common/trunk/RESTHandler.pm
===================================================================
--- pve-common/trunk/RESTHandler.pm	2010-08-25 13:37:21 UTC (rev 5055)
+++ pve-common/trunk/RESTHandler.pm	2010-08-26 06:52:37 UTC (rev 5056)
@@ -133,7 +133,7 @@
     }
 }
 
-sub find_handler {
+sub __find_handler_full {
     my ($class, $method, $stack, $uri_param) = @_;
 
     my $info;
@@ -163,10 +163,18 @@
 	    $stack = [ join ('/', @$stack) ] if scalar(@$stack) > 1;
 	}
 
-	return $subh->find_handler($method, $stack, $uri_param);
+	return $subh->__find_handler_full($method, $stack, $uri_param);
     }
 
     return ($class, $info);
+};
+
+sub find_handler {
+    my ($class, $method, $path, $uri_param) = @_;
+
+    my $stack = [ grep { length($_) > 0 }  split('\/+' , $path)]; # skip empty fragments
+
+    return $class->__find_handler_full($method, $stack, $uri_param);
 }
 
 sub handle {



More information about the pve-devel mailing list