A follow-up to my last post... adding this line to the render func:

$tmpl =~ s/__\((.*?)\)__/<%=($1)%>/gm; # fixup embedded tests

Allows this construct to be used:

__(__F_ONSALE__?'YES':'NO')__

These constructs also work as expected:

Item on sale? Yes or No:
__(__F_ONSALE__?'YES':'NO')__

Item NOT on sale? Yes or No:
__(!__F_ONSALE__?'YES':'NO')__

Price > 5? Yes or No
__(__AMT_PRICE__>5?'YES':'NO')__

Item on Sale? Sale Price or Reg Price:
__(__F_ONSALE__?__AMT_SALE__:__AMT_PRICE__)__

Here is the complete render func to date:

sub render { ## process a body-template string and render appropriately
        my ($tmpl, $hash, $fmt) = @_;
        $tmpl =~ s/__\[(.*?)\]__/<$1>/gm; # fixup delayed-embedded xmlsubs
        $tmpl =~ s/__\((.*?)\)__/<%=($1)%>/gm; # fixup embedded tests
        while ($tmpl =~ /__(.*?)__/) {
                my $TOKEN = $1; my $token = lc($TOKEN);
                if ((my $fmt = $$fmt{$TOKEN}) ne undef) {
                        # to-uppercase
                        if ($fmt =~ /^%uc/i) { $fmt =~ s/[^0-9]//gm; 
$$hash{$tok
en} = uc(substr($$hash{$token}, 0, $fmt || length($$hash{$token}))); }
                        # to-lowercase
                        elsif ($fmt =~ /^%lc/i) { $fmt =~ s/[^0-9]//gm; 
$$hash{$
token} = lc(substr($$hash{$token}, 0, $fmt || length($$hash{$token}))); }
                        # picture
                        else { $$hash{$token} = sprintf($fmt, $$hash{$token}); 
}
                        }
                $tmpl =~ s/__${TOKEN}__/$$hash{$token}/gme;
                }
        $Response->Include(\$tmpl);
        }

__END__


This is getting cool :) 

John





-- 

--------------------------------------------------------------------------------
Check out http://www.Wizard.Org for great deals on Electronic Parts
*NEW* Computer Parts & Accessories - Drives - LCD - Systems - Linux
--------------------------------------------------------------------------------
** Affordable Online Store w/Merchant Card Processing & Paypal **
Write to us: [EMAIL PROTECTED]  --  Get your Store Online Today!
--------------------------------------------------------------------------------





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to