Bad AnyEvent Install

When I tried to move my AnyEvent-based code over to Windows today, I got a slightly unpleasant surprise.

$ perl kernel.pl
fcntl is not implemented at c:/strawberry/perl/site/lib/AnyEvent/Util.pm line 362.

(Actually, that path is not accurate – it is from simulating the problem on a different computer. The actual path is a network share.)

Drat I thought, maybe AnyEvent isn’t as portable as I thought. But hang on a minute. When doubting a widely used library ahead of your own code, it is usually your code that is at fault. In my experience anyhow. And besides, Twiggy runs on Windows. What have I done wrong?

And this is down to my company’s perl policy. A number of pure perl modules are installed on a windows network share which is samba mounted onto the unix servers. We’re primarily a C++/Java shop and Perl is something of a second-class citizen but there are a good number of modules available (including Moose, AnyEvent, POE, etc.)

The downside is that it is hard to get modules installed that aren’t there already, and we are not permitted to download them ourselves. Most of the time, this isn’t a problem.

Anyway, I tried to fix this in my own script using variants on:

packageAnyEvent;
useconstantWIN32 => 1;
packageKernel;

and

subAnyEvent::WIN32() { 1 }

both before and after the use AnyEvent lines. I couldn’t get round it though. This happened when the definitions were after the use lines.

8 Responses

This problem intrigued me. I always found it magical how you can override another module’s symbol table entry, but the only module it will affect is your own! I mean you only notice a difference if you call that changed symbol table entry (subroutine) from your module.

Anyways, the only way I could think of to bypass constants was for you to make a YOUR OWN constant.pm file and have it act as a proxy between the real constant.pm and everyone else.

I’m guessing this is why the constant.pl is generated in the first place. If there is an if statement inside sub WIN32 () {} it will not be inlined. Hence the if statement is converted to its result when creating the constant function.

@zloyrusskiy – thanks for the solution it looks good. I still don’t think I would say there is a bug in AnyEvent despite the fact it is solvable. Installing on one Perl on Unix and expecting it to work on a Windows Perl is a little unreasonable. What do you think?

Anyway, I’ll get your solution off to Marc and see if he wants to incorporate it into a later version.

@juster – gosh, that solution looks complicated. First good chance to use require hooks eh? 🙂 I’ll have to look at it in detail to understand it.