如何覆盖模块方法中使用的函数?

时间:2012-03-06 11:51:19

标签: perl function methods module overwrite

#!/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 如何在此脚本中使用get()覆盖my_get()

sub my_get {
    my $url;
    my $mech = WWW::Mechanize::Cached->new();
    $mech->get( $url );
    my $content = $mech->content( format => 'text' );
    return $content;
}

1 个答案:

答案 0 :(得分:10)

sub WWW::Mechanize::Cached::get {
    # your code
}

或者,如果get方法实际上正如您所暗示的那样,则继承自LWP :: Simple -

sub LWP::Simple::get {
    # your code
}