From: Jos I. Boumans Date: Sat, 15 Sep 2007 16:22:20 +0000 (+0200) Subject: Module::Load::Conditional 0.18 (was Re: Module::Load::Conditional 0.18 wannabe) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3fa779abd4d5a443708a30f61ef389c19295ec35;p=p5sagit%2Fp5-mst-13.2.git Module::Load::Conditional 0.18 (was Re: Module::Load::Conditional 0.18 wannabe) From: "Jos I. Boumans" Message-Id: p4raw-id: //depot/perl@31883 --- diff --git a/lib/Module/Load/Conditional.pm b/lib/Module/Load/Conditional.pm index e29c563..613dda1 100644 --- a/lib/Module/Load/Conditional.pm +++ b/lib/Module/Load/Conditional.pm @@ -3,20 +3,22 @@ package Module::Load::Conditional; use strict; use Module::Load; -use Params::Check qw[check]; -use Locale::Maketext::Simple Style => 'gettext'; +use Params::Check qw[check]; +use Locale::Maketext::Simple Style => 'gettext'; use Carp (); use File::Spec (); use FileHandle (); use version qw[qv]; +use constant ON_VMS => $^O eq 'VMS'; + BEGIN { use vars qw[ $VERSION @ISA $VERBOSE $CACHE @EXPORT_OK $FIND_VERSION $ERROR $CHECK_INC_HASH]; use Exporter; @ISA = qw[Exporter]; - $VERSION = '0.16'; + $VERSION = '0.18'; $VERBOSE = 0; $FIND_VERSION = 1; $CHECK_INC_HASH = 0; @@ -224,7 +226,11 @@ sub check_install { } } - $href->{file} = $filename; + ### files need to be in unix format under vms, + ### or they might be loaded twice + $href->{file} = ON_VMS + ? VMS::Filespec::unixify( $filename ) + : $filename; ### user wants us to find the version from files if( $FIND_VERSION ) { @@ -256,7 +262,7 @@ sub check_install { ### if we couldn't find the file, return undef ### return unless defined $href->{file}; - ### only complain if we expected fo find a version higher than 0.0 anyway + ### only complain if we're expected to find a version higher than 0.0 anyway if( $FIND_VERSION and not defined $href->{version} ) { { ### don't warn about the 'not numeric' stuff ### local $^W; @@ -270,7 +276,12 @@ sub check_install { } else { ### don't warn about the 'not numeric' stuff ### local $^W; - $href->{uptodate} = $args->{version} <= $href->{version} ? 1 : 0; + + ### use qv(), as it will deal with developer release number + ### ie ones containing _ as well. This addresses bug report + ### #29348: Version compare logic doesn't handle alphas? + $href->{uptodate} = + qv( $args->{version} ) <= qv( $href->{version} ) ? 1 : 0; } return $href; @@ -411,9 +422,13 @@ sub can_load { ### else, check if the hash key is defined already, ### meaning $mod => 0, ### indicating UNSUCCESSFUL prior attempt of usage + + ### use qv(), as it will deal with developer release number + ### ie ones containing _ as well. This addresses bug report + ### #29348: Version compare logic doesn't handle alphas? if ( !$args->{nocache} && defined $CACHE->{$mod}->{usable} - && (($CACHE->{$mod}->{version}||0) >= $href->{$mod}) + && (qv($CACHE->{$mod}->{version}||0) >= qv($href->{$mod})) ) { $error = loc( q[Already tried to use '%1', which was unsuccessful], $mod); last BLOCK; @@ -468,12 +483,14 @@ sub can_load { if( defined $error ) { $ERROR = $error; Carp::carp( loc(q|%1 [THIS MAY BE A PROBLEM!]|,$error) ) if $args->{verbose}; - return undef; + return; } else { return 1; } } +=back + =head2 @list = requires( MODULE ); C can tell you what other modules a particular module @@ -565,15 +582,17 @@ C. C +=head1 BUG REPORTS + +Please report bugs or other issues to Ebug-module-load-conditional@rt.cpan.orgE. + =head1 AUTHOR -This module by -Jos Boumans Ekane@cpan.orgE. +This module by Jos Boumans Ekane@cpan.orgE. =head1 COPYRIGHT -This module is copyright (c) 2002-2007 Jos Boumans -Ekane@cpan.orgE. All rights reserved. +This library is free software; you may redistribute and/or modify it +under the same terms as Perl itself. -This library is free software; you may redistribute and/or modify -it under the same terms as Perl itself. +=cut diff --git a/lib/Module/Load/Conditional/t/01_Module_Load_Conditional.t b/lib/Module/Load/Conditional/t/01_Module_Load_Conditional.t index 678d40a..be467fd 100644 --- a/lib/Module/Load/Conditional/t/01_Module_Load_Conditional.t +++ b/lib/Module/Load/Conditional/t/01_Module_Load_Conditional.t @@ -1,24 +1,28 @@ ### Module::Load::Conditional test suite ### -BEGIN { - if( $ENV{PERL_CORE} ) { - chdir '../lib/Module/Load/Conditional' - if -d '../lib/Module/Load/Conditional'; - unshift @INC, '../../../..'; - - ### fix perl location too - $^X = '../../../../../t/' . $^X; - } -} - +### this should no longer be needed +# BEGIN { +# if( $ENV{PERL_CORE} ) { +# chdir '../lib/Module/Load/Conditional' +# if -d '../lib/Module/Load/Conditional'; +# unshift @INC, '../../../..'; +# +# ### fix perl location too +# $^X = '../../../../../t/' . $^X; +# } +# } + +BEGIN { use FindBin } BEGIN { chdir 't' if -d 't' } use strict; -use lib qw[../lib to_load]; use File::Spec (); +use Test::More 'no_plan'; + +use constant ON_VMS => $^O eq 'VMS'; -use Test::More tests => 23; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/to_load"; -### case 1 ### use_ok( 'Module::Load::Conditional' ); ### stupid stupid warnings ### @@ -40,35 +44,37 @@ use_ok( 'Module::Load::Conditional' ); ); ok( $rv->{uptodate}, q[Verify self] ); - ok( $rv->{version} == $Module::Load::Conditional::VERSION, + is( $rv->{version}, $Module::Load::Conditional::VERSION, q[ Found proper version] ); - # This test is expecting the file to in UNIX format, so force - $rv->{file} = VMS::Filespec::unixify($rv->{file}) if $^O eq 'VMS'; - - # break up the specification - my @rv_path; - if ($^O eq 'VMS') { - # Use the UNIX specific method, as the VMS one currently - # converts the file spec back to VMS format. - @rv_path = File::Spec::Unix->splitpath($rv->{file}); - } else { - @rv_path = File::Spec->splitpath($rv->{file}); - @rv_path = ($rv_path[0], - File::Spec->splitdir($rv_path[1]), $rv_path[2]); - } + ### break up the specification + my @rv_path = do { + + ### Use the UNIX specific method, as the VMS one currently + ### converts the file spec back to VMS format. + my $class = ON_VMS ? 'File::Spec::Unix' : 'File::Spec'; + + my($vol, $path, $file) = $class->splitpath( $rv->{'file'} ); - # First element could be blank for some system types like VMS - shift @rv_path if $rv_path[0] eq ''; + my @path = ($vol, $class->splitdir( $path ), $file ); - ok( $INC{'Module/Load/Conditional.pm'} eq - File::Spec::Unix->catfile(@rv_path), + ### First element could be blank for some system types like VMS + shift @path if $vol eq ''; + + ### and return it + @path; + }; + + is( $INC{'Module/Load/Conditional.pm'}, + File::Spec::Unix->catfile(@rv_path), q[ Found proper file] ); } -{ +### the version may contain an _, which means perl will warn about 'not +### numeric' -- turn off that warning here. +{ local $^W; my $rv = check_install( module => 'Module::Load::Conditional', version => $Module::Load::Conditional::VERSION + 1, @@ -103,6 +109,23 @@ use_ok( 'Module::Load::Conditional' ); is( $rv->{version}, 2, " Version is correct" ); } +### test beta/developer release versions +{ my $test_ver = $Module::Load::Conditional::VERSION; + + ### strip beta tags + $test_ver =~ s/_\d+//g; + $test_ver .= '_99'; + + my $rv = check_install( + module => 'Module::Load::Conditional', + version => $test_ver, + ); + + ok( $rv, "Checking beta versions" ); + ok( !$rv->{'uptodate'}, " Beta version is higher" ); + +} + ### test $FIND_VERSION { local $Module::Load::Conditional::FIND_VERSION = 0; local $Module::Load::Conditional::FIND_VERSION = 0; @@ -170,6 +193,9 @@ SKIP:{ { package A::B::C::D; $A::B::C::D::VERSION = $$; $INC{'A/B/C/D.pm'} = $$.$$; + + ### XXX this is no longer needed with M::Load 0.11_01 + #$INC{'[.A.B.C]D.pm'} = $$.$$ if $^O eq 'VMS'; } my $href = check_install( module => 'A::B::C::D', version => 0 ); diff --git a/lib/Module/Load/Conditional/t/02_Parse_Version.t b/lib/Module/Load/Conditional/t/02_Parse_Version.t index 48fad07..dd29c67 100644 --- a/lib/Module/Load/Conditional/t/02_Parse_Version.t +++ b/lib/Module/Load/Conditional/t/02_Parse_Version.t @@ -72,6 +72,8 @@ sub _succeed { ( $VERSION = q($Id: Tidy.pm,v 1.56 2006/07/19 23:13:33 perltidy Exp $) ) =~ s/^.*\s+(\d+)\/(\d+)\/(\d+).*$/$1$2$3/; # all one line for MakeMaker ($VERSION) = q $Revision: 2.120 $ =~ /([\d.]+)/; ($VERSION) = q$Revision: 1.00 $ =~ /([\d.]+)/; + $VERSION = "3.0.8"; + $VERSION = '1.0.5'; ]; }