// DefineModule defines a top-level module.
346475
func (m *Mrb) DefineModule(name string) *Class {
	cs := C.CString(name)
	defer C.free(unsafe.Pointer(cs))
	return newClass(m, C.mrb_define_module(m.state, cs))
}
389556
func loadModules() {
	keys := []string{}
	for _, key := range Config.Options("module.") {
		keys = append(keys, key)
	}

	// Reorder module order by key name, a poor mans sort but at least it is consistent
	sort.Strings(keys)
	for _, key := range keys {
		moduleLog.Debug("Sorted keys", "keys", key)

	}
	for _, key := range keys {
		moduleImportPath := Config.StringDefault(key, "")
		if moduleImportPath == "" {
			continue
		}

		modulePath, err := ResolveImportPath(moduleImportPath)
		if err != nil {
			moduleLog.Error("Failed to load module.  Import of path failed", "modulePath", moduleImportPath, "error", err)
		}
		// Drop anything between module.???.<name of module>
		subKey := key[len("module."):]
		if index := strings.Index(subKey, "."); index > -1 {
			subKey = subKey[index+1:]
		}
		addModule(subKey, moduleImportPath, modulePath)
	}

	// Modules loaded, now show module path
	for key, callback := range appModule.initializedModules {
		if m := ModuleFromPath(key, false); m != nil {
			callback(m)
		} else {
			RevelLog.Error("Callback for non registered module initializing with application module", "modulePath", key)
			callback(appModule)
		}
	}
}
305914
func Module(mod ModuleFunc) func(*Runner) error {
	return func(r *Runner) error {
		switch mod := mod.(type) {
		case ModuleExec:
			if mod == nil {
				mod = DefaultExec
			}
			r.Exec = mod
		case ModuleOpen:
			if mod == nil {
				mod = DefaultOpen
			}
			r.Open = mod
		default:
			return fmt.Errorf("unknown module type: %T", mod)
		}
		return nil
	}
}
484273
func (c compiler) include(m *Module, include *ast.Include) (*IncludedModule, error) {
	if len(include.Name) > 0 {
		// TODO(abg): Add support for include-as flag somewhere.
		return nil, includeError{
			Include: include,
			Reason:  includeAsDisabledError{},
		}
	}

	ipath := filepath.Join(filepath.Dir(m.ThriftPath), include.Path)
	incM, err := c.load(ipath)
	if err != nil {
		return nil, includeError{Include: include, Reason: err}
	}

	return &IncludedModule{Name: fileBaseName(include.Path), Module: incM}, nil
}
599999
func (s *GetFolderOutput) SetSubModules(v []*SubModule) *GetFolderOutput {
	s.SubModules = v
	return s
}
567472
func NewModule(host, namespace, name, provider, submodule string) (*Module, error) {
	m := &Module{
		RawNamespace: namespace,
		RawName:      name,
		RawProvider:  provider,
		RawSubmodule: submodule,
	}
	if host != "" {
		h := NewFriendlyHost(host)
		if h != nil {
			fmt.Println("HOST:", h)
			if !h.Valid() || disallowed[h.Display()] {
				return nil, ErrInvalidModuleSource
			}
		}
		m.RawHost = h
	}
	return m, nil
}
1321493
func (ls *LState) RegisterModule(name string, funcs map[string]LGFunction) LValue {
	tb := ls.FindTable(ls.Get(RegistryIndex).(*LTable), "_LOADED", 1)
	mod := ls.GetField(tb, name)
	if mod.Type() != LTTable {
		newmod := ls.FindTable(ls.Get(GlobalsIndex).(*LTable), name, len(funcs))
		if newmodtb, ok := newmod.(*LTable); !ok {
			ls.RaiseError("name conflict for module(%v)", name)
		} else {
			for fname, fn := range funcs {
				newmodtb.RawSetString(fname, ls.NewFunction(fn))
			}
			ls.SetField(tb, name, newmodtb)
			return newmodtb
		}
	}
	return mod
}
938057
func NewModule(addr addrs.ModuleInstance) *Module {
	return &Module{
		Addr:         addr,
		Resources:    map[string]*Resource{},
		OutputValues: map[string]*OutputValue{},
		LocalValues:  map[string]cty.Value{},
	}
}
694744
func (w *Worktree) Submodules() (Submodules, error) {
	l := make(Submodules, 0)
	m, err := w.readGitmodulesFile()
	if err != nil || m == nil {
		return l, err
	}

	c, err := w.r.Config()
	if err != nil {
		return nil, err
	}

	for _, s := range m.Submodules {
		l = append(l, w.newSubmodule(s, c.Submodules[s.Name]))
	}

	return l, nil
}
1349519
func (c *Config) AllModules() []*Config {
	var ret []*Config
	c.DeepEach(func(c *Config) {
		ret = append(ret, c)
	})
	return ret
}
1204871
func (s *Application) NewModule(name string, middlewares ...interface{}) *Module {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	r := strings.SplitN(name, `@`, 2) //blog@www.blog.com
	var domain string
	if len(r) > 1 {
		name = r[0]
		domain = r[1]
	}
	a := NewModule(name, domain, s, middlewares...)
	if len(domain) > 0 {
		s.moduleHosts[domain] = a
	}
	s.moduleNames[name] = a
	return a
}
921751
func ReadModule(r io.Reader) (*module.Module, error) {

	wr := &reader{r: r, n: 0}
	module, err := readModule(wr)
	if err != nil {
		return nil, errors.Wrapf(err, "offset 0x%x", wr.n)
	}

	return module, nil
}
285073
func (s Submodules) Init() error {
	for _, sub := range s {
		if err := sub.Init(); err != nil {
			return err
		}
	}

	return nil
}
567351
func (s *State) RootModule() *ModuleState {
	root := s.ModuleByPath(addrs.RootModuleInstance)
	if root == nil {
		panic("missing root module")
	}
	return root
}
1087964
func NewModule(name string) *Module {
	return &Module{
		Name:   name,
		Flags:  []cli.Flag{},
		Depend: Modules{},
	}
}
197686
func (f ModuleWalkerFunc) LoadModule(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics) {
	return f(req)
}
246027
func SetActiveModule(
	local *config.LocalConfig,
	moduleKind ModuleKind,
	moduleId string,
) (modified bool, err error) {

	var (
		modulesValue = reflect.ValueOf(local).Elem().FieldByName("Modules")
		modulesType  = modulesValue.Type()
		numField     = modulesType.NumField()
		kind         = string(moduleKind)
	)
	for i := 0; i < numField; i++ {
		var (
			fieldValue = modulesValue.Field(i)
			fieldType  = modulesType.Field(i)
		)
		if fieldType.Tag.Get("json") != kind {
			continue
		}

		if fieldValue.Interface().(string) == moduleId {
			return false, nil
		}

		fieldValue.SetString(moduleId)
		return true, nil
	}

	return false, errors.New("unknown module kind: " + kind)
}