--- AnyEvent/constants.pl.PL 2010/10/11 03:41:39 1.6 +++ AnyEvent/constants.pl.PL 2013/07/30 23:14:32 1.13 @@ -2,34 +2,87 @@ # this file is unfortunately only executed at Makefile.PL time -use Socket; +my ($fh, $oldstdout); -open my $fh, ">lib/AnyEvent/constants.pl" - or die "lib/AnyEvent/constants.pl: $_[0]\n"; +BEGIN { + open $fh, ">lib/AnyEvent/constants.pl" + or die "lib/AnyEvent/constants.pl: $!\n"; -my $oldstdout = select $fh; + $oldstdout = select $fh; + + print "# automatically generated from constants.pl.PL\n"; +} + +{ + # from common::sense 3.7 + use strict qw(vars subs); + no warnings; + use warnings qw(FATAL closed threads internal debugging pack malloc portable prototype + inplace io pipe unpack deprecated glob digit printf + layer reserved taint closure semicolon); + no warnings qw(exec newline unopened); + + BEGIN { + my $H = $^H; + my $WARN = ${^WARNING_BITS}; + + print "sub AnyEvent::common_sense {\n"; + printf " local \$^W;\n"; + printf " \${^WARNING_BITS} ^= \${^WARNING_BITS} ^ \"%s\";\n", + join "", map "\\x$_", unpack "(H2)*", ${^WARNING_BITS}; + # use strict, use utf8; + printf " \$^H |= 0x%x;\n", $^H; + print "}\n"; + } +} + +use Config; + +print "# generated for perl $] built for $Config{archname}\n"; + +# when built as part of perl, these are not available +BEGIN { eval "use Socket ()" } +BEGIN { eval "use Fcntl ()" } +BEGIN { eval "use POSIX ()" } sub i($$) { - print "sub $_[0] () { ", $_[1]*1, " }\n"; + print "sub $_[0](){", $_[1]*1, "}\n"; } sub n($$) { - print "sub $_[0] () { ", (defined $_[1] ? $_[1]*1 : "undef"), " }\n"; + print "sub $_[0](){", (defined $_[1] ? $_[1]*1 : "undef"), "}\n"; } print "package AnyEvent;\n"; our $WIN32 = $^O =~ /mswin32/i; +# used a lot i CYGWIN => $^O =~ /cygwin/i; i WIN32 => $WIN32; -use Fcntl (); +# add these purely to avoid loading Fcntl, which is slow and bloated. -i F_SETFL => eval { Fcntl::F_SETFL() }; -i F_SETFD => eval { Fcntl::F_SETFD() }; -i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() }; -i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() }; +i F_SETFD => eval { Fcntl::F_SETFD() } || 2; +i F_SETFL => eval { Fcntl::F_SETFL() } || 4; +i O_NONBLOCK => eval { Fcntl::O_NONBLOCK() } || 04000; +i FD_CLOEXEC => eval { Fcntl::FD_CLOEXEC() } || 1; + +print "package AnyEvent::Base;\n"; + +# add these purely to avoid loading POSIX, which is slow and bloated. + +i WNOHANG => eval { POSIX::WNOHANG() } || 1; + +print "package AnyEvent::IO;\n"; + +i O_RDONLY => eval { Fcntl::O_RDONLY() } || 0; +i O_WRONLY => eval { Fcntl::O_WRONLY() } || 1; +i O_RDWR => eval { Fcntl::O_RDWR () } || 2; +i O_CREAT => eval { Fcntl::O_CREAT () } || 64; +i O_EXCL => eval { Fcntl::O_EXCL () } || 128; +i O_TRUNC => eval { Fcntl::O_TRUNC () } || 512; +i O_APPEND => eval { Fcntl::O_APPEND() } || 1024; print "package AnyEvent::Util;\n"; @@ -47,17 +100,18 @@ my $af_inet6; -$af_inet6 ||= eval { Socket::AF_INET6 () }; -$af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; +$af_inet6 ||= eval { Socket::AF_INET6 () }; # where it should be +$af_inet6 ||= eval { require Socket6; Socket6::AF_INET6() }; # where it actually is ... -# uhoh +# ... or isn't, because nobody has it installed $af_inet6 ||= 10 if $^O =~ /linux/; $af_inet6 ||= 23 if $^O =~ /cygwin/i; $af_inet6 ||= 23 if AnyEvent::WIN32; $af_inet6 ||= 24 if $^O =~ /openbsd|netbsd/; $af_inet6 ||= 28 if $^O =~ /freebsd/; -#TODO: WSAxxx, EDOM/ESPIPE +#TODO: EDOM/ESPIPE +#TODO: maybe move socket stuff to Socket::? i _AF_INET6 => $af_inet6; #i AF_UNIX => Socket::AF_UNIX (); @@ -69,6 +123,8 @@ #i SO_OOBINLINE => Socket::SO_OOBINLINE (); #i IPPROTO_TCP => Socket::IPPROTO_TCP (); +print "package AnyEvent::Socket;\n"; + # more hardcoded os-specific constants - none # of these are available via any known module, but we # are forward-looking and try Socket:: anyways.