查找某个模块版本的发布日期

发布于 2024-10-02 07:26:15 字数 119 浏览 1 评论 0原文

通过

use Term::Size;
say $Term::Size::VERSION;

我可以找到模块的版本。
脚本如何找到该模块版本的发布日期?

With

use Term::Size;
say $Term::Size::VERSION;

I can find out the version of the module.
How could the script find out the release-date of this module-version?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

活雷疯 2024-10-09 07:26:15
  1. 构造 模块 搜索的 URL,如下所示:“http://search.cpan.org/perldoc?Term::Size”。

  2. 使用 LWP 检索 URL。请注意,上面的 URL 将返回一个 HTTP 重定向响应到不同的 URL:http://search.cpan.org/~ferreira/Term-Size-0.207/Size.pm - 这是模块最新版本的链接。

    注意:需要执行这些步骤 (#1-#4) 有两个原因:

    a.主要版本永久链接 (http://search.cpan.org/dist/Term-Size) 仅适用于最新版本。

    b.一个更大的问题是模块可能是更大发行版的一部分。模块本身没有发布日期 - 只有发布版本才有。例如,对于“XML::Parser::Style::Tree”,它是 XML-Parser 分发的一部分,因此 URL 应该具有 http://search.cpan.org/ ~msergeant/XML-Parser-2.36 前缀,如果没有步骤#1-#4,您将无法自动计算该前缀。

    不幸的是,这个关键区别在您的示例中并不明显,因为您只是幸运地选择了一个与发行版名称共享名称的模块

  3. 通过替换从重定向 (0.207) 自动获取的“最新”版本来更改该 URL你自己的(比如0.203)。您会得到 http://search.cpan.org/~ferreira/Term-Size-0.203/Size.pm

  4. 更改该 URL 以删除特定于模块的后缀,例如“Size.pm " - 您会得到 http://search.cpan.org/~ferreira/Term-Size-0.203/ 这是该版本发布的 URL。

    另一种方法是通过 WWW::Mechanize 实际抓取模块的页面,解析 HTML cia HTML::TreeParser 或正则表达式,并在 HTML 片段中找到发布的相对链接,从而获取发布 URL,如下所示这 - 这是 DIV 元素中带有 id=premalink 的第二个 a href 链接:

    
     
    
  5. 现在您拥有了您的版本的发布页面的 URL (http://search.cpan.org/~ferreira/Term-Size-0.203/)

  6. 通过 WWW::Mechanize 检索正确版本的发布页面,并通过 HTML::TreeParser 或任何其他喜欢的 HTML 进行解析解析器模块,或 gasp 正则表达式。您正在寻找的是一组 HTML,如下所示:

    <前><代码><表>;

    此版本
    Term-Size-0.203
    <小> [下载]
    [浏览

    <小>2006年5月21日

    从该 HTML 中,很明显您需要从第一个单元格包含单词“This”的行 中提取第四个 元素的内容发布”。

    去掉封闭的 标签,您就得到了发布日期。

这一切值得吗? ;)

  1. Construct the URL for the the module search like this: "http://search.cpan.org/perldoc?Term::Size".

  2. Retrieve the URL with LWP. Please note that the URL above will return back an HTTP redirect response to a DIFFERENT URL: http://search.cpan.org/~ferreira/Term-Size-0.207/Size.pm - which is the link to the latest version of the module.

    NOTE: these steps (#1-#4) are needed because of 2 reasons:

    a. The main release permalink (http://search.cpan.org/dist/Term-Size) only goes to the LATEST version.

    b. A much bigger problem is that a module may be part of a larger distribution. Modules themseleves don't have release dates - only releases do. For examle, for "XML::Parser::Style::Tree", it's part of XML-Parser distribution and thus the URL should have http://search.cpan.org/~msergeant/XML-Parser-2.36 prefix which you can't automatically compute without steps #1-#4.

    This critical distinction is unfortunately not obvious in your example because you just lucked out in picking a module which shares its name with the distribution name

  3. Change that URL by replacing the "latest" version you automatically got from the redirect (0.207) with your own (say 0.203). You get http://search.cpan.org/~ferreira/Term-Size-0.203/Size.pm

  4. Change that URL to remove the module-specific suffix, e.g. "Size.pm" - you get http://search.cpan.org/~ferreira/Term-Size-0.203/ which is the URL for that version's release.

    An alternate approach is to get the release URL by actually grabbing the module's page via WWW::Mechanize, parsing the HTML cia HTML::TreeParser or regex, and finding the relative link to the release in a snippet of HTML looking like this - it's the SECOND a href link in a DIV element with id=premalink:

    <a name="_top"></a>
     <div class=path>
    
    
     <div id=permalink class="noprint"><a href="/perldoc?Term::Size">permalink</a>
     </div>
     <a href="/~ferreira/">Adriano Ferreira</a> >
     <a href="/~ferreira/Term-Size-0.203/">Term-Size-0.203</a> >
      Term::Size
    </div>
    
  5. Now you have the URL for the release page for YOUR version (http://search.cpan.org/~ferreira/Term-Size-0.203/)

  6. Retrieve the correct version's release page via WWW::Mechanize and parse via either HTML::TreeParser, or any other favorite HTML parser module, or gasp regex. What you are looking for is a set of HTML which looks like this:

    <table>
     <tr>
      <td class=label>This Release</td>
      <td class=cell>Term-Size-0.203</td>
      <td><small> [<a href="/CPAN/authors/id/F/FE/FERREIRA/Term-Size-0.203.tar.gz">Download</a>]
      [<a href="/src/FERREIRA/Term-Size-0.203/">Browse</a>] </small></td>
    
    
      <td><small>21 May 2006</small>
      </td>
     </tr>
    

    From that HTML it's fairly obvious you need to extract the fourth <td> element's contents from the row <tr> whose first cell contains the word "This Release".

    Strip off the enclosing <small> tags and you got your release date.

Was it all worth it? ;)

梦在深巷 2024-10-09 07:26:15

search.cpan.org 上找到该模块。转到模块最新版本的主页,例如 Term::尺寸。此页面包含最新版本的发布日期,以及包含其他版本号和发布日期的下拉列表。

Find the module on search.cpan.org. Go to the home page for the latest version of the module, for instance for Term::Size. This page contains the release date for the latest version, plus a dropdown with other version numbers and release dates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文