[ic] $Tag->price() [calc] re-entrancy problems

Peter peter at pajamian.dhs.org
Mon Aug 24 04:55:57 UTC 2009

Ok, here is the issue.  I often times do something like this in
CommonAdjust:  "&($item->{code} =~ /^FOO/ ? '-30%' : '0')"

Basically that is a quick way to discount every product with a sku that
begins with FOO by 30%.  This has worked great for me in the past ...
Until I came up with a situation where I needed to call the price tag
from inside an [item-calc] in order to determine if an item is on sale
... I do this:

if ($Row->{price} > $Tag->price({code=$Row->{code}, noformat => 1})) {
	# Some code to run if item is on sale here.

The idea above is that I can't use [item-price] because I need to see
what the price for the code would be without any options applied.
Anyways, now here's the problem ... the [price] tag ends up calling
tag_calc() when there is an atom in the CommonAdjust that starts with &.
 This results in a calc re-entrancy issue, and I end up with the
following in my error.log:
Safe: 'eval "string"' trapped by operation mask at (tag 'calcn') line 1.
>       (in cleanup) Undefined subroutine &main:: called at
/usr/local/perl-5.8.8/lib/5.8.8/x86_64-linux/Safe.pm line 236.

Interestingly you can get the exact same error if you attempt to do this:
$Tag->calc({body => 'return "foo";'});

Ok, so the issue boils down to this.  I need to find a way to either
make [calc] re-entrant (is there an opcode I can SafeUntrap to make it
work?) or I need to find another way to be able to do what I'm trying to
do.  Any suggestions?


More information about the interchange-users mailing list