Skip to content

Instantly share code, notes, and snippets.

@hiratara
Created October 12, 2018 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiratara/6125cbdb7c8ba9c55ec9a9cecaafe8c3 to your computer and use it in GitHub Desktop.
Save hiratara/6125cbdb7c8ba9c55ec9a9cecaafe8c3 to your computer and use it in GitHub Desktop.
An example of monkey patch
use strict;
use warnings;
use Time::Piece;
{
no warnings 'redefine';
my $orig_strptime = \&Time::Piece::strptime;
*Time::Piece::strptime = sub {
my @warns;
my $result = do {
local $SIG{__WARN__} = sub { push @warns, @_ };
$orig_strptime->(@_);
};
warn "CAPTURED: $_" for @warns;
warn "caller: " . caller if @warns;
$result;
};
}
Time::Piece->strptime('2015-12-27 13:19:00', '%Y-%m-%d');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment