'Writes out a module file for this object.
This method employs a template pattern and expects derived classes to:
- override the header property
- provide formats for autoload, prerequisites and environment changes'

def write(self, overwrite=False):

    if self.blacklisted:
        return
    tty.debug((' DCTB WRITE    :    %s    [%s]' % (self.spec.cshort_spec, self.file_name)))
    module_dir = os.path.dirname(self.file_name)
    if (not os.path.exists(module_dir)):
        mkdirp(module_dir)
    env = inspect_path(self.spec.prefix)
    spack_env = EnvironmentModifications()
    for item in dependencies(self.spec, 'all'):
        package = self.spec[item.name].package
        modules = parent_class_modules(package.__class__)
        for mod in modules:
            set_module_variables_for_package(package, mod)
        set_module_variables_for_package(package, package.module)
        package.setup_dependent_package(self.pkg.module, self.spec)
        package.setup_dependent_environment(spack_env, env, self.spec)
    set_module_variables_for_package(self.pkg, self.pkg.module)
    self.spec.package.setup_environment(spack_env, env)
    (module_configuration, conf_env) = parse_config_options(self)
    env.extend(conf_env)
    filters = module_configuration.get('filter', {}).get('environment_blacklist', {})
    module_file_content = self.header
    for x in filter_blacklisted(module_configuration.pop('autoload', []), self.name):
        module_file_content += self.autoload(x)
    for x in module_configuration.pop('load', []):
        module_file_content += self.autoload(x)
    for x in filter_blacklisted(module_configuration.pop('prerequisites', []), self.name):
        module_file_content += self.prerequisite(x)
    for line in self.process_environment_command(filter_environment_blacklist(env, filters)):
        module_file_content += line
    for line in self.module_specific_content(module_configuration):
        module_file_content += line
    if ((not overwrite) and os.path.exists(self.file_name)):
        message = 'Module    file    already    exists    :    skipping    creation\n'
        message += 'file    :    {0.file_name}\n'
        message += 'spec    :    {0.spec}'
        tty.warn(message.format(self))
        return
    with open(self.file_name, 'w') as f:
        f.write(module_file_content)
