in reply to objects becoming unblessed?

but the transition is never an Emitter object/instance to begin with, it's just an anonymous hash ref.

sub transitions { my $self = shift; if (@_) { $self->{TRANSITIONS} = shift; ....

Here you set the TRANSITION to the anonymous hash and here

... return $self->{TRANSITIONS};

You just return it.

-derby

update Please disregard and follow jand's advice.

Replies are listed 'Best First'.
Re: Re: objects becoming unblessed?
by jand (Friar) on Mar 17, 2003 at 17:42 UTC
    You are overlooking that the original code has both a transition() and a transitions() method, where only the code for the later has been provided. I was assuming that the former would choose a random transition from the hash, based on the transition probabilities. Obviously a hash is not a good data structure for this. A sorted array of arrays would allow to retrieve the original Emitter objects, and also provide for optimization of the random selection function. See the recent Weighted random numbers generator topic.
      Jand,

      I did miss the transitions and I agree about the data structure; however, if transitions is used to populate the data structure, it's not populating it with Emitter objects, but anonymous hashes. The transition (no s) used to move through the data structure, will need to create the objects (either via an object constructor or an initial blessing of the anon hash into the Emitter class).

      From the snippets provided, it appears the objects have not become unblessed but were never blessed in the first place.

      -derby

        You are missing one level of indirection. The objects are the keys of the unblessed hash (except that objects can't be keys). Look at the code again:
        $self->{START} = Emitter->new(); $self->{FAIR} = Emitter->new(); $self->{LOADED} = Emitter->new(); ... $self->{START}->transitions( { $self->{FAIR} => 0.5, $self->{LOADED} => 0.5 } );
        It does create 3 objects and then tries to set up 2 transitions using the anonymous hash. But the last line will already turn the object references into strings. It works as if it had been:
        $self->{START}->transitions( { "Emitter=HASH(0x12345678)" => 0.5, "Emitter=HASH(0xABCDABCD)" => 0.5 } );