First of all, I question the value of declaring a function in
the
application scope, if you are not going to use it there.
Sounds like a
waste of memory. Why not just dynamically declare the
function on a
page when it is known that it is going to be used on that
page?
Secondly, I'm not sure this line is doing what you think it
is doing.
> <cfset request.myFunction=application.myFunction>
My understanding is that generally ColdFusion creates a copy
by
reference of complex variables. I have only seen this
discussed in
relationship to things like arrays and structures so I am
unsure how it
implies to a 'function' variable. But I suspect there is a
high chance
that this line only creates a pointer in 'request.myFunction'
to the
same code referenced in 'application.myFunction' and you have
not
mitigated the issues you seem to be concerned about.
Thirdly, it really sounds like you are trying to use user
defined
functions as components. You may have cleaner code if you
just went
ahead and made some 'utility' components that encapsulate
these functions.
Finally to answer your question, I know of no mechanism for a
function
to introspect what scope from which it is being utilized. The
only hack
I can imagine is to modify your code when it is copied into
the local
scope. Something like having a boolean, 'runme' lets say,
that is set
to false in the default 'application' scope, but then set to
'true' in
the local copy.
But I would still be highly confused by this convoluted
looking
situation you have here. In my world I would have either a
utility cfc
containing functions like this that can be configured, or a
simple
utility cfm file containing these functions and then
dynamically set or
unset these naturally local functions as necessary by
business requirements.