Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: Using a base module with a required version

by davido (Cardinal)
on Aug 02, 2019 at 19:56 UTC ( [id://11103779]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Using a base module with a required version
in thread Using a base module with a required version

I looked at the code for parent, which in most cases should be used instead of base. I'm wondering (since you have been involved in parent) what you think of a parent::versioned that could be invoked like this:

use parent::versioned 'Foo'; # No version checking. use parent::versioned qw(Foo Bar); # No version checking. use parent::versioned --norequire qw(Foo Bar); # Still no version chec +king. use parent::versioned ['Foo' => 0.23], ['Bar' => 1.5], 'Baz'; # Versio +n checking on Foo and Bar. use parent::versioned --norequire 'Baz', ['Foo' => 0.23]; # Version ch +ecking on Foo.

Implementation would be really straightforward as a fork off of existing parent (so as not to clutter parent with baggage).

Hashrefs could be used instead, so that multiple entries could reside within a single hashref, but the array-ref keeps things nicely flat.


Dave

Replies are listed 'Best First'.
Re^5: Using a base module with a required version
by davido (Cardinal) on Aug 04, 2019 at 02:49 UTC

    Here it is: parent::versioned version 0.002. This link points directly to the initial mainline (non-dev) CPAN release version. It passes the full parent test suite, plus additional tests around the versioning logic. Code test coverage is 100%. Once the CPAN mirrors pick it up this link will be best for long-term use, as it's not tied to a version number: parent::versioned.

    Synopsis:

    use parent::versioned qw(Foo Bar::Baz); # Same as parent.pm # Set minimum versions for Foo and Buzz::Wham dependencies. # But Bar::Baz and Fizz::Bang wont' be version-checked. use parent::versioned ['Foo' => 1.0], qw(Bar::Baz Fizz::Bang), ['Buzz: +:Wham' => 0.25]; # If you're actually using quadruple inheritance, question your decisi +on. # A more common example: use parent::versioned ['My::Parent::Class' => 3.5];

    Version checking happens at compiletime, since it's built into the import() method. Any version failure will throw an exception. Any module that requires version checking should be specified in an array-ref tuple. Multiple tuples may exist, and may be combined with non-version-checked inheritance too.

    It's not in the Perl core, so you'll have to install it using your favorite method. It adds no dependencies besides Perl itself.


    Dave

Re^5: Using a base module with a required version
by Corion (Patriarch) on Aug 03, 2019 at 06:26 UTC

    I think using array refs would be a good API for that.

    Since parent has basically no reusable moving parts, simply copying the code and modifying it is the best approach.

    I'm reluctant to modify parent itself, as the code is fairly simple as it is and it has the chance of breaking a lot of things.

      My thoughts exactly: Copy what is there to a new module, add the versioning functionality, verify no regressions against existing test suite, and of course shoot for 100% coverage on new features.


      Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found