develooper Front page | perl.module-authors | Postings from August 2021

How to handle minimum versions of dependencies which are recommendedbut not required?

Thread Next
Diab Jerius
August 8, 2021 19:35
How to handle minimum versions of dependencies which are recommendedbut not required?
Message ID:

I've a module 
which may use JSON and YAML writers.

For JSON, I use JSON::MaybeXS.  Cpanel::JSON::XS >= 3.0236 is required.

My code can use either YAML::XS or YAML::PP.  YAML::XS  >= 0.67 is required.

Since JSON & YAML output are optional, I've encoded the XS dependencies 
as runtime recommendations, rather than requirements. JSON::MaybeXS is 
specified as a runtime dependency (as is YAML::PP, but that's a mistake; 
it should also be a runtime recommendation).

Here are the relevant bits of  META.json 

|||"runtime"| |: {|
|||"recommends"| |: {|
|||"Cpanel::JSON::XS"| |: ||"3.0236"||,|
|||"JSON::PP"| |: ||"0"||,|
|||"YAML::XS"| |: ||"0.67"|
|||"requires"| |: {|
|||"JSON::MaybeXS"| |: ||"0"||,|
|||"YAML::PP"| |: ||"0"||,|

Here's the problem, illustrated by this CPAN testers failure:

The smoker has versions of Cpanel::JSON::XS and YAML::XS which are older 
than my required versions.  Since the ::XS versions are prioritized over 
the ::PP versions, the code uses those and thus fails the tests.   I 
presume that because the ::XS versions are recommendations rather than 
requirements, they weren't updated to the versions that the code requires.

Is there some way of triggering an update to the required versions via 
the metadata, or should I put a runtime version check into the tests and 
skip if the appropriate versions aren't installed?

For production runs, I'll have to add a runtime check in the code which 
falls back to YAML::PP if the version of YAML::XS is too old, but I 
don't see how I can do that with JSON::MaybeXS, as there are no hooks to 
indicate acceptable versions of the backend.  I think my only option is 
to take the same approach as for YAML, namely manually specifying which 
backend libraries are acceptable.  I don't like this, as now I can't 
automatically take advantage of JSON::MaybeXS's list of backends.

Any advice on how to gracefully handle this situation?



Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About