Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Thanks for the clarifications. To be honest, it sounds like your problems are more political than technological. You probably need to implement a plan for upgrading software that's agreed to by all parties: probably involving rigorous testing, appropriate notifications, sign-offs at various levels and so on. I'll leave you to work on that. See also codiac's comments.

Here's a suggestion that doesn't require altering @INC directly or via the lib pragma, nor does it rely on checking version numbers. (I've used version numbers in the examples below purely for identification purposes, the solution itself doesn't need them.)

Some up-front information:

$ alias perle alias perle='perl -Mstrict -Mwarnings -Mautodie=:all -E' $ perl -v | head -2 | tail -1 This is perl 5, version 24, subversion 0 (v5.24.0) built for darwin-th +read-multi-2level

Let's say you've got an xyz module. That's in production and lives in directory old. Here's old/xyz.pm:

package xyz; our $VERSION = '1.0'; sub import { print "import called with args: @_\n"; } 1;

You can use that with or without a VERSION; it might have a LIST, which could be empty.

$ perle 'BEGIN { @INC = qw{old new .} } use xyz 1.0; say $xyz::VERSION +' import called with args: xyz 1.0 $ perle 'BEGIN { @INC = qw{old new .} } use xyz 1.0 (); say $xyz::VERS +ION' 1.0 $ perle 'BEGIN { @INC = qw{old new .} } use xyz 1.0 qw{a b c}; say $xy +z::VERSION' import called with args: xyz a b c 1.0 $ perle 'BEGIN { @INC = qw{old new .} } use xyz; say $xyz::VERSION' import called with args: xyz 1.0 $ perle 'BEGIN { @INC = qw{old new .} } use xyz (); say $xyz::VERSION' 1.0 $ perle 'BEGIN { @INC = qw{old new .} } use xyz qw{a b c}; say $xyz::V +ERSION' import called with args: xyz a b c 1.0

Now, let's say that a new version of the xyz module becomes available. It has some features the developers want. You install it in directory new. Here's new/xyz.pm:

package xyz; our $VERSION = '2.0'; sub import { print "import called with args: @_\n"; } 1;

For the purposes of demonstration, that's identical to old/xyz.pm except for the version number. Attempting to use it by just specifying VERSION doesn't work because old/xyz.pm is found first in @INC (i.e. the problem already discussed).

$ perle 'BEGIN { @INC = qw{old new .} } use xyz 2.0; say $xyz::VERSION +' xyz version 2 required--this is only version 1.0 at -e line 1. BEGIN failed--compilation aborted at -e line 1.

What I suggest you do is create a new module that only needs to be very simple. I've called this Bleed::xyz and put it in the current directory (i.e. the last place in @INC to be searched). Here's ./Bleed/xyz.pm:

package Bleed::xyz; our $VERSION = '2.0'; BEGIN { require 'new/xyz.pm'; } sub import { shift; xyz->import(@_); } 1;

Now version 2.0 of xyz can be used with all the various combinations of VERSION and LIST.

$ perle 'BEGIN { @INC = qw{old new .} } use Bleed::xyz 2.0; say $xyz:: +VERSION' import called with args: xyz 2.0 $ perle 'BEGIN { @INC = qw{old new .} } use Bleed::xyz 2.0 (); say $xy +z::VERSION' 2.0 $ perle 'BEGIN { @INC = qw{old new .} } use Bleed::xyz 2.0 qw{a b c}; +say $xyz::VERSION' import called with args: xyz a b c 2.0 $ perle 'BEGIN { @INC = qw{old new .} } use Bleed::xyz; say $xyz::VERS +ION' import called with args: xyz 2.0 $ perle 'BEGIN { @INC = qw{old new .} } use Bleed::xyz (); say $xyz::V +ERSION' 2.0 $ perle 'BEGIN { @INC = qw{old new .} } use Bleed::xyz qw{a b c}; say +$xyz::VERSION' import called with args: xyz a b c 2.0

When version 2.0 of the xyz module is accepted into production, and assuming that involves moving new/xyz.pm to old/xyz.pm, you'll need one, very minor change to Bleed::xyz (i.e. s/new/old/). All existing code should continue to work. You can change instances of use Bleed::xyz to just use xyz at your leisure.

"BTW, why is the '.' location not good in the @INC?"

I didn't say that. I said:

"... you end up with '.' at the front of the list: not a good idea.".

Consider someone's who's bad. In /home/bad they write code with names like strict.pm, warnings.pm, autodie.pm, etc. that all do bad things. They then run your code from /home/bad. If @INC starts with '.', bad things will happen.

— Ken


In reply to Re^3: how to improve: use MODULE VERSION LIST by kcott
in thread how to improve: use MODULE VERSION LIST by smile4me

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2021-08-04 05:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (41 votes). Check out past polls.

    Notices?