Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by Corion (Patriarch)
on Aug 02, 2019 at 18:58 UTC ( [id://11103775]=note: print w/replies, xml ) Need Help??


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

Yes, the two statements run at different times, as you found out:

package November; use base 'Juliet'; # runs at compile time Juliet->VERSION(1.1); # runs at runtime, after November.pm has been pa +rsed completely

This usually makes little difference as long as November.pm is its own file. If November.pm is loaded later, code from earlier modules will already have run by the time the ->VERSION() call is made.

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

    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

      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

      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

Re^4: Using a base module with a required version
by Anonymous Monk on Aug 04, 2019 at 18:21 UTC
    You could just BEGIN { Juliet->VERSION('1.1') }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found