Getting a List of References

A list of references for an entity may be obtained from an Understand::Ent object with the command $ent->refs(). All references returned are objects of the class Understand::Ref.

The returned list may be refined with a filter that specifies the kind of references desired. For example, $ent->refs("Define") will return definition references.

The list may be even further refined with a second filter that specifies the kind of referenced entities desired. For example, @refs=$ent->refs("Define","Parameter") will return just definition references for parameter entities.

A final parameter with value 1 may be used to specify that only unique entities should be returned. For example, @refs=$ent->refs("Call","Function",1) returns a list of references to called functions, where only the first reference to each unique function is returned.

See $ent->refs() for detailed information.

See Entity and Reference Kinds for lists of reference kinds for each programming language supported by Understand. In particular, see Using Kinds in the Perl API for a list of methods that deal with reference kinds.

In addition to getting general entity and metrics information, you can also get information about the references to or from an entity. Again, you obtain a list of all references for a particular entity, and then filter the list to include only those types of references that you are interested in. For example:

foreach $var ($db->ents("Global Object ~Static")) { 
  print $var->name(),":\n"; 
  foreach $ref ($var->refs()) { 
    printf "  %-8s %-16s %s (%d,%d)\n", 
      $ref->kindname(), 
      $ref->ent()->name(), 
      $ref->file()->name(), 
      $ref->line(), 
      $ref->column(); 
  } 
  print "\n"; 
} 

Scientific Toolworks, Inc.
http://www.scitools.com