in reply to Re^4: SDLx handlers and Moose
in thread SDLx handlers and Moose

Why I must pass @_ to the sub when it was implicit before in this example:

The callbacks are function references. They're not methods; they have no invocants. SDL will invoke those references and pass the parameters it wants to them. SDL doesn't know you're using methods. SDL doesn't know which objects you want to use.

Because you want to call methods on objects, you have to give SDL callbacks which are closures which then invoke methods on your objects.

Because you're using that layer of indirection, you have to pass the arguments to your methods directly.

Replies are listed 'Best First'.
Re^6: SDLx handlers and Moose
by Ransom (Beadle) on May 29, 2012 at 12:09 UTC

    Ok so with this post and the post above, basically I'm declaring an anonymous sub with the closure (for the callback), and inside the closure I'm saying this is the object and method you need to use/pass args to.

    Hoping I've grasped this little bit of wisdom.

    Thanks for your help,

    Ransom

      Exactly. The callback won't remember the object unless you wrap the object up in a closure.