Created
April 28, 2010 06:06
-
-
Save juster/381788 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
use 5.010; | |
use File::Spec::Functions qw(catfile); | |
sub make_inc_hook | |
{ | |
my %new_vals = @_; | |
my ($path) = grep { -f $_ } map { | |
catfile( $_, qw/ AnyEvent constants.pl / ); | |
} @INC or die "Couldn't find AnyEvent/constants.pl"; | |
open my $fh, '<', $path or die "open: $!"; | |
my $const_match = sprintf 'sub (%s) [(][)] { [^ ]+ }', | |
join q{|}, keys %new_vals; | |
my $filter = sub { | |
return 0 unless $_; | |
s{$const_match}{sub $1 () { $new_vals{$1} }}; | |
return 1; | |
}; | |
return sub { | |
my ($self, $target) = @_; | |
return undef unless ( $target eq 'AnyEvent/constants.pl' ); | |
return ( $fh, $filter ); | |
}; | |
} | |
unshift @INC, make_inc_hook( WIN32 => 1, | |
WSAEINVAL => 1002, | |
WSAEWOULDBLOCK => 10035, | |
WSAEINPROGRESS => 10036, | |
); | |
require "AnyEvent/constants.pl"; | |
say "AnyEvent::WIN32() = ", AnyEvent::WIN32(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment