# File lib/pluginfactory.rb, line 303
303:         def requireDerivative( modName )
304: 
305:                 # See if we have a list of special subdirs that derivatives
306:                 # live in
307:                 if ( self.respond_to?(:derivativeDirs) )
308:                         subdirs = self.derivativeDirs
309:                         subdirs = [ subdirs ] unless subdirs.is_a?( Array )
310: 
311:                 # If not, just try requiring it from $LOAD_PATH
312:                 else
313:                         subdirs = ['']
314:                 end
315: 
316:                 fatals = []
317: 
318:                 # Iterate over the subdirs until we successfully require a
319:                 # module.
320:                 catch( :found ) {
321:                         subdirs.collect {|dir| dir.strip}.each do |subdir|
322:                                 self.makeRequirePath( modName, subdir ).each {|path|
323:                                         #PluginFactory::log :debug, "Trying #{path}..."
324: 
325:                                         # Try to require the module, saving errors and jumping
326:                                         # out of the catch block on success.
327:                                         begin
328:                                                 require( path.untaint )
329:                                         rescue LoadError => err
330:                                                 PluginFactory::log :debug,
331:                                                         "No module at '%s', trying the next alternative: '%s'" %
332:                                                         [ path, err.message ]
333:                                         rescue ScriptError,StandardError => err
334:                                                 fatals << err
335:                                                 PluginFactory::log :error,
336:                                                         "Found '#{path}', but encountered an error: %s\n\t%s" %
337:                                                         [ err.message, err.backtrace.join("\n\t") ]
338:                                         else
339:                                                 #PluginFactory::log :debug, 
340:                                                 # "Found '#{path}'. Throwing :found"
341:                                                 throw :found
342:                                         end
343:                                 }
344:                         end
345: 
346:                         #PluginFactory::log :debug, "fatals = %p" % [ fatals ]
347: 
348:                         # Re-raise is there was a file found, but it didn't load for
349:                         # some reason.
350:                         if ! fatals.empty?
351:                                 #PluginFactory::log :debug, "Re-raising first fatal error"
352:                                 Kernel::raise( fatals.first )
353:                         end
354: 
355:                         nil
356:                 }
357:         end