如何制作“先决条件"CPAN::Meta::Spec 需要分发而不是包?
我正在研究如何打包我的一些 Perl 应用程序并更好地管理它们的依赖项,以使我和我的客户更容易分发,这很可能根本不包括上传到 CPAN.相反,我会在必要时提供自定义存储库,或者更有可能提供对 Subversion 等 SCM 的访问权限.
I'm researching about how to package some of my Perl apps and better manage their dependencies to make distribution easier for me and my customers, which most likely doesn't include uploading to CPAN at all. Instead, I would provide custom repos if necessary or, more likely, access to SCMs like Subversion.
CPAN::Meta::Spec 似乎提供了什么我需要描述我的应用程序、它们的依赖项,甚至从哪里获取它们,但我想知道的是先决条件的详细程度.规范包含以下语句:
CPAN::Meta::Spec seems to provide what I need to describe my apps, their dependencies and even where to get them from, but what I'm wondering is about the level of detail of pre-requisites. The spec contains the following sentence:
必须将关系集指定为包名称到版本范围的映射.
The set of relations must be specified as a Map of package names to version ranges.
对于我的需求来说,需要软件包似乎有点太低了,我更喜欢要求分发.Maven 和 Gradle 之类的工具几乎可以使用(根据我的理解),例如Apache Commons Lang 与 Apache Commons IO 等,而不是像 org.apache.commons.lang3.AnnotationUtils
或 org.apache.commons.io.ByteOrderMark
这样的单个类.OTOH,文档中的示例包含以下几行:
Requiring packages seems a little too low level for my needs, I would prefer requiring distributions instead. Pretty much the level (from my understanding) tools like Maven and Gradle work at, e.g. Apache Commons Lang vs. Apache Commons IO etc. instead of individual classes like org.apache.commons.lang3.AnnotationUtils
or org.apache.commons.io.ByteOrderMark
. OTOH, the example in the docs contains the following lines:
requires => {
'perl' => '5.006',
'File::Spec' => '0.86',
'JSON' => '2.16',
},
包含 perl
的行对我来说看起来不像一个包,我没有找到一些 package perl
或 perl.pm
我系统上的任何地方.在我看来,这与示例中的其他内容的处理方式不同.
The line containing perl
doesn't look like a package to me and I didn't find some package perl
or perl.pm
anywhere on my system. Seems to me like that is handled differently to the other things of the example.
我有一个系统范围的文件夹,其中包含例如一些实用程序包,对我来说似乎与一些抽象的 perl
相当.该文件夹应该被定义为一个发行版,为该文件夹中的所有包维护一个版本号,因此应该允许其他应用程序要求
整个事情.如果我正确理解文档,我不仅需要在文件夹中创建 META.yml
,还需要创建一些例如sysutils.pm
包含 package sysutils;
并定义一些版本.
I have a system wide folder containing e.g. some utility packages, which seems comparable to some abstract perl
to me. That folder should get defined as one distribution, maintain a version number for all of the packages in that folder and therefore should allow other apps to require
that whole thing. If I understand the docs correctly, I would need to create not only the META.yml
in the folder, but additionally some e.g. sysutils.pm
containing package sysutils;
and defining some version.
有什么方法可以避免创建那个文件,并且真的要求
发行版本身?
Is there some way to avoid creating that file and really require
the distribution itself only?
META.yml
已经包含了它自己的名称和版本,所以看起来像是理论上可以require
的一些抽象东西.我认为不需要添加一个额外的 .pm
文件来代表发行版本身,只是为了让 require
能够工作.就我而言,它不包含任何业务逻辑.
The META.yml
already contains a name and version on it's own, so looks like some abstract thing one could require
in theory. I don't see the need of adding an additional .pm
-file representing the distribution itself only to allow require
to work. It wouldn't contain any business logic in my case.
谢谢!
那真的不是你想要做的.您想预先请求您实际需要的内容.因此,例如,如果您需要 File::Spec
,这就是您所需要的,无论它来自 perl 核心还是来自单独的 CPAN 发行版.
That's really not what you want to do. You want to pre-req what you actually require. So, for example, if you need File::Spec
, that's what you need, regardless of whether it comes from perl core or from a separate CPAN distribution.
我见过某些模块从 CPAN 移动到核心的情况,反之亦然.通过直接要求模块,您不需要仅仅因为您依赖的人改变了他们的分发方法而发布您的依赖发行版的新版本.
I've seen cases where certain modules have moved from CPAN to core, or vice versa. By requiring the module directly, you don't need to ship new releases of your dependent distributions simply because someone you depend on changed their method of distribution.
我还看到某些模块在确定它们作为独立模块有价值时从其原始发行版中分离出来的情况.依赖模块意味着你不再为了一个简单的依赖而拖入一堆其他模块.
I've also seen cases where certain modules are split off from their original distributions when it was determined they were valuable as standalone modules. Depending on the module means that you no longer drag in a bunch of other modules for a simple dependency.
您或多或少要寻找的内容类似于Task::*
模块.它们中的大多数都没有真正的逻辑,只是进一步的依赖项列表.
What you're more or less looking for is akin to the Task::*
modules. No real logic in most of them, just a list of further dependencies.