Skip to content

Commit

Permalink
Added 'share_dir' parameter processing (no action yet)
Browse files Browse the repository at this point in the history
This is the input side, that sets share_dir either by default 
or via parameters to new().  The action side that causes files
to be installed correctly as for File::ShareDir still has to
be written.



git-svn-id: http://svn.perl.org/modules/Module-Build/trunk@13231 50811bd7-b8ce-0310-adc1-d9db26280581
  • Loading branch information
xdg committed Aug 28, 2009
1 parent 876760c commit f65c83d
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 0 deletions.
58 changes: 58 additions & 0 deletions lib/Module/Build/Base.pm
Expand Up @@ -922,6 +922,7 @@ __PACKAGE__->add_property($_) for qw(
recursive_test_files
script_files
scripts
share_dir
sign
test_files
verbose
Expand Down Expand Up @@ -3561,6 +3562,63 @@ sub _files_in {
return @files;
}

sub share_dir {
my $self = shift;
my $p = $self->{properties};

$p->{share_dir} = shift if @_;

# Always coerce to proper hash form
if ( ! defined $p->{share_dir} ) {
# not set -- use default 'share' dir if exists
$p->{share_dir} = { dist => [ 'share' ] } if -d 'share';
}
elsif ( ! ref $p->{share_dir} ) {
# scalar -- treat as a single 'dist' directory
$p->{share_dir} = { dist => [ $p->{share_dir} ] };
}
elsif ( ref $p->{share_dir} eq 'ARRAY' ) {
# array -- treat as a list of 'dist' directories
$p->{share_dir} = { dist => $p->{share_dir} };
}
elsif ( ref $p->{share_dir} eq 'HASH' ) {
# hash -- check structure
my $share_dir = $p->{share_dir};
# check dist key
if ( defined $share_dir->{dist} ) {
if ( ! ref $share_dir->{dist} ) {
# scalar, so upgrade to arrayref
$share_dir->{dist} = [ $share_dir->{dist} ];
}
elsif ( ref $share_dir->{dist} ne 'ARRAY' ) {
die "'dist' key in 'share_dir' must be scalar or arrayref";
}
}
# check module key
if ( defined $share_dir->{module} ) {
my $mod_hash = $share_dir->{module};
if ( ref $mod_hash eq 'HASH' ) {
for my $k ( keys %$mod_hash ) {
if ( ! ref $mod_hash->{$k} ) {
$mod_hash->{$k} = [ $mod_hash->{$k} ];
}
elsif( ref $mod_hash->{$k} ne 'ARRAY' ) {
die "modules in 'module' key of 'share_dir' must be scalar or arrayref";
}
}
}
else {
die "'module' key in 'share_dir' must be hashref";
}
}
}
else {
die "'share_dir' must be hashref, arrayref or string";
}

return $p->{share_dir};
}

sub script_files {
my $self = shift;

Expand Down
157 changes: 157 additions & 0 deletions t/share_dir.t
@@ -0,0 +1,157 @@
#!/usr/bin/perl -w

use strict;
use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
use MBTest;
use File::Spec::Functions qw/catdir catfile/;

#--------------------------------------------------------------------------#
# Begin testing
#--------------------------------------------------------------------------#

plan tests => 12;

require_ok('Module::Build');
ensure_blib('Module::Build');

#--------------------------------------------------------------------------#
# Create test distribution
#--------------------------------------------------------------------------#

my $tmp = MBTest->tmpdir;

use DistGen;
my $dist = DistGen->new( dir => $tmp );

$dist->regen;
END{ $dist->remove }

$dist->chdir_in;

#--------------------------------------------------------------------------#
# Test setting 'share_dir'
#--------------------------------------------------------------------------#

my $mb = $dist->new_from_context;

# Test without a 'share' dir
ok( $mb, "Created Module::Build object" );
is( $mb->share_dir, undef,
"default share undef if no 'share' dir exists"
);

# Add 'share' dir and an 'other' dir and content
$dist->add_file('share/foo.txt',<< '---');
This is foo.txt
---
$dist->add_file('other/bar.txt',<< '---');
This is bar.txt
---
$dist->regen;
ok( -e catfile(qw/share foo.txt/), "Created 'share' directory" );

# Check default when share_dir is not given
$mb = $dist->new_from_context;
is_deeply( $mb->share_dir, { dist => [ 'share' ] },
"Default share_dir set as dist-type share"
);

# share_dir set to scalar
$dist->change_build_pl(
{
module_name => $dist->name,
license => 'perl',
share_dir => 'share',
}
);
$dist->regen;
$mb = $dist->new_from_context;
is_deeply( $mb->share_dir, { dist => [ 'share' ] },
"Scalar share_dir set as dist-type share"
);

# share_dir set to arrayref
$dist->change_build_pl(
{
module_name => $dist->name,
license => 'perl',
share_dir => [ 'share' ],
}
);
$dist->regen;
$mb = $dist->new_from_context;
is_deeply( $mb->share_dir, { dist => [ 'share' ] },
"Arrayref share_dir set as dist-type share"
);

# share_dir set to hashref w scalar
$dist->change_build_pl(
{
module_name => $dist->name,
license => 'perl',
share_dir => { dist => 'share' },
}
);
$dist->regen;
$mb = $dist->new_from_context;
is_deeply( $mb->share_dir, { dist => [ 'share' ] },
"Hashref share_dir w/ scalar dist set as dist-type share"
);

# share_dir set to hashref w array
$dist->change_build_pl(
{
module_name => $dist->name,
license => 'perl',
share_dir => { dist => [ 'share' ] },
}
);
$dist->regen;
$mb = $dist->new_from_context;
is_deeply( $mb->share_dir, { dist => [ 'share' ] },
"Hashref share_dir w/ arrayref dist set as dist-type share"
);

# Generate a module sharedir (scalar)
$dist->change_build_pl(
{
module_name => $dist->name,
license => 'perl',
share_dir => {
dist => 'share',
module => { $dist->name => 'other' },
},
}
);
$dist->regen;
$mb = $dist->new_from_context;
is_deeply( $mb->share_dir,
{ dist => [ 'share' ],
module => { $dist->name => ['other'] },
},
"Hashref share_dir w/ both dist and module shares (scalar-form)"
);

# Generate a module sharedir (array)
$dist->change_build_pl(
{
module_name => $dist->name,
license => 'perl',
share_dir => {
dist => [ 'share' ],
module => { $dist->name => ['other'] },
},
}
);
$dist->regen;
$mb = $dist->new_from_context;
is_deeply( $mb->share_dir,
{ dist => [ 'share' ],
module => { $dist->name => ['other'] },
},
"Hashref share_dir w/ both dist and module shares (array-form)"
);




0 comments on commit f65c83d

Please sign in to comment.