7
#!/usr/bin/env perl
use warnings;
use 5.012;
use utf8;
use WWW::Mechanize::Cached;
use Some::Module qw(some_method);
my $url = '...';
my $result = some_method($url);
some_method()
本身使用get()
形式LWP::Simple
。
我该如何在脚本中用我的my_get()
覆盖get()
?如何覆盖模块方法中使用的函数?
sub my_get {
my $url;
my $mech = WWW::Mechanize::Cached->new();
$mech->get($url);
my $content = $mech->content(format => 'text');
return $content;
}
确保装入要重写模块在你这样做之前,你可能需要一个'不警告'重新定义''。我在_Mastering Perl_中广泛地讨论了这个问题。关于这个问题有一整章。 :) – 2012-03-06 15:16:29