contrib / buildsystems / Generators.pmon commit Merge branch 'jk/HEAD-symref-in-xfer-namespaces' (86d8730)
   1package Generators;
   2require Exporter;
   3
   4use strict;
   5use File::Basename;
   6no strict 'refs';
   7use vars qw($VERSION @AVAILABLE);
   8
   9our $VERSION = '1.00';
  10our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE);
  11@ISA = qw(Exporter);
  12
  13BEGIN {
  14    local(*D);
  15    my $me = $INC{"Generators.pm"};
  16    die "Couldn't find myself in \@INC, which is required to load the generators!" if ("$me" eq "");
  17    $me = dirname($me);
  18    if (opendir(D,"$me/Generators")) {
  19        foreach my $gen (readdir(D)) {
  20            next if ($gen  =~ /^\.\.?$/);
  21            require "${me}/Generators/$gen";
  22            $gen =~ s,\.pm,,;
  23            push(@AVAILABLE, $gen);
  24        }
  25        closedir(D);
  26        my $gens = join(', ', @AVAILABLE);
  27    }
  28
  29    push @EXPORT_OK, qw(available);
  30}
  31
  32sub available {
  33    return @AVAILABLE;
  34}
  35
  36sub generate {
  37    my ($gen, $git_dir, $out_dir, $rel_dir, %build_structure) = @_;
  38    return eval("Generators::${gen}::generate(\$git_dir, \$out_dir, \$rel_dir, \%build_structure)") if grep(/^$gen$/, @AVAILABLE);
  39    die "Generator \"${gen}\" is not available!\nAvailable generators are: @AVAILABLE\n";
  40}
  41
  421;