Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: safe and $self

by feanor_269 (Beadle)
on Nov 26, 2002 at 23:11 UTC ( #215964=note: print w/replies, xml ) Need Help??


in reply to Re: safe and $self
in thread safe and $self

I finally signed up for an account (instead of just lurking), so I'm the anonymous monk that posted this node. the code I have is:
sub codewrapper { my $self = shift; $self->{code}->share('$self'); $self->{code}->share('$test'); $code=$_[0]; $self->{code}->reval($code); $test->{code}->reval($code); }
$test is the test object, and that gives the same error, it is declared with my $test = ..., but outside of any subs. neither work, both produce eval errors.

Replies are listed 'Best First'.
Re: Re: Re: safe and $self
by djantzen (Priest) on Nov 27, 2002 at 02:09 UTC
Re^3: safe and $self
by tadman (Prior) on Nov 27, 2002 at 05:57 UTC
    I think, like what fever said, that you've painted yourself in to a corner with this. $self is a lexical variable, in other words, it doesn't really exist outside of the codewrapper function, those seven lines.

    The real problem is if you are ever calling the codewrapper function within itself. Then you're going to have trouble sharing the correct $self since there will, at that point, be two of them.

    The solution might be to not use Safe at all. It might be best to re-engineer your application, since using eval, and presumably reval are much slower than the alternatives.

    If this isn't going to work, then what you're probably going to have to do is create separate compartments for each object. I'm not sure if there's an easy way to do this or not.
      Unfortunately, since I have to eval perl code from untrusted sources (this would be for a mud, and they would be the builders and imms... see what I mean by untrustworthy?) I have to use safe and reval. speed isn't horribly important either. I'm going to play with making an array of the references to each object and just sharing that locally (Altho maybe just as a package variable?) anyway, class, no time now.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://215964]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2020-12-01 00:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?