Author: dagolden
Date: Thu Aug 27 21:12:23 2009
New Revision: 13231

Added:
   Module-Build/trunk/t/share_dir.t   (contents, props changed)
Modified:
   Module-Build/trunk/lib/Module/Build/Base.pm

Log:
Added 'share_dir' parameter processing (no action yet)

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.



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 Thu Aug 27 21:12:23 2009
@@ -922,6 +922,7 @@
   recursive_test_files
   script_files
   scripts
+  share_dir
   sign
   test_files
   verbose
@@ -3561,6 +3562,63 @@
   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;
 

Added: Module-Build/trunk/t/share_dir.t
==============================================================================
--- (empty file)
+++ Module-Build/trunk/t/share_dir.t    Thu Aug 27 21:12:23 2009
@@ -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)"
+);
+
+
+
+

Reply via email to