Tuesday 9 October 2012

getMetadata(): expectations management

G'day:
Just a quick one.  Have a look at this code:



// MY.cfc
component {

    function inComponent(){

    }

}

<!---test.cfm --->
<cfscript>
    o = new My();

    function inCallingCode(){
    }
    o.fromCallingCode = inCallingCode;

    writeDump(var=o, label="Object"); // outputs f() in the "methods" part of the dump
    writeOutput("<hr />");

    for (key in o){
        writeDump(var=o[key], label="Each public variable: #key#");
    }
    writeOutput("<hr />");


    writeDump(var=getMetadata(o), label="getMetadata()"); // what would you expect to see in the "functions" sub-array of this?
    writeOutput("<hr />");

    try{
        writeOutput("Calling o.fromCallingCode()<br />");
        o.fromCallingCode();
        writeOutput("OK<br />");
    } catch(any e){
        writeOutput("#e.message# #e.detail#<br />");
    }

    try{
        writeOutput("Calling o.inCallingCode()<br />");
        o.inCallingCode();
        writeOutput("OK<br />");
    } catch(any e){
        writeOutput("#e.message# #e.detail#<br />");
    }
</cfscript>

This outputs much the same thing on both CF9 and Railo 4.0.0.013:

Object - component cf.cfml.functions.system.getMetadata.My
METHODS
INCALLINGCODE
INCOMPONENT

Each public variable: inComponent - function inComponent
Each public variable: FROMCALLINGCODE - function inCallingCode

getMetadata() - struct
EXTENDS
FULLNAMEcf.cfml.functions.system.getMetadata.My
FUNCTIONS
getMetadata() - array
1
getMetadata() - struct
NAMEinComponent
PARAMETERS
getMetadata() - array [empty]
NAMEcf.cfml.functions.system.getMetadata.My
PATHD:\websites\www.scribble.local\cf\cfml\functions\system\getMetadata\My.cfc
TYPEcomponent

Calling o.fromCallingCode()
OK
Calling o.inCallingCode()
The method inCallingCode was not found in component D:\websites\www.scribble.local\cf\cfml\functions\system\getMetadata\My.cfc. Ensure that the method is defined, and that it is spelled correctly.


What I was expecting here is that I'd see a method fromCallingCode() being cited in all three of those dumps. What would you expect to see?

There's a coupla problems here from my perspective:
  1. How is it that the first dump things the method name is inCallingCode() when I inserted it into the object as fromCallingCode()?
  2. Where is it at all in the functions array returned from getMetadata()?
(Note that the function actually is  fromCallingCode(). Which is what I'd expect)

So what do you think: bug?  Am I missing something?

--
Adam