Some weeks ago on the perl5-porters list, someone (Ken Williams?) mentioned re-writing, re-factorizing, modularizing etc. h2xs in the same way he did it with
xsubpp by creating
I thought, well, why not. Can't be that hard. It should be benificial for those times when
Module::Build finally replaces
ExtUtils::MakeMaker as the preferred way of creating CPAN modules.
And so I started with
ExtUtils::H2XS. That was eight days ago. Right now I am not too far away from regretting this decision deeply. The code of h2xs is disgusting to an almost criminal extent. It uses about (and this is no exaggeration) 50 global variables (named in an as obfascated way as possible) to gather all the information it needs to create a module skeleton. I have already spotted around 10 variables that are only assigned to but never read from. It uses for-loops where there can clearly be only one iteration, passes arguments to the few functions it has that are discarded inside these functions.
Furthermore, the code differs greatly from what the documentation says. It has switches that are useless (-f for instance) and it offers features that aren't mentioned in the docs (the mysterious ext/ directory).
The real problem is that no one on the porters list can provide some help with h2xs' internals. That's not because they wouldn't want to, it's because they don't understand it either. No one does.
This surely has historical reasons. Over the years, h2xs has been patched to death...you can easily tell that different parts of it have been written by different people. The only thing they had in common was that they never looked at the seemingly unrelated other parts of the code (which results in so many useless and duplicate variables used) and that they never commented any of their additions. Ideally, patches and changes would have an author-tag so that later the authors can be asked what their code does in case of emergencies (such as this case). But they haven't. (Admittedly: my enum-patch for h2xs to be found in perl5.8.1 was no exception from the above).
And one final rant: Who was responsible for adding the
-x/--autogen-xsubs switch? This whole C::Scan business is causing me a major headache. It's by far the hardest part (and at the same time the part that almost never works in practice). Once I am done with implementing a functional duplicate of the current h2xs, I'll create a subclass of
ExtUtils::H2XS::XSUBS (the package that encapsulates all the work of C::Scan) that uses
ExtUtils::XSBuilder to create XSUB accessors. Unlike
C::Scan, this module actually works and uses a proper C-grammar instead of these silly heuristics of