perl - 如何在 perl 中编写覆盖导入函数的模块函数

标签 perl module subroutine

我有一个问题:我想为我的模块 M 编写一个名为“copy”的方法。这个函数是导入函数 File::Copy::copy 的包装。所以我必须使用 File::Copy::copy 并定义我自己的副本。但是它会报错说复制被重新定义了。如何实现我的目标?

#M.pm
package M;
use File::Copy;

#... constructor and other methods

sub copy {
  my $self = shift;
  my $target = shift;
  File::Copy::copy($self->{'PATH'},$target);
}

最佳答案

use File::Copy qw( );  # Don't import anything.

关于perl - 如何在 perl 中编写覆盖导入函数的模块函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12537657/

相关文章:

perl - 如何使用 Moose 设置 DBIx::Class 模式——明确指南

c - 寻找 MPI 例程

Linux使用 "select: Bad file descriptor"后返回 "cat"错误

perl - 在简单的 Perl 教程中为模块添加包含路径

perl - 根据用户 ip 查找最近的服务器?

java - 从 Java 连接到 PickBasic

Fortran 'call' 语句 : what can it actually call?

PHP 模块在 ts_allocate_dtor 上崩溃

javascript - requireJS - 几个问题

python - 如何在python中不使用 "import"导入