perl - 安装 perl 模块时不能使用数组作为引用

编辑:使用 sudo cpanm Data::Match --force

我正在尝试使用 ubuntu 18.04 安装“Data::Match”perl 模块。 我使用:

perl Makefile.pl
make
make test

我收到以下错误:

make test
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-Iblib/lib" "-Iblib/arch" test.pl
1..1
# Running under perl version 5.026001 for linux
# Current time local: Wed Jun 29 18:41:13 2022
# Current time GMT:   Wed Jun 29 15:41:13 2022
# Using Test.pm version 1.30
Can't use an array as a reference at blib/lib/Data/Match.pm line 968.
Compilation failed in require at test.pl line 10.
BEGIN failed--compilation aborted at test.pl line 10.
Makefile:825: recipe for target 'test_dynamic' failed
make: *** [test_dynamic] Error 255

我安装了许多其他模块,它们都运行良好。 我也尝试安装

perl -MCPAN -e shell

但这并没有帮助。

我该怎么办?

最佳答案

Data::Match 模块有一些 Perl v5.22 收紧的语法。这就是它失败的原因。请注意,强制安装具有此类严重问题的模块意味着它只会在您运行程序时失败。

如果可以,请不要使用此模块。我不知道它的作用,所以我没有任何替代建议。

假设您出于某种原因需要此模块,即使它已有 20 年历史。也许您正在支持一个您只需要开始工作的旧版应用程序。

这一行 ( L968 ) 取消引用本身就是数组引用的数组元素:

$str .= $sep . '{' . join(',', @$ind->[0]) . '}';

这应该是分隔引用部分的circumfix符号:

$str .= $sep . '{' . join(',', @{$ind->[0]}) . '}';

如果您在运行 perl Makefile.PL 之前对 Match.pm 进行了更改,则测试会通过(但会出现警告)并且您可以安装该模块。

如果这就是您所需要的,您可以到此为止。

Distroprefs

CPAN.pm 有办法处理这些情况,因此您不必在每次要安装模块时都进行更改。在 CPAN.pm 开始工作之前,它可以修补有问题的发行版、建议替代发行版或许多其他事情。你用“distroprefs”来做到这一点。 CPAN.pm repo中有很多例子.

有几件事需要设置。首先,设置您的 distroprefs 目录 (o conf init prefs_dir)。其次,配置一个目录来保存你的补丁(o conf patches_dir)。我在我的 .cpan 目录下选择 patches,但它可以是任何东西。退出前保存更改。

% cpan
% cpan[1]> o conf init prefs_dir
Directory where to store default options/environment/dialogs for
building modules that need some customization? [/Users/brian/.cpan/prefs]
% cpan[2]> o conf patches_dir /Users/brian/.cpan/patches
% cpan[3]> o conf commit

distropref 有两部分。第一个指定你想要发生什么。这可以是 YAML、Storable 或 Data::Dumper 文件。如果是 YAML(大多数人似乎都在使用),那么您需要先安装 YAML 模块。

这是一个简单的 distroprefs 文件。它告诉 CPAN.pm 如何匹配您在 CPAN (AUTHOR/FILE) 上看到的分布。在此示例中,它的操作是 patches,这是一个补丁文件数组。由于您设置了 patches_dir,因此它会出现在该位置。补丁的文件名并不特殊,可以压缩。我选择了发行版名称,我的名字作为修补它的人,然后是 .patch

---
match:
  module: "Data::Match"
  distribution: "^KSTEPHENS/Data-Match-0.06.tar.gz"
patches:
    - Data-Match-0.06-BDFOY-01.patch

这是你的补丁。备份原始文件,更改目标文件,然后获取统一差异(或您的 patch 理解的任何内容):

$ diff -u Match.pm.orig Match.pm
--- Match.pm.orig   2022-06-29 15:04:06.000000000 -0400
+++ Match.pm    2022-06-29 14:55:45.000000000 -0400
@@ -965,7 +965,7 @@
     elsif ( $ref eq 'HASH' ) {
       if ( ref($ind) eq 'ARRAY' ) {
    # Not supported by DRef.
-   $str .= $sep . '{' . join(',', @$ind->[0]) . '}';
+   $str .= $sep . '{' . join(',', @{$ind->[0]}) . '}';
       } else {
    $str .= $sep . $ind;
       }

但是你想在你的补丁目录中使用你指定的名称,所以将输出重定向到那里:

$ diff -u Match.pm.orig Match.pm > /Users/brian/.cpan/patches/Data-Match-0.06-BDFOY-01.patch

如果你真的想变得很花哨,你可以把那个补丁目录放在你的配置文件的环境变量中,这样你就不必记住它了:

$ diff -u Match.pm.orig Match.pm > $CPAN_PATCHES_DIR/Data-Match-0.06-BDFOY-01.patch

现在,当您尝试使用 cpan 安装 Data::Match 时,它知道它正在安装 Data-Match-0.06,它匹配该发行版来自 distroprefs 文件,该 distroprefs 文件告诉 CPAN.pm 执行操作。在这种情况下,它需要找到补丁文件并应用它。打上补丁后,测试通过,安装成功:

% cpan Data::Match
Reading '/Users/brian/.cpan/Metadata'
  Database was generated on Wed, 29 Jun 2022 05:56:00 GMT
Running install for module 'Data::Match'

______________________ D i s t r o P r e f s ______________________
                  Data-Match-0.06-BDFOY-01.yml[0]
Checksum for /Users/brian/.cpan/sources/authors/id/K/KS/KSTEPHENS/Data-Match-0.06.tar.gz ok
Applying 1 patch:
  /Users/brian/.cpan/patches/Data-Match-0.06-BDFOY-01.patch
  /usr/bin/patch -N --fuzz=3 -p0
patching file Match.pm
Configuring K/KS/KSTEPHENS/Data-Match-0.06.tar.gz with Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Data::Match
Writing MYMETA.yml and MYMETA.json
  KSTEPHENS/Data-Match-0.06.tar.gz
  /usr/local/perls/perl-5.36.0/bin/perl Makefile.PL -- OK
Running make for K/KS/KSTEPHENS/Data-Match-0.06.tar.gz
cp Match.pm blib/lib/Data/Match.pm
cp lib/Sort/Topological.pm blib/lib/Sort/Topological.pm
Manifying 2 pod documents
  KSTEPHENS/Data-Match-0.06.tar.gz
  /usr/bin/make -- OK
Running make test for KSTEPHENS/Data-Match-0.06.tar.gz
PERL_DL_NONLAZY=1 "/usr/local/perls/perl-5.36.0/bin/perl" "-Iblib/lib" "-Iblib/arch" test.pl
1..1
# Running under perl version 5.036000 for darwin
# Current time local: Wed Jun 29 15:54:13 2022
# Current time GMT:   Wed Jun 29 19:54:13 2022
# Using Test.pm version 1.31
ok 1
PERL_DL_NONLAZY=1 "/usr/local/perls/perl-5.36.0/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/t1.t .. ok
t/t2.t .. ok
t/t3.t .. 1/15 splice() offset past end of array at /Users/brian/.cpan/build/Data-Match-0.06-15/blib/lib/Data/Match.pm line 1941.
t/t3.t .. ok
t/t4.t .. ok
All tests successful.
Files=4, Tests=182,  0 wallclock secs ( 0.03 usr  0.01 sys +  0.18 cusr  0.04 csys =  0.26 CPU)
Result: PASS

https://stackoverflow.com/questions/72804459/

相关文章:

c++ - 从样板代码到模板实现

r - 混合 glm 零膨胀模型的 Bootstrap 方法

typescript - 使用类转换器 : Nest js 序列化嵌套对象

r - 在R中按组计算每两行值的比例

javascript - 如何声明 useState() 初始值为 null,然后再给它一个对象值?

python - 由于 OSError : [Errno 2] No such file or di

python - 我怎么能实现 “HH:MM:SS” 格式

r - 如果数据集的某些列为空,我想在 R 中删除那些列

javascript - 通过 :even and :odd 向 querySelectorAll

python - 删除 pandas 列中的前导零,但仅适用于数字