in reply to Re^2: Missing object reference in sub
in thread Missing object reference in sub

I can't do what chromatic said because I do not have an $obj at the point. (Remember that the call to the Daemon constructor never returns.)

Sure you can. The closure has to bind to the lexical at compile time, but the object has to be valid at the point of the call, which is after the object creation. Add one line:

my $id; $id = Frontier::Daemon->new( ... );

... then use $id in the closure.

Replies are listed 'Best First'.
Re^4: Missing object reference in sub
by almut (Canon) on Sep 26, 2007 at 21:10 UTC

    ... but would $id ever get assigned something, if the constructor doesn't return?

      No, you're right. You need to create your own object anyway, not stuff the sum method in the Frontier::Daemon namespace, though.

Re^4: Missing object reference in sub
by Lazarus (Novice) on Sep 28, 2007 at 13:55 UTC

    Tried it. Got back error:

    Can't call method "sum" on an undefined value at line ...