We've just finished adding another feature to Model-Glue 3 called copyToScope(). This feature makes it easier to pull variables out of the event scope and place them into another scope. A big thanks to Paul Marcotte for suggesting this feature.
How does it work?
Say you want to pull 3 values from the event and use them in your view. Normally, you would run 3 separate commands:
<cfset hand = event.getValue("hand") />
<cfset xe.nested = event.getValue("xe.nested") />
Here in the labs of Model-Glue, we want to reduce developer excise when possible. The new copyToScope() method can be used to short cut the same process.
The end result is the exact same as above, except only 1 line of code is needed to pull several values from the event at once.
What about default values?
As event.getValue() takes an optional argument to set default values, our new friend event.copyToScope() will take an optional array of default values. The position of the list elements pertain to the position of the value in the array. This means the 1st value in the list gets the 1st position in the array, the 2nd gets the 2nd and so on. Let's look at an example where I want to provide defaults to 2 items in the list:
<cfset event.copyToScope(variables, "foot,hand,xe.nested", defaultArray) />
Once the function executes, the value of variables.foot is DefaultForFoot and the value for variables.hand is DefaultForHand. If no value existed in the event for xe.nested, it will be set to an empty string as per normal when a value is requested from the event that has not been set yet.
Does it only work with the variables scope?
Nope. It will work with any scope you see fit. Session, Server, Application, even a plain ole struct, though I expect the variables scope will be most often used.
Where can I get the code?
You can update from SVN at http://svn.firemoss.com/modelglue and try the feature out. Several bugs have also been fixed including a bug with Railo compatibility submitted by Denny Valliant. Thanks to Denny for his contribution.