Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

module needs another module for build

by dk (Chaplain)
on Aug 09, 2011 at 16:50 UTC ( [id://919504]=perlquestion: print w/replies, xml ) Need Help??

dk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I'm writing a module, and I'm trying to solve a problem how it should require another module for building itself under CPAN shell. In details, my setup is as follows: I'm authoring module A, which uses module B's config, which has all libraries, include paths, etc stuff needed to build A properly. Basically A's Makefile.PL should be very simple code like this:

WriteMakefile( INC => "$B::Config{INC}", LIB => "$B::Config{LIB}", ... )
Trouble is, if B is NOT installed (yet), I can't read B::Config. Currently I'm making a hack: if B cannot be require'd, I'm creating a Makefile where I do list B as a prerequisite, with empty INC and LIB. CPAN then fetches B, builds and installs it, and returns to A, but it doesn't run Makefile.PL again, just issues "make". To work around that, I'm writing a prefix into the makefile that forcibly re-runs Makefile.PL, hoping that this time B will be available.

That works, but the code is cumbersome, and I'd like to know if I'm missing some simpler technique. Manuals and google gave me BUILD_REQUIRES option, but judging by manual of CPAN::FirstTime, it's rather an option for declaring a prerequisite as a possibly temporal module, so CPAN user can skip installing it if he wishes so.

Also, experimenting with such setup is not easy: I'll need to upload module A to the pause, then try to install it under CPAN, to see if my assumptions works.

So, simply speaking, I'm a bit out of tools when it comes to testing how my module behaves under CPAN environment. Are there any good advices? Thank you!

Replies are listed 'Best First'.
Re: module needs another module for build
by bingos (Vicar) on Aug 09, 2011 at 22:45 UTC

    build_requires will be resolved too late to be of any help. build_requires are resolved by *after* Makefile.PL has already been executed by cpan/cpanp/cpanm etc.

    CONFIGURE_REQUIRES on the other hand are a list of prereqs that must be resolved *before* Makefile.PL is executed.

    • CONFIGURE_REQUIRES - modules required by Makefile.PL/Build.PL
    • BUILD_REQUIRES - modules required only during the build process
    • PREREQ_PM - modules required to run your module
    WriteMakefile( CONFIGURE_REQUIRES => { 'B' => 0, }, PREREQ_PM => { 'B' => 0, }, )

    We require the 'B' module during configuration and at runtime in the above example.

      Thank you! CONFIGURE_REQUIRES is definitely a step forward, will try. I wonder if CPAN shell can detect that this field has changed after Makefile.PL was run and re-run it, because I have another module that does just that, if none of the libraries it needs are found, it falls back on a third-party module.

        The CPAN clients (cpan/cpanp/cpanm) take the following steps:

        • Download distribution
        • Extract distribution
        • Does a META.yml or META.json file exist? Okay, parse and look for configure_requires, resolve all the requirements listed there
        • Execute Makefile.PL or Build.PL
        • If there is a MYMETA.yml or MYMETA.json, parse and look for build and runtime requirements, resolve these
        • No, MYMETA files, okay, if there is a Makefile parse that to resolve requirements
        • Oh, its a Module::Build based dist, try running 'Build prereq_data' action, if that fails, poke around in _build/ directory to find the requirements
        • Resolve requirements
        • Execute 'make' for EUMM or './Build' for M::B
        • Execute 'make test' for EUMM or './Build test' for M::B
        • Execute 'make install' for EUMM or './Build install' for M::B

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://919504]
Approved by Perlbotics
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-05-29 11:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found