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;
}
}
- $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 ) {
### 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;
} 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;
### 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;
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<requires> can tell you what other modules a particular module
C<Module::Load>
+=head1 BUG REPORTS
+
+Please report bugs or other issues to E<lt>bug-module-load-conditional@rt.cpan.orgE<gt>.
+
=head1 AUTHOR
-This module by
-Jos Boumans E<lt>kane@cpan.orgE<gt>.
+This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
=head1 COPYRIGHT
-This module is copyright (c) 2002-2007 Jos Boumans
-E<lt>kane@cpan.orgE<gt>. 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
### 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 ###
);
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,
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;
{ 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 );