findSubModules method

Iterable<Module> findSubModules(
  1. Pattern pattern
)

Searches for sub-modules by instance name pattern within this Module. The String representation being matched against uses / as a separator for hierarchy.

If a String is provided, it will search for an exact match to the end of a hierarchy. If a RegExp is provided, it will search for a match anywhere in the hierarchy.

Some examples:

// Real hierarchy:
// myTop/myUpperMid/myLowerMid/myLeaf

// Find all modules with the name "myLeaf"
findSubModules('myLeaf');

// Find all modules with the name "myLowerMid"
findSubModules('myLowerMid');

// Find modules named "myLeaf" directly within "myLowerMid"
findSubModules('myLowerMid/myLeaf');

// Find modules named "myLowerMid" directly within "myUpperMid"
findSubModules('myUpperMid/myLowerMid');

// Find all modules underneath "myUpperMid"
findSubModules(RegExp('myUpperMid/.*')); // finds myLowerMid and myLeaf

// Find all modules underneath "myUpperMid" named "myLeaf"
findSubModules(RegExp('myUpperMid/.*/?myLeaf$'));

The returned Iterable is lazy, so it will only search through the hierarchy as long as it is iterated against.

Implementation

Iterable<Module> findSubModules(Pattern pattern) => _findSubModules(pattern);