1 
2 module autoloader.multi_autoloader;
3 
4 import autoloader.base;
5 
6 class MultiAutoloader : Autoloader
7 {
8 private:
9     Autoloader[] _autoloaders;
10 
11 public:
12     /++
13      + Constructs an autoloader that defers lookup to the given autoloaders.
14      ++/
15     this(Autoloader[] autoloaders)
16     {
17         _autoloaders = autoloaders;
18     }
19 
20     /++
21      + The list of autoloaders that are wrapped by this multiloader.
22      ++/
23     @property
24     Autoloader[] autoloaders()
25     {
26         return _autoloaders;
27     }
28 
29     /++
30      + Tries to load a class given by name, deferring to the wrapped autoloaders
31      + in the order that they were given in during construction.
32      +
33      + Returns:
34      +   The ClassInfo object of the class given by name, or null if not found.
35      ++/
36     override const(ClassInfo) lookup(string name)
37     {
38         foreach(autoloader; autoloaders)
39         {
40             auto result = autoloader.lookup(name);
41             if(result !is null) return result;
42         }
43 
44         return null;
45     }
46 }