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