]>
Commit | Line | Data |
---|---|---|
259d87c3 MSO |
1 | package Generators; |
2 | require Exporter; | |
3 | ||
4 | use strict; | |
5 | use File::Basename; | |
6 | no strict 'refs'; | |
7 | use vars qw($VERSION @AVAILABLE); | |
8 | ||
9 | our $VERSION = '1.00'; | |
10 | our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE); | |
11 | @ISA = qw(Exporter); | |
12 | ||
13 | BEGIN { | |
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)) { | |
e88919bf | 20 | next unless ($gen =~ /\.pm$/); |
259d87c3 MSO |
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 | ||
32 | sub available { | |
33 | return @AVAILABLE; | |
34 | } | |
35 | ||
36 | sub 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 | ||
42 | 1; |