Author: spadkins
Date: Wed Apr 25 12:41:40 2007
New Revision: 9453

Modified:
   p5ee/trunk/App-Context/lib/App/Service.pm

Log:
add the undef_value option

Modified: p5ee/trunk/App-Context/lib/App/Service.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Service.pm   (original)
+++ p5ee/trunk/App-Context/lib/App/Service.pm   Wed Apr 25 12:41:40 2007
@@ -363,7 +363,7 @@
 
 sub substitute {
     &App::sub_entry if ($App::trace);
-    my ($self, $text, $values) = @_;
+    my ($self, $text, $values, $options) = @_;
     my ($phrase, $var, $value, $context, $default);
     $context = $self->{context};
     $values = {} if (! defined $values);
@@ -373,12 +373,14 @@
         $hash = $text;    # oops, not text, but a hash of text values
         $newhash = {};    # prepare a new hash for the substituted values
         foreach $var (keys %$hash) {
-            $newhash->{$var} = $self->substitute($hash->{$var}, $values);
+            $newhash->{$var} = $self->substitute($hash->{$var}, $values, 
$options);
         }
         &App::sub_exit($newhash) if ($App::trace);
         return($newhash); # short-circuit this whole process
     }
 
+    my $undef_value = (defined $options->{undef_value}) ? 
$options->{undef_value} : "";
+
     # looking for patterns like the following: {user} {user:Guest}
     while ( $text =~ /\{([^\{\}:]+)(:[^\{\}]+)?\}/ ) {  # vars of the form 
{var}
         $var = $1;
@@ -397,7 +399,7 @@
             $value = $default;
         }
         elsif (!defined $value) {
-            $value = "";
+            $value = $undef_value;
         }
         $text =~ s/\{$var(:[^\{\}]+)?\}/$value/g;
     }

Reply via email to