[Module-build-checkins] Module-Build/lib/Module/Build Base.pm,1.451,1.452 ModuleInfo.pm,1.4,1.5
Status: Beta
Brought to you by:
kwilliams
|
From: Randy W. S. <si...@us...> - 2005-07-01 11:20:11
|
Update of /cvsroot/module-build/Module-Build/lib/Module/Build In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1071/lib/Module/Build Modified Files: Base.pm ModuleInfo.pm Log Message: Provide more intelligent cataloging of provided packages. [cpan #13464] Index: Base.pm =================================================================== RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Base.pm,v retrieving revision 1.451 retrieving revision 1.452 diff -u -d -r1.451 -r1.452 --- Base.pm 29 Jun 2005 06:38:59 -0000 1.451 +++ Base.pm 1 Jul 2005 11:19:47 -0000 1.452 @@ -2576,7 +2576,7 @@ sub find_dist_packages { my $self = shift; - + # Only packages in .pm files are candidates for inclusion here. # Only include things in the MANIFEST, not things in developer's # private stock. @@ -2589,22 +2589,60 @@ keys %$manifest; my @pm_files = grep {exists $dist_files{$_}} keys %{ $self->find_pm_files }; - - my %out; + + my( %prime, %alt ); foreach my $file (@pm_files) { next if $file =~ m{^t/}; # Skip things in t/ - - my $localfile = File::Spec->catfile( split m{/}, $file ); + + my @path = split( /\//, $file ); + (my $prime_package = join( '::', @path[1..$#path])) =~ s/\.pm$//; + + my $localfile = File::Spec->catfile( @path ); my $pm_info = Module::Build::ModuleInfo->new_from_file( $localfile ); - + foreach my $package ($pm_info->packages_inside($localfile)) { - $out{$package}{file} = $dist_files{$file}; - $out{$package}{version} = $pm_info->version( $package ) - if defined( $pm_info->version( $package ) ); + next if $package eq 'main'; # main can appear numerous times, ignore + next if (split( /::/, $package ))[-1] =~ /^_/; # private pkg, ignore + + my $version = $pm_info->version( $package ); + if ( $package eq $prime_package ) { + $prime{$package}{file} = $dist_files{$file}; + $prime{$package}{version} = $version if defined( $version ); + } else { + if ( exists( $alt{$package} ) && + exists( $alt{$package}{version} ) && + defined( $alt{$package}{version} ) ) { + # This should never happen because M::B::ModuleInfo catches it first + if ( $self->compare_versions( $version, '==', + $alt{$package}{version} ) ) { + $self->log_warn( "$package ($alt{$package}{version}) conflicts " . + "with $package ($version)\n" ); + } + } else { + $alt{$package}{file} = $dist_files{$file}; + $alt{$package}{version} = $version if defined( $version ); + } + } } } - return \%out; + + foreach my $package ( keys( %alt ) ) { + if ( exists( $prime{$package} ) ) { + my $p_vers = exists( $prime{$package}{version} ) ? + $prime{$package}{version} : '<undef>'; + if ( exists( $alt{$package}{version} ) && + $alt{$package}{version} ne $p_vers ) { + $self->log_warn( "Version declaration for package '$package' in " . + "'$prime{$package}{file}' ($p_vers) conflicts with " . + "'$alt{$package}{file}' ($alt{$package}{version})\n" ); + + } + } else { + $prime{$package} = $alt{$package}; + } + } + return \%prime; } sub make_tarball { Index: ModuleInfo.pm =================================================================== RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/ModuleInfo.pm,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- ModuleInfo.pm 23 Apr 2005 12:00:14 -0000 1.4 +++ ModuleInfo.pm 1 Jul 2005 11:20:01 -0000 1.5 @@ -105,7 +105,7 @@ my $fh = IO::File->new( $filename ) or die( "Can't open '$filename': $!" ); - my( $in_pod, $seen_end ) = ( 0, 0 ); + my( $in_pod, $seen_end, $need_vers ) = ( 0, 0,0 ); my( @pkgs, %vers, %pod, @pod ); my $pkg = 'main'; my $pod_sect = ''; @@ -143,10 +143,12 @@ $pkg = $1; push( @pkgs, $pkg ) unless grep( $pkg eq $_, @pkgs ); $vers{$pkg} = undef unless exists( $vers{$pkg} ); + $need_vers = 1; # first non-comment line in undeclared package main is VERSION } elsif ( !exists($vers{main}) && $pkg eq 'main' && - $line =~ $VERS_REGEXP ) { + $line =~ $VERS_REGEXP ) { + $need_vers = 0; my $v = $self->_evaluate_version_line( $line ); $vers{$pkg} = $v; push( @pkgs, 'main' ); @@ -154,15 +156,20 @@ # first non-comement line in undeclared packge defines package main } elsif ( !exists($vers{main}) && $pkg eq 'main' && $line =~ /\w+/ ) { + $need_vers = 1; $vers{main} = ''; push( @pkgs, 'main' ); - } elsif ( $line =~ $VERS_REGEXP ) { + } elsif ( $line =~ $VERS_REGEXP && $need_vers ) { # only first keep if this is the first $VERSION seen - unless ( defined $vers{$pkg} && length $vers{$pkg} ) { - my $v = $self->_evaluate_version_line( $line ); + $need_vers = 0; + my $v = $self->_evaluate_version_line( $line ); + unless ( defined $vers{$pkg} && length $vers{$pkg} ) { $vers{$pkg} = $v; - } + } else { + warn "Package '$pkg' already declared with version '$vers{$pkg}'\n" . + " ignoring new version '$v'.\n"; + } } |