Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Update these modules if installed?

by syphilis (Archbishop)
on Mar 08, 2020 at 03:14 UTC ( [id://11113961]=note: print w/replies, xml ) Need Help??


in reply to Update dependants if installed (was: Update these modules if installed?)

In a Perl distribution, what would be the recommended way to specify a "dependency" type that says: update these modules to at least these versions, if you have them installed?

I would do something like (untested):

In the Makefile.PL, list all dependencies along with their minimum required versions:
... my %min_version = (Some/Place/Foo.pm => 0.06, # need at least version +0.06 of Some::Place::Foo Other/Spot/Bar.pm => 1.35, # need at least version +1.35 of Other::Spot::Bar Baz.pm => 2.72, # need at least version +2.72 of Baz ); my @prereqs; for(keys(%min_version)) { eval {require $_}; # Ignore modules that don't load. unless($@){ my $m = $_; $m =~ s/\//::/g; $m =~ s/\.pm$//; my $v = $min_version{$_}; push @prereqs($m, $v); } } my %h = @prereqs; ....
And then, in WriteMakefile() section of the Makefile.PL, I would specify:
... 'PREREQ_PM' => \%h, ...
Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Update these modules if installed?
by perlancar (Hermit) on Mar 08, 2020 at 13:08 UTC

    Thanks, that's what I first thought too (dynamically generating the dependencies). However, in my case, Log::ger wants to update its *dependants* and I'm afraid adding them to the list of prereqs will trigger a circular dependency. So installing dependants will need to be performed after the installation of itself.

      adding them to the list of prereqs will trigger a circular dependency

      It's only a problem if those prereqs themselves specify a version of Log::ger that's newer than the Log::ger that's currently installed. (And there must be a Log::ger that's "currently installed", or the "list of prereqs" would be empty.)
      So, I guess that's the issue.

      IIUC, your question could therefore be generalized as:
      "How do I, as maintainer of both the Foo and Bar modules, ensure that Bar, which is dependant upon Foo, is automatically updated whenever Foo is updated ?"
      Maybe just bundle Foo and Bar into the same distro ? (I think that would be the "approved" method, though I wouldn't like to assert that it's always desirable.)

      Other than that, I can't really think of anything that hasn't already been mentioned.

      Cheers,
      Rob
        IIUC, your question could therefore be generalized as: "How do I, as maintainer of both the Foo and Bar modules, ensure that Bar, which is dependant upon Foo, is automatically updated whenever Foo is updated ?"

        More precisely, "How do I, as maintainer of both the Foo and Bar modules, ensure that Bar, which is dependant upon Foo, is automatically updated when there is a new version Foo that is backward incompatible, which sometimes happens?" Which of course is also solved by putting Foo and Bar in the same distro :-)

        It's only a problem if those prereqs themselves specify a version of Log::ger that's newer than the Log::ger that's currently installed. (And there must be a Log::ger that's "currently installed", or the "list of prereqs" would be empty.) So, I guess that's the issue.

        Which will be the case everytime. Say the user currently has Log::ger 0.032 and Log::ger::Plugin::Foo 0.001 (which depends on Log::ger 0.027). She wants to upgrade to Log::ger 0.033. This version is backward incompatible with 0.032 and I have also released Log-ger-Plugin-Foo 0.002 which depends on Log::ger 0.033. Now suppose Log::ger 0.033 adds Log::ger::Plugin::Foo 0.002 as a prereq to trigger its update. This will also instruct CPAN client to install Log::ger 0.033 and that's when it complains with circular dependency problem, because Log::ger 0.033 is not installed yet.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11113961]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found