steffen: server/perl-kolab/Kolab-Conf Conf.pm,1.63,1.64

cvs at intevation.de cvs at intevation.de
Mon Oct 3 03:07:00 CEST 2005


Author: steffen

Update of /kolabrepository/server/perl-kolab/Kolab-Conf
In directory doto:/tmp/cvs-serv25849/Kolab-Conf

Modified Files:
	Conf.pm 
Log Message:
Changed the template expansion code to make it easier to add new expansion "modifiers"

Index: Conf.pm
===================================================================
RCS file: /kolabrepository/server/perl-kolab/Kolab-Conf/Conf.pm,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- Conf.pm	17 Sep 2005 14:21:23 -0000	1.63
+++ Conf.pm	3 Oct 2005 01:06:58 -0000	1.64
@@ -260,32 +260,50 @@
             ($skip > 0) && $skip--;
             s/\@{3}endif\@{3}\n?//;
         } else {
-            while (/\@{3}(\S+?)(\|.+?)?\@{3}/) {
-                my $attr = $1;
-                my $opt  = $2;
-                #print STDERR "attr=$attr, opt=$opt\n";
-                if ($Kolab::config{$attr}) {
-                    my $val = "";
-                    if (ref $Kolab::config{$attr} eq "ARRAY") {
-                        if ($opt && $opt =~ /\|join(.*)/) {
-                            $val = join $1, @{$Kolab::config{$attr}};
-                        } else {
-                            $val = $Kolab::config{$attr}->[0];
-                        }
-                    } else {
-                        $val = $Kolab::config{$attr};
-                    }
-                    s/\@{3}(\S+?)(\|.+?)?\@{3}/$val/;
-		    last if ( $val eq "\@\@\@$attr\@\@\@" ); # prevent endless loop
-                } else {
-                    Kolab::log('T', "No configuration variable corresponding to `$1' exists", KOLAB_WARN);
-                    s/\@{3}(\S+?)\@{3}//;
-                }
-            }
-        }
-        ($skip == 0) && print $config $_;
-    }
-
+            while (/\@{3}(\S+?)(\|(.+?)\((.*)\))?\@{3}/) {
+	      my $attr = $1;
+	      my $fct  = $3;
+	      my $args = $4;
+	      #print STDERR "attr=\"$attr\", fct=\"$fct\", args=\"$args\"\n";
+	      if ($Kolab::config{$attr}) {
+		my $val = "";
+		if( !$fct ) {
+		  if (ref $Kolab::config{$attr} eq "ARRAY") {
+		    $val = $Kolab::config{$attr}->[0];
+		  } else {
+		    $val = $Kolab::config{$attr};
+		  }
+		} else {
+		  # Modifier functions
+		SWITCH: {
+		    # Join function
+		    $fct eq 'join' && do {
+		      $val = join $args, (ref $Kolab::config{$attr} eq "ARRAY")
+			?@{$Kolab::config{$attr}}
+			  :($Kolab::config{$attr});
+		      last SWITCH;
+		    };
+		    # Quote function
+		    $fct eq 'quote' && do {
+		      # slapd.conf compatible quoting
+		      $val = $Kolab::config{$attr};
+		      $val =~ s/"/\"/g;
+		      $val = '"'.$val.'"';
+		      last SWITCH;
+		    }
+		  }
+		}
+		s/\@{3}(\S+?)(\|.+?)?\@{3}/$val/;
+		last if ( $val eq "\@\@\@$attr\@\@\@" ); # prevent endless loop
+	      } else {
+		Kolab::log('T', "No configuration variable corresponding to `$1' exists", KOLAB_WARN);
+		s/\@{3}(\S+?)\@{3}//;
+	      }
+	    }
+	    ($skip == 0) && print $config $_;
+	  }
+      }
+	
     $template->close;
     $config->close;
 





More information about the commits mailing list