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.


modification to: frameworkSuperType.cfc --->
  <cffunction name="includeUDF"
access="private" hint="Injects a UDF Library into the handler." output="false"
************************************************************* --->
<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)>
      <cfelseif fileExists(UDFFullPath)>
          <cfinclude template="#arguments.udflibrary#">
        <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

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">
    <!--- 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"))
      <cfset caller.this[i] =