Piers Cawley writes: > So, I was wondering about how to do multidispatch based on the > context in which something is called, which leads me to wonder if > there's going to be a way of reifying calling context so I could > write: > > method whatever($arg1, $arg2) > { my multi whatever ($self, Scalar $context: > $arg1, $arg2) { ... } > my multi whatever ($self, Array $context: > $arg1, $arg2) { ... } > whatever($_, want(), $arg1, $arg2) }
The way I see that happening is if we allow certain kinds of constants in multi declarations. my multi whatever ($self, Class $context is derived(Scalar): $arg1, $arg2) {...} That'd be nice in a number of different ways. Without this special feature, an enabling level of indirection can be added with parameterized types: my class ClassVal [Class $TYPE] { # Does nothing, and may even be optimized away } my multi whatever ($self, ClassVal[Scalar] $context: $arg1, $arg2) {...} # ... whatever($_, ClassVal[want], $arg1, $arg2); # ^ does a : go here? That doesn't handle inheritance correctly, but it can be made to, provided proper introspection into $TYPE. Luke