【问题标题】:Package collection of modules as Erlang application?将模块打包为 Erlang 应用程序?
【发布时间】:2014-08-02 23:03:06
【问题描述】:

我一直在研究一些相对简单的 Erlang 模块。我有 4 个模块一起工作。所有模块名称都像这样“命名空间”:

project
project_helper
project_another_module
project_third_submodule

模块很简单。它们只包含函数。没有什么并发的。没有进程、主管或 gen_servers。只是功能。要使用代码,您只需调用顶级 project 模块中的函数。所有调用都是同步的。传入数据,等待函数完成,然后取回数据。

我的问题是,我该如何打包这段代码?是否需要设置为应用程序? Erlang 应用程序有什么好处?

【问题讨论】:

    标签: module erlang package synchronous


    【解决方案1】:

    您必须将其打包为应用程序,以便其他应用程序可以将您的库作为依赖项放在其 .app 文件中。 此信息在版本生成过程中用于包含您的库。

    要做到这一点,请在您的 your_library.app 中省略 {mod, ...} 部分。

    来自应用手册:(erl -man app)

    mod:
      Specifies the application callback module and a start argument, see application(3).
    
      The  mod  key is necessary for an application implemented as a supervision tree, or the application controller will not know how to start it. The mod key can be
      omitted for applications without processes, typically code libraries such as the application STDLIB.
    

    【讨论】:

      【解决方案2】:

      这取决于您计划如何使用您的代码。 您不必将代码设置为应用程序。 打包它的简单方法是通过 Erlang shell 使用命令 c(Module) 编译所有模块,然后压缩文件夹并在需要时发送。

      但是,我建议遵循 OTP 应用程序的最佳实践: http://learnyousomeerlang.com/building-otp-applications

      如果您将代码设置为 OTP 应用程序,它将为您提供可重用性。 您可以将这些模块包含在您稍后创建的其他应用程序中。

      我建议使用 rebar (https://github.com/rebar/rebar/wiki) 作为构建工具。 并将您的代码放入某个源代码控制环境中,以便您可以更轻松地将代码包含在您未来的项目中。

      【讨论】:

        【解决方案3】:

        当需要打包一组模块时,它们仍然属于一个应用程序。该应用程序根本不需要回调模块。 Learn You Some Erlang 将这些类型的应用程序称为“库应用程序”。库.app 文件应该像普通的.app 文件。唯一的区别是 mod 元组 ({mod, {Module, Args}}) 不存在。

        更多详情请参考 LYSE:http://learnyousomeerlang.com/building-otp-applications#library-applications

        【讨论】:

          猜你喜欢
          • 2019-06-01
          • 2015-12-14
          • 1970-01-01
          • 2017-03-26
          • 2012-06-15
          • 2011-07-02
          • 2012-06-22
          • 2018-01-20
          • 2017-12-11
          相关资源
          最近更新 更多