I love playing around with new toys. So, I'm ecstatic now that ColdFusion 9 has been officially released to the world, and even more so after what I'm about to tell you. Oh sure, I've been playing around with the betas, but mostly in testing the cfajax/ExtJs 3 upgrades (and I'll be posting more on that in the coming months). Time has been somewhat limited for me, so playtime has had to take a back burner. But, I wish I had gotten into this a bit sooner.
Yesterday I finally got around to working with some of the new cfscript implementations. I find these upgrades to be one of the key features for me personally. One, It's a faster coding style for me. Two, I was getting tired of bouncing between script and tags. Three, I really like the economy of code associated with script, finding it to be far less verbose. So, I'm lovin' the fact that I can write all of my CFC's, including my Application.cfc, in pure script. Now I can keep the tags with the display. But, as someone pointed out to me in a recent comment, there are still a few tags (anyone know which ones?) that haven't yet gotten script implementations. What can we do about that?
So, in diving right into playing with script enhancements, I ran into a few roadblocks. Minor errors, stemming from me not properly understanding the implementation. Now, the first place I went was to the documentation. Ray Camden keeps saying to me "Why don't people read the documentation?" I'm one of those that agrees with him. Yes, the documentation has some holes, and even bad examples, but you would be surpised what you can learn. (Read on, you'll see where I'm going with this!)
In discovering all of this wonderful new scripting, I came across Script Functions Implemented as CFCs in the new CF 9 CFML Reference. I was stepping through all of the subtopics, when I came upon this little tidbit:
Script functions are available in the following location: cf_root\CustomTags\com\adobe\coldfusion.I wasn't really surprised by this. Ray had recently alluded to this functionality in his recent post on Gotchas with Queries in Script. I just hadn't thought about it too much. Now, reading the above, a question had smacked me upside the head. Can we extend ColdFusion? Can we write our own "Script Functions Implemented as CFC's?" Basically create our own server plugins?
Ensure that you do not delete the default custom tag mapping listed in the ColdFusion Administrator (Extensions > Custom Tag Paths > Custom tag mappings).
Script functions work if they are either in the default location or web root. If you have the functions in any other location, add a /com mapping in the ColdFusion Administrator that points to the new location (for example C:\com).
Well, of course we can. We've been able to do that since CF 6, haven't we? Written CFC's, and used CreateObject()? Placed CFC instances into persistent scopes for broad access? Yes, we have. But I wondered if someone could write a script version of cfsavecontent, and instantiate it anywhere within the application using the new content(); type of syntax? So, I decided to do a little digging, and a little testing.
Side Note: You must have access to your ColdFusion file system to do the following.
The first thing to note, is that all of the functions mentioned, in that set of topics of the CFML Reference, are represented as CFC's inside the server's default CustomTags folder.
public com.adobe.coldfusion.query function init()
public com.cutterscrossing.coldfusion.myComponent function init()
REQUEST.him = new myComponent();
<cfsetting enablecfoutputonly="false" />
There are many different possible applications, from writing script versions for the few remaining tags, to creating your own scripted function objects (for instance: write a scripted function object for converting video to flv format). What do you think we could do with this?