J
JS Bangs
All,
I've got a module that will read an XML file that has code as the
contents of some elements. I'd like to be able to capture this code as a
code reference and pass that code reference to a function, without risking
any internals. The following code works, but doesn't seem foolproof:
# %code, $self, and $parse defined elsewhere
if (exists $code{$_}) {
my $c;
my $code = '$c = sub {' . $parse->{$_} . '}';
# Prevent $code from modifying in-scope variables we need to keep
{
local($self, $parse);
eval $code;
}
if ($@) {
err("Errors processing $_ : $@");
}
else {
$self->$_($c);
}
}
Suggestions very welcome.
--
Jesse S. Bangs (e-mail address removed)
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
Jesus asked them, "Who do you say that I am?"
And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."
And Jesus said, "What?"
I've got a module that will read an XML file that has code as the
contents of some elements. I'd like to be able to capture this code as a
code reference and pass that code reference to a function, without risking
any internals. The following code works, but doesn't seem foolproof:
# %code, $self, and $parse defined elsewhere
if (exists $code{$_}) {
my $c;
my $code = '$c = sub {' . $parse->{$_} . '}';
# Prevent $code from modifying in-scope variables we need to keep
{
local($self, $parse);
eval $code;
}
if ($@) {
err("Errors processing $_ : $@");
}
else {
$self->$_($c);
}
}
Suggestions very welcome.
--
Jesse S. Bangs (e-mail address removed)
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
Jesus asked them, "Who do you say that I am?"
And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."
And Jesus said, "What?"