ColdBox Framework Forums Notification: Post to enable includeUDF() to replace existing functions

Title: enable includeUDF() to replace existing functions
Thread: enable includeUDF() to replace existing functions
Forum: Enhancements
Conference: ColdBox
User: jondbo Hi,

I'm interested in enabling includeUDF() to optionally override existing
methods in the current handler CFC; I came up with the following approach based
on using CFmodule as a "hidden" scope, and manually replacing the functions in
the CFC via the "caller" scope.

The main downside I see to this approach is
that it replaces the original function without providing a mechanism for
accessing the original function (i.e. "super").

I'm interested in reactions
to both the goal and the (hackish?) approach.

Thanks!

[code]
<!---
modification to: frameworkSuperType.cfc --->
  <cffunction name="includeUDF"
access="private" hint="Injects a UDF Library into the handler." output="false"
returntype="void">
    <!---
************************************************************* --->
<cfargument name="udflibrary" required="true" type="string" hint="The UDF
library to inject.">
    <cfargument name="replaceExisting" required="false"
type="boolean" default="false" hint="Determines whether the UDF library will
automatically override existing functions with the same name as UDF-declared
functons (or throw an error in case of collision); this defaults to false.">
<!--- ************************************************************* --->
<cfset var UDFFullPath = ExpandPath(arguments.udflibrary)>
    <cfset var
UDFRelativePath = ExpandPath("/" & getController().getSetting("AppMapping") &
"/" & arguments.udflibrary)>
    
    <!--- check if UDFLibraryFile is defined
--->
    <cfif arguments.udflibrary neq "">
      <!--- Check if file exists on
declared relative --->
      <cfif fileExists(UDFRelativePath)>
        <cfif
arguments.replaceExisting>
          <cfmodule
template="includes/includeUDF.cfm"
path="/#getController().getSetting("appMapping")#/#arguments.udflibrary#">
<cfelse>
          <cfinclude
template="/#getController().getSetting("appMapping")#/#arguments.udflibrary#">
</cfif>
      <cfelseif fileExists(UDFFullPath)>
        <cfif
arguments.replaceExisting>
          <cfmodule
template="includes/includeUDF.cfm"
            path="#arguments.udflibrary#">
<cfelse>
          <cfinclude template="#arguments.udflibrary#">
        </cfif>
<cfelse>
        <cfthrow type="Framework.eventhandler.UDFLibraryNotFoundException"
message="Error loading UDFLibraryFile. The UDF library was not
found in your application's include directory or in the location you specified:
<strong>#UDFFullPath#</strong>. Please make sure you verify the file's
location.">
      </cfif>
    </cfif>
  </cffunction>
[/code]

[code]
<!---
FILE: includes/includeUDF.cfm --->

<!--- require the path to the UDF
functionality --->
<cfparam name="attributes.path" type="string">

<!---
include UDF function library (setting them in the "variables" scope) --->
<cfinclude template="#attributes.path#">

<!--- copy included functions to the
calling CFC's --->
<cfloop collection="#variables#" item="i">
  <cfif
iscustomfunction(variables[i])>
    <!--- copy the function to the calling CFC's
variables scope --->
    <cfset caller.variables[i] = variables[i]>
    <!--- if
the function is externally available, also reference it in the "this" scope;
assume that functions are public unless explicitly made private --->
    <cfset m
= getmetadata(variables[i])>
    <cfif (not structkeyexists(m,"access"))
      or
(listfindnocase("public,remote",m.access))>
      <cfset caller.this[i] =
caller.variables[i]>
    </cfif>
  </cfif>
</cfloop>
[/code]
http://forums.coldboxframework.com/index.cfm?event=ehMessages.dspMessages&threadid=CFF06247-FF6E-E829-9A946D92F4FD1446