diff options
author | elliott_c <ocielliottc@users.noreply.github.com> | 2005-04-04 17:28:48 +0000 |
---|---|---|
committer | elliott_c <ocielliottc@users.noreply.github.com> | 2005-04-04 17:28:48 +0000 |
commit | 5e39c912e065184e85d61f28267ababa9e3e0060 (patch) | |
tree | 1a819d73eca53c8e0b7be910ee485d115abc7517 | |
parent | 17f8902351766f3eb19dbceea8ee48bc0a306836 (diff) | |
download | MPC-5e39c912e065184e85d61f28267ababa9e3e0060.tar.gz |
ChangeLogTag: Mon Apr 4 12:27:14 2005 Chad Elliott <elliott_c@ociweb.com>
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | modules/TemplateParser.pm | 45 |
2 files changed, 54 insertions, 1 deletions
@@ -1,3 +1,13 @@ +Mon Apr 4 12:27:14 2005 Chad Elliott <elliott_c@ociweb.com> + + * modules/TemplateParser.pm: + + Added a new template function, 'starts_with', that takes two + parameters. The first parameter is a template variable and the + second is a literal string. If the value of the template variable + starts with the literal string, then starts_with evaluates to + true. + Fri Apr 1 12:39:12 2005 Chad Elliott <elliott_c@ociweb.com> * templates/em3vcp.mpd: diff --git a/modules/TemplateParser.pm b/modules/TemplateParser.pm index ad82b735..ee72d312 100644 --- a/modules/TemplateParser.pm +++ b/modules/TemplateParser.pm @@ -53,6 +53,7 @@ my(%keywords) = ('if' => 0, 'sort' => 2, 'uniq' => 3, 'multiple' => 5, + 'starts_with' => 5, ); # ************************************************************ @@ -578,6 +579,48 @@ sub handle_multiple { } +sub get_starts_with { + my($self) = shift; + my($str) = shift; + return $self->doif_starts_with([$str]); +} + + +sub doif_starts_with { + my($self) = shift; + my($val) = shift; + + if (defined $val) { + my($str) = "@$val"; + if ($str =~ /([^,]+)\s*,\s*(.*)/) { + my($name) = $1; + my($pattern) = $2; + if (defined $name && defined $pattern) { + return ($self->get_value_with_default($name) =~ /^$pattern/); + } + } + } + return undef; +} + + +sub handle_starts_with { + my($self) = shift; + my($str) = shift; + + if (defined $str) { + my($val) = $self->doif_starts_with([$str]); + + if (defined $val) { + $self->append_current($val); + } + else { + $self->append_current(0); + } + } +} + + sub perform_reverse { my($self) = shift; my($value) = shift; @@ -698,7 +741,7 @@ sub process_compound_if { $val = $str; foreach my $cmd (reverse @cmds) { - if (($keywords{$cmd} & $type) != 0) { + if (defined $keywords{$cmd} && ($keywords{$cmd} & $type) != 0) { my($func) = "$prefix$cmd"; $val = $self->$func($val); |