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

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Aug 13 10:46:04 CEST 2010


Author: dietmar
Date: 2010-08-13 08:46:04 +0000 (Fri, 13 Aug 2010)
New Revision: 4997

Modified:
   pve-common/trunk/ChangeLog
   pve-common/trunk/JSONSchema.pm
Log:
(check_format): make it possible to automagically check comman
	separated lists.


Modified: pve-common/trunk/ChangeLog
===================================================================
--- pve-common/trunk/ChangeLog	2010-08-13 08:38:03 UTC (rev 4996)
+++ pve-common/trunk/ChangeLog	2010-08-13 08:46:04 UTC (rev 4997)
@@ -2,6 +2,8 @@
 
 	* JSONSchema.pm (register_format): implement a way to register
 	'format' verification methods.
+	(check_format): make it possible to automagically check comman
+	separated lists.
 
 2010-08-12  Proxmox Support Team  <support at proxmox.com>
 

Modified: pve-common/trunk/JSONSchema.pm
===================================================================
--- pve-common/trunk/JSONSchema.pm	2010-08-13 08:38:03 UTC (rev 4996)
+++ pve-common/trunk/JSONSchema.pm	2010-08-13 08:46:04 UTC (rev 4997)
@@ -5,6 +5,7 @@
 use Storable; # for dclone
 use Getopt::Long;
 use Devel::Cycle -quiet; # fixme: remove?
+use PVE::Tools qw(split_list);
 use Data::Dumper; # fixme: remove
 
 # Note: This class implements something similar to JSON schema, but it is not 100% complete. 
@@ -26,11 +27,23 @@
 sub check_format {
     my ($format, $value) = @_;
 
-    my $code = $format_list->{$format};
+    if ($format =~ m/^(.*)-list$/) {
+	
+	my $code = $format_list->{$1};
 
-    die "undefined format '$format'\n" if !$code;
+	die "undefined format '$format'\n" if !$code;
 
-    &$code($value);
+	foreach my $v (split_list($value)) {
+	    &$code($v);
+	}
+    } else {
+
+	my $code = $format_list->{$format};
+
+	die "undefined format '$format'\n" if !$code;
+
+	&$code($value);
+    }
 } 
 
 sub add_error {




More information about the pve-devel mailing list