Listing 1: assert.cfm
<!-- assert.cfm -->
<!-- hal.helms@TeamAllaire.com -->
<!---
|| Responsibilities: First, I make sure that
I'm supposed to be checking assertions. If so, then I check the assertions
sent to me to ensure that all assertions are TRUE. If any assertions fail,
I CFTHROW an error back to the calling page.
||
-->
||
END FUSEDOC--->
<cfoutput>
<!---@COMMENT: If testAssertions was turned
off, then return without doing anything.--->
<cfparam name="request.testAssertions"
default="TRUE">
<cfif NOT request.testAssertions>
<cfexit method="EXITTAG">
</cfif>
<!---@COMMENT: Make sure an assertion was
sent to me.--->
<cftry>
<cfparam name="attributes.assertion">
<cfcatch>
<cfset caller.assert = "FALSE: No assertion
provided">
</cfcatch>
</cftry>
<!---@COMMENT: Loop over the assertions,
getting a handle on each variable/assertion pair--->
<cfloop list="#attributes.assertion#"
index="variableAssertion" delimiters="#chr( 10 )#">
<!---...then separate the pair into
various components--->
<cfset varSection = Trim( GetToken(
variableAssertion, 1, ':' ) )>
<cfset varName = Trim( ListFirst(
varSection, ' ' ) )>
<cfset varAlias = Trim( ListLast(
varSection, ' ' ) )>
<cfset assertionSection = Trim(
GetToken( variableAssertion, 2, ':' ) )>
<!---...substitute the variable
names for the aliases--->
<cfloop list="#assertionSection#"
index="anAssertion" delimiters=";">
<cfset assertion = ReplaceNoCase(
anAssertion, '|#varAlias#|', 'caller.#varName#', 'ALL' )>
<!---...and if an assertion fails,
throw the bum out.--->
<cfif NOT ( Evaluate( Trim ( assertion
) ) )>
<cfthrow type="FailedAssertion"
message="The assertion #assertion# failed">
</cfif>
</cfloop>
</cfloop>
</cfoutput>