Created
October 12, 2018 02:55
-
-
Save hiratara/6125cbdb7c8ba9c55ec9a9cecaafe8c3 to your computer and use it in GitHub Desktop.
An example of monkey patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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