Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree w/ tpryan. ColdSpring makes this very easy. However, here is another alternative. Instead of parsing the stack trace, you can parse the CFC file itself.</p> <pre><code>&lt;cffunction name="foo" displayname="foo" hint="this is just a test function" access="public" returntype="string"&gt; &lt;cfset var test = getFunctionName(getMetaData().path, getPageContext().getCurrentLineNo()) /&gt; &lt;cfreturn test /&gt; &lt;/cffunction&gt; &lt;cffunction name="getFunctionName" hint="returns the function name based on the line number" access="public" returntype="string"&gt; &lt;cfargument name="filepath" type="string" required="true" /&gt; &lt;cfargument name="linenum" type="any" required="true" /&gt; &lt;cfset var line = "" /&gt; &lt;cfset var functionName = "" /&gt; &lt;cfset var i = 1 /&gt; &lt;!---- loop over CFC by line ----&gt; &lt;cfloop file="#ARGUMENTS.filepath#" index="line"&gt; &lt;cfif findNoCase('cffunction', line, 1)&gt; &lt;cfset functionName = line /&gt; &lt;/cfif&gt; &lt;cfif i EQ ARGUMENTS.linenum&gt;&lt;cfbreak /&gt;&lt;/cfif&gt; &lt;cfset i++ /&gt; &lt;/cfloop&gt; &lt;!---- parse function name ----&gt; &lt;cfset functionName = REMatchNoCase("(\bname=[""|'])+[a-z]*[""|']", functionName) /&gt; &lt;cfset functionName = REMatchNoCase("[""']+[a-z]*[""']", functionName[1]) /&gt; &lt;cfset functionName = ReReplaceNoCase(functionName[1], "[""']", "", "all") /&gt; &lt;!---- return success ----&gt; &lt;cfreturn functionName /&gt; &lt;/cffunction&gt; </code></pre> <p>The above is written for ColdFusion 8. CFLOOP added support for looping over files line by line (and doesn't read the entire file into memory). I did a few tests comparing the stack trace method vs. file parsing. Both performed equally well on a small CFC being called directly from a single CFM template. Obviously if you have very large CFCs the parsing method might be a bit slower. On the other hand, if you have a large stack trace (like if you are using any of the popular frameworks) then file parsing may be faster.</p> <p><strong>-= Viva ColdFusion =-</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload