8
#!/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 );

The some_method() uses itself get() form LWP::Simple.
How could I overwrite the get() with my my_get() in this script?

sub my_get {
    my $url;
    my $mech = WWW::Mechanize::Cached->new();
    $mech->get( $url );
    my $content = $mech->content( format => 'text' );
    return $content;
}
sid_com
  • 24,137
  • 26
  • 96
  • 187

1 Answers1

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

OR, if the get method is actually, as you imply in the question, is inherited from LWP::Simple -

sub LWP::Simple::get {
    # your code
}
DVK
  • 126,886
  • 32
  • 213
  • 327
  • 1
    Make sure you load the module you want to override before you do this, and you might want a `no warnings 'redefine'`. I talk about this stuff extensively in _Mastering Perl_. There's a whole chapter on just this question. :) – brian d foy Mar 06 '12 at 15:16