Author: dagolden
Date: Sun Sep 13 20:56:20 2009
New Revision: 13333
Added:
Module-Build/trunk/t/properties/module_name.t (contents, props changed)
Modified:
Module-Build/trunk/Changes
Module-Build/trunk/MANIFEST
Module-Build/trunk/lib/Module/Build/Base.pm
Log:
guess module_name when not provided
Modified: Module-Build/trunk/Changes
==============================================================================
--- Module-Build/trunk/Changes (original)
+++ Module-Build/trunk/Changes Sun Sep 13 20:56:20 2009
@@ -11,6 +11,9 @@
- Updated PPM generation to PPM v4 (RT#49600) [Olivier Mengue]
- When c_source is specified, the directory scan will include additional,
less-common C++ extensions (RT49298) [David Golden]
+ - When module_name is not supplied, no packlist was being written; fixed
+ by guessing module_name from dist_version_from or the directory name
+ (just like ExtUtils::Manifest does without NAME) [David Golden]
Other:
- Replaced use of YAML.pm with YAML::Tiny; Module::Build::YAML is now
Modified: Module-Build/trunk/MANIFEST
==============================================================================
--- Module-Build/trunk/MANIFEST (original)
+++ Module-Build/trunk/MANIFEST Sun Sep 13 20:56:20 2009
@@ -65,6 +65,7 @@
t/PL_files.t
t/pod_parser.t
t/ppm.t
+t/properties/module_name.t
t/properties/needs_compiler.t
t/properties/share_dir.t
t/README.pod
Modified: Module-Build/trunk/lib/Module/Build/Base.pm
==============================================================================
--- Module-Build/trunk/lib/Module/Build/Base.pm (original)
+++ Module-Build/trunk/lib/Module/Build/Base.pm Sun Sep 13 20:56:20 2009
@@ -54,7 +54,8 @@
$self->dist_name;
$self->dist_version;
-
+ $self->_guess_module_name unless $self->module_name;
+
$self->_find_nested_builds;
return $self;
@@ -1027,6 +1028,33 @@
return $opts{class};
}
+sub _guess_module_name {
+ my $self = shift;
+ my $p = $self->{properties};
+ return if $p->{module_name};
+ if ( $p->{dist_version_from} && -e $p->{dist_version_from} ) {
+ my $mi =
Module::Build::ModuleInfo->new_from_file($self->dist_version_from);
+ $p->{module_name} = $mi->name;
+ }
+ else {
+ my $mod_path = my $mod_name = File::Basename::basename($self->base_dir);
+ $mod_name =~ s{-}{::}g;
+ $mod_path =~ s{-}{/}g;
+ $mod_path .= ".pm";
+ if ( -e $mod_path || -e File::Spec->catfile('lib', $mod_path) ) {
+ $p->{module_name} = $mod_name;
+ }
+ else {
+ $self->log_warn( << 'END_WARN' );
+No 'module_name' was provided and it could not be inferred
+from other properties. This will prevent a packlist from
+being written for this file. Please set either 'module_name'
+or 'dist_version_from' in Build.PL.
+END_WARN
+ }
+ }
+}
+
sub dist_name {
my $self = shift;
my $p = $self->{properties};
Added: Module-Build/trunk/t/properties/module_name.t
==============================================================================
--- (empty file)
+++ Module-Build/trunk/t/properties/module_name.t Sun Sep 13 20:56:20 2009
@@ -0,0 +1,53 @@
+# sample.t -- a sample test file for Module::Build
+
+use strict;
+use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
+use MBTest;
+use DistGen;
+
+plan tests => 4;
+
+# Ensure any Module::Build modules are loaded from correct directory
+blib_load('Module::Build');
+
+# enter the directory and generate the skeleton files
+my $dist = DistGen->new( name => "Not::So::Simple" )->chdir_in;
+
+#--------------------------------------------------------------------------#
+# try getting module_name from dist directory name
+#--------------------------------------------------------------------------#
+
+$dist->change_build_pl(
+ dist_name => 'Random-Name',
+ dist_version => 1,
+)->regen;
+
+my $mb = $dist->new_from_context();
+isa_ok( $mb, "Module::Build" );
+is( $mb->module_name, "Not::So::Simple",
+ "module_name guessed from directory name"
+);
+
+#--------------------------------------------------------------------------#
+# Try getting module_name from dist_version_from
+#--------------------------------------------------------------------------#
+
+$dist->add_file( 'lib/Simple/Name.pm', << 'END_PACKAGE' );
+package Simple::Name;
+our $VERSION = 1.23;
+1;
+END_PACKAGE
+
+$dist->change_build_pl(
+ dist_name => 'Random-Name',
+ dist_version_from => 'lib/Simple/Name.pm',
+ dist_abstract => "Don't complain about missing abstract",
+)->regen( clean => 1 );
+
+$mb = $dist->new_from_context();
+isa_ok( $mb, "Module::Build" );
+is( $mb->module_name, "Simple::Name",
+ "module_name guessed from dist_version_from"
+);
+
+# vim:ts=2:sw=2:et:sta:sts=2