Yesterday I posted a reminder that ColdFusion 11 developers can stop using the old "CFCs for Tags" feature that provided support for certain things in script. I mentioned that everything could be used in cfscript now and that the old CFCs were (sometimes, not always) a bit buggy.
Brad Wood suggested I actually provide an example of this and I thought it was a good idea. I wrote up two quick demos that demonstrate the new syntax. This isn't super deep or anything, but hopefully it gives you a basic idea of how this new syntax looks. First, an example of a few different tags:
cfhttp(url="http://www.cnn.com",result="cnnReq");
writeDump(cnnReq.responseHeader);
cfhttp(url="http://www.cnn.com",result="cnnReq",method="post") {
cfhttpparam(type="formfield",name="something",value=createUUID());
}
writeDump(cnnReq.responseHeader);
cfsearch(collection="test1", criteria="cat", name="searchResults");
writeDump(searchResults);
cffeed(action="read", source="http://feeds.feedburner.com/raymondcamdensblog", query="feed");
writeDump(feed);
Make note of how you can't use a result (ie, foo = goo()) in any of these calls and instead use an argument. That could be easily fixed and should be. Second, note how child tags are handled in the second cfhttp call. I don't have anything to add to it, but as I said, just note the syntax.
For the heck of it, I then wrote a second demo. This one takes an array of RSS URLs and uses cfthread to fetch them in parallel. It then merges the resultant queries and sorts them. A mini-aggregator if you will.
feeds = ["http://feeds.feedburner.com/raymondcamdensblog","http://www.cflib.org/rss","http://feeds.feedburner.com/ColdfusionbloggersorgFeed"];
threads = [];
//for each feed, use a thread to fetch rss
feeds.each(function(f,x) {
var name = "get_#x#";
threads.append(name);
cfthread(name=name,feed=f) {
cffeed(action="read", source=attributes.feed, query="feed");
thread.feed = feed;
}
});
cfthread(action="join",name=threads.toList());
//copy thread queries out and create sql merge statement
sql = "";
feeds.each(function(f,x) {
variables["feed#x#"] = cfthread["get_#x#"].feed;
if(x > 1) {
sql &= " union ";
}
sql &= "select * from feed#x#";
});
merged = queryExecute(sql,{},{dbtype:"query"});
//credit Vince Collins: https://vincentcollins.wordpress.com/2008/02/22/cffeed-dont-forget-you-can-cast-the-resulting-query-column/
merged = queryExecute("select content, title, rsslink, cast(publisheddate as date) as publisheddate from merged order by publisheddate desc", {}, {dbtype:"query"});
writedump(var=merged,top=20);
I hope this helps!