# File src/PlugMan.rb, line 343
    def PlugMan.define(plug_name, &block)

      # create plugin object and execute the metadata block
      p = PlugMan::Plugin.new
    
      # set some plugin metadata
      p.name plug_name.to_sym
      p.source_file @load_path

      p.instance_eval(&block)

      # check for existing plugin with this name
      exist = @registered_plugins[plug_name.to_sym]
      if exist && exist.version > p.version
        @logger.warn { "Plugin #{plug_name.inspect} already exists with newer version of #{exist.version.to_s} (attempted to register version #{p.version.to_s}.)" }
      else
        if exist && p.version >= exist.version
          @logger.warn { "Plugin #{plug_name.inspect} already exists with older version of #{exist.version.to_s}, replacing with version #{p.version.to_s}." }      
        end
        @registered_plugins[plug_name.to_sym] = p
      end

      # set state to stopped (plugins must be started explicitly)
      p.state :stopped
      p.extension_points [] unless p.extension_points
      if !p.requires || p.requires.empty? && (!p.extends || p.extends.keys.empty?)
        p.requires [:root] unless p.name == ROOT_PLUGIN
      end

      @logger.debug { "Created plugin #{plug_name.inspect}" + (p.extension_points.empty? ? "." : ", extension points: " + p.extension_points.join(", ")) }
    end