Skip to content

Instantly share code, notes, and snippets.

@juster
Created April 28, 2010 06:06
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 juster/381788 to your computer and use it in GitHub Desktop.
Save juster/381788 to your computer and use it in GitHub Desktop.
#!/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