cf_plumber

cf_plumber

Version: 1.0 build 20040416
Requires: Adobe ColdFusion 5.0 or greater
Total size: 3.33 KB
Download time: 0.59 seconds at 56kbps
Edition: Freeware

Description

This tool analyses your code for any leaking variables. The report lists any variables that seem to have been created, deleted, or changed between the opening and closing cf_plumber tags. This can be a handy way of checking that your functions and CFCs are declaring and scoping their variables properly. Note: Query record sets seem to generate different WDDX markup once they have been the subject of a query-of-queries, so may appear below spuriously if you are using query-of-queries.

Result

Displays a results table.

Category

debugging

Parameters


No parameters

Custom tag source


 
<!---**
* cf_plumber
* Analyse your code for any leaking variables. Designed for debugging purposes 
* only. Requires a closing tag, takes no parameters.
* 
* @result Displays a report table
* @author Matthew Walker, WWW.eswsoftware.com
* @version 1, 2004-04-16
*--->

<cfif thisTag.executionMode eq "start">

  <cfif not thisTag.hasEndTag>
    <cfthrow message="cf_plumber requires a closing tag.">
  </cfif>
  <cfset before = duplicate(caller)>
  <cfparam name="request.eswsoftware" default="#structNew()#">
  <cfparam name="request.eswsoftware.plumber" default="#structNew()#">
  <cfset request.eswsoftware.plumber.version = 1>
  
<cfelse>

  <cfset after = duplicate(caller)>
  <cfset leaks = "">
  <cfset allKeys = structNew()>
  <cfloop collection="#before#" item="key">
    <cfset allKeys[key] = "">
  </cfloop>
  <cfloop collection="#after#" item="key">
    <cfset allKeys[key] = "">
  </cfloop>

  <cfloop collection="#allKeys#" item="key">
    
    <cfset message = "">
    
    <cfif structKeyExists(before, key)>
      <cfif structKeyExists(after, key)>
        <cfwddx action="CFML2WDDX" input="#before[key]#" output="beforeVar" usetimezoneinfo="no">
        <cfwddx action="CFML2WDDX" input="#after[key]#" output="afterVar" usetimezoneinfo="no">
        <cfif hash(beforeVar) neq hash(afterVar)>
          <cfset message = "Changed">
        </cfif>
      <cfelse>
        <cfset message = "Deleted">
      </cfif>
    <cfelse>
      <cfset message = "Created">
    </cfif>
    
    <cfif len(message)>
      <cfsavecontent variable="leak">
        <tr valign="top">
          <td>
            <cfoutput>#key#</cfoutput>
          </td>
          <td>
            <cfoutput>#message#</cfoutput>
          </td>
          <td>
            <cfif structKeyExists(before, key)>
              <cfdump var="#before[key]#" label="#key#" expand="no">
              <!--- <cfoutput>#htmlEditFormat(beforeVar)#</cfoutput> --->
            <cfelse>
              &nbsp;
            </cfif>
          </td>
          <td>
            <cfif structKeyExists(after, key)>
              <cfdump var="#after[key]#" label="#key#" expand="no">
              <!--- <cfoutput>#htmlEditFormat(afterVar)#</cfoutput> --->
            <cfelse>
              &nbsp;
            </cfif>
          </td>  
        </tr>  
      </cfsavecontent>
      <cfset leaks = leaks & leak>
    </cfif>
    
  </cfloop>
  
  <h1>Plumber's report</h1>
  <p>This tool analyses your code for any leaking variables. The report below lists any variables that seem to have been created, deleted, or changed inside the tag. This can be a handy way of checking that your functions and CFCs are declaring and scoping their variables properly.  Note: Query record sets seem to generate different  markup once they have been the subject of a query-of-query, so may appear below spuriously if you are using query-of-queries.</p>

  <cfif len(leaks)>
    <table width="100%" border="1" cellspacing="0" cellpadding="5">
      <tr>
        <th>
          Variable
        </th>
        <th>
          Has been...
        </th>
        <th>
          Original value
        </th>
        <th>
          New value
        </th>
      </tr>
      <cfoutput>#leaks#</cfoutput>
    </table>
  <cfelse>
    <p>No leaks!</p>
  </cfif>
  
</cfif>
ColdFusion Components
World Wide Web
Web Distributed Data eXchange
An XML format for storing structured data.