# from Dr.Ruud
# on Sunday 21 January 2007 05:30 am:

>> I also need to get Perl v53.46.48 installed, but that
>> should be a piece of cake.
>
>$ perl -wle 'print v53.46.48'
>5.0

Heh, that was just a joke about how the overridden require sees version 
numbers.  Actually, it seems to be something to do with upgrading the 
value to a string if you use it as one.  The 53.46.48 stuff appears to 
have come from ord("5") . ord(".") . ord("0").  I suppose the compiler 
has tagged it as a version before it comes into require?

BTW, for those that haven't seen this before, the vstring v8.9.10 is a 
three byte string:  chr(8) . chr(9) . chr(10).

----------
#!/usr/bin/perl

use warnings;
use strict;

BEGIN {
  *CORE::GLOBAL::require = sub {
    my ($module) = @_;
    warn "wants $module";
    CORE::require $module;
  };
}

require 5.0004 ;
print "ok\n";
---------

  $ perl overriding_require.1.pl
  wants 5.0004 at overriding_require.1.pl line 9.
  Perl v53.46.48 required--this is only v5.8.4, stopped at
  overriding_require.1.pl line 10.

Now, if I don't use the $module value for anything before passing it 
along, I guess I get to delete a bunch of the special cases from 
Devel::TraceDeps:

    my ($module) = @_;
    my $thing = $module;
    warn "wants $thing";
    CORE::require $module;
  ...
  require 5.0004 ;
  require 5.0;
  require 5.006;
  require v5.0.4;
  require 5.0.4;
  print "ok\n";

  $ perl overriding_require.2.pl
  wants 5.0004 at overriding_require.2.pl line 10.
  wants 5 at overriding_require.2.pl line 10.
  wants 5.006 at overriding_require.2.pl line 10.
  wants  at overriding_require.2.pl line 10.
  wants  at overriding_require.2.pl line 10.
  ok

Neat, huh?  I suppose I could add "who says they need what version" to 
the output, eh?

--Eric
-- 
Turns out the optimal technique is to put it in reverse and gun it.
--Steven Squyres (on challenges in interplanetary robot navigation)
---------------------------------------------------
    http://scratchcomputing.com
---------------------------------------------------

Reply via email to