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

Hi monks!

I've been trying to configure the cpan conf file out of another script.
open(FILE, ">/etc/perl/CPAN/Config.pm") || die "/etc/perl/CPAN/Config. +pm: $!"; print FILE " ...
which works. But when I run CPAN via "sudo cpan" it complains about not being configured due to missing parameters (which I all set in my print above...). Is there some kind of check in cpan (a md5 or timestamp) which detects if the Config.pm file was set/written by cpan itself?

Replies are listed 'Best First'.
Re: Configuring CPAN out of script does not work
by Joost (Canon) on Aug 22, 2007 at 15:30 UTC
    First; are you sure your cpan command loads the config from /etc/perl/CPAN/Config.pm and not some other location?

    Also; did you check that the contents of Config.pm matches what you think it should be?

    Also; what is in your Config.pm and what is the error you're getting?

    In any case, I'd be very surprised if CPAN.pm does any checks on Config.pm besides trying to use its content.

Re: Configuring CPAN out of script does not work
by ides (Deacon) on Aug 22, 2007 at 15:41 UTC

    If it is complaining about missing parameters, the configuration file you are generating is most likely missing some parameter. Check your generated file against one generated by the CPAN shell itself and see if you're missing anything.

    Frank Wiles <frank@revsys.com>
    www.revsys.com

Re: Configuring CPAN out of script does not work
by dsheroh (Monsignor) on Aug 22, 2007 at 23:09 UTC
    I asked a similar question about a year and a half ago over at Automating CPAN Configuration. Not exactly the same thing, but some of the answers I got may apply to your situation.
Re: Configuring CPAN out of script does not work
by naikonta (Curate) on Aug 22, 2007 at 17:45 UTC
    I assume that /etc/perl is part of your @INC. If it's not, then you may have problem there. I don't understand why you configure cpan manually like that. If you run cpan as root for the first time, the CPAN/Config.pm file will be created automatically (for example in /usr/lib/perl5/5.8.8, but it depends on your local @INC setting) and you have a chance to configure it. Oh, now I think about it, you might want to write your own CPAN::Config to keep your default the same across systems so you don't have to run into manual and boring prompted-configuration process.

    CPAN.pm seems to always complain whenever it finds that one or more config item is missing and then offers a reconfiguration. The problem is, you write the config items manually from the script (if I get you correctly). You say you set them all. But installed CPAN.pm may have newer config item(s) you haven't handled yet. I touch my CPAN/MyConfig.pm very rarely. Yet when I upgrade CPAN.pm (with significant change on the config items), it will tell me about missing/uninitialized configuration item(s). For me, it's not a problem. I take it as part of the upgrading process.

    So I don't think that the complain is due to some magical cheking in CPAN.pm (I haven't looked at the source code thoroughly but I won't bother for this case). One suggestion if you want to keep your method is: run the cpan for the first time as root to create the initial CPAN/Config.pm. It should be guaranteed that it will contain the complete items the current CPAN.pm has. Open the newly created file, take all its items, and override the ones with your own values, and save it back. It shouldn't be hard to modify your script. Good luck!


    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

      "run the cpan for the first time as root to create the initial CPAN/Config.pm"

      Actually, that's exactly what I did (cos I am lazy..)

      I went to /etc/perl/CPAN/Config.pm, opened it in an editor and copy/pasted it over into the
      print FILE " --here goes the config, would paste it but not at hand (and is actuall +y nothing special)--- ";
      So when I run my script it overwrites the contents of the Config.pm properly. Then I run cpan and it complains. I redo the config questions and then cpan runs ok.

      When I re-run my script to test, and replace the file once again with the same data, cpan again complains...

      Any further ideas? (I will see if my script really writes the config file cpan is contacting under the user I am trying this.. Although it should be the one: cpan states this path right after startup..)