"Fossies" - the Fresh Open Source Software Archive

Member "Module-Build-0.4224/t/install_extra_target.t" (30 May 2017, 3008 Bytes) of package /linux/privat/Module-Build-0.4224.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!perl -w
    2 # Contributed by: Thorben Jaendling
    3 
    4 use strict;
    5 use lib 't/lib';
    6 use MBTest tests => 6;
    7 
    8 blib_load('Module::Build');
    9 
   10 use File::Spec::Functions qw( catdir catfile );
   11 
   12 my $tmp = MBTest->tmpdir;
   13 my $output;
   14 
   15 use DistGen;
   16 my $dist = DistGen->new( dir => $tmp );
   17 
   18 # note("Dist is in $tmp\n");
   19 
   20 $dist->add_file("Build.PL", <<'===EOF===');
   21 #!perl -w
   22 
   23 use strict;
   24 use Module::Build;
   25 
   26 my $subclass = Module::Build->subclass(code => <<'=EOF=');
   27 sub copy_files
   28 {
   29 	my $self = shift;
   30 	my $dir = shift;
   31 
   32 	my $files = $self->rscan_dir($dir, sub {-f $_ and not m!/\.|[#~]$!});
   33 
   34 	foreach my $file (@$files) {
   35 		$self->copy_if_modified(from => $file, to_dir => "blib");
   36 	}
   37 }
   38 
   39 #Copy etc files to blib
   40 sub process_etc_files
   41 {
   42 	my $self = shift;
   43 
   44 	$self->copy_files("etc");
   45 }
   46 
   47 #Copy share files to blib
   48 sub process_shared_files
   49 {
   50 	my $self = shift;
   51 
   52 	$self->copy_files("shared");
   53 }
   54 
   55 1;
   56 =EOF=
   57 
   58 my $build = $subclass->new(
   59 	module_name => 'Simple',
   60 	license     => 'perl'
   61 );
   62 
   63 $build->add_build_element('etc');
   64 $build->add_build_element('shared');
   65 
   66 my $distdir = lc $build->dist_name();
   67 
   68 foreach my $id ('core', 'site', 'vendor') {
   69 	#Where to install these build types when using prefix symantics
   70 	$build->prefix_relpaths($id, 'shared' => "shared/$distdir");
   71 	$build->prefix_relpaths($id, 'etc' => "etc/$distdir");
   72 
   73 	#Where to install these build types when using default symantics
   74 	my $set = $build->install_sets($id);
   75 	$set->{'shared'} = '/usr/'.($id eq 'site' ? 'local/':'')."shared/$distdir";
   76 	$set->{'etc'} = ($id eq 'site' ? '/usr/local/etc/':'/etc/').$distdir;
   77 }
   78 
   79 #Where to install these types when using install_base symantics
   80 $build->install_base_relpaths('shared' => "shared/$distdir");
   81 $build->install_base_relpaths('etc' => "etc/$distdir");
   82 
   83 $build->create_build_script();
   84 
   85 ===EOF===
   86 
   87 #Test Build.PL exists ok?
   88 
   89 $dist->add_file("etc/config", <<'===EOF===');
   90 [main]
   91 Foo = bar
   92 Jim = bob
   93 
   94 [supplemental]
   95 stardate = 1234344
   96 
   97 ===EOF===
   98 
   99 $dist->add_file("shared/data", <<'===EOF===');
  100 7 * 9 = 42?
  101 
  102 ===EOF===
  103 
  104 $dist->add_file("shared/html/index.html", <<'===EOF===');
  105 <HTML>
  106   <BODY>
  107     <H1>Hello World!</H1>
  108   </BODY>
  109 </HTML>
  110 
  111 ===EOF===
  112 
  113 $dist->regen;
  114 $dist->chdir_in;
  115 
  116 my $installdest = catdir($tmp, 't', "install_extra_targets-$$");
  117 
  118 $output = stdout_of sub { $dist->run_build_pl("--install_base=$installdest") };
  119 
  120 $output .= stdout_of sub { $dist->run_build };
  121 
  122 my $error;
  123 $error++ unless ok(-e "blib/etc/config", "Built etc/config");
  124 $error++ unless ok(-e "blib/shared/data", "Built shared/data");
  125 $error++ unless ok(-e "blib/shared/html/index.html", "Built shared/html");
  126 diag "OUTPUT:\n$output" if $error;
  127 
  128 $output = stdout_of sub { $dist->run_build('install') };
  129 
  130 $error = 0;
  131 $error++ unless ok(-e catfile($installdest, qw/etc simple config/), "installed etc/config");
  132 $error++ unless ok(-e catfile($installdest, qw/shared simple data/), "installed shared/data");
  133 $error++ unless ok(-e catfile($installdest, qw/shared simple html index.html/), "installed shared/html");
  134 diag "OUTPUT:\n$output" if $error;
  135