Added dependencies from new XML modules.
[dbsrgits/SQL-Translator.git] / Makefile.PL
1 package SQL::Translator;
2
3 use strict;
4 use ExtUtils::MakeMaker;
5 $|++;
6
7 my %PREREQ_PM;
8 my %missing = (
9     optional => [ ],
10     required => [ ],
11 );
12
13 print "Checking for required and recommended modules.\n";
14 #              Module Name              Version Optional?
15 check_version('Class::Base'             => 0    => 0);
16 check_version('File::Basename'          => 0    => 0);
17 check_version('File::Spec'              => 0    => 0);
18 check_version('GD'                      => 0    => 1);
19 check_version('GraphViz'                => 0    => 1);
20 check_version('IO::Dir'                 => 0    => 0);
21 check_version('IO::File'                => 0    => 0);
22 check_version('IO::Scalar'              => 0    => 0);
23 check_version('Parse::RecDescent'       => 1.94 => 0);
24 check_version('Pod::Usage'              => 0    => 0);
25 check_version('Spreadsheet::ParseExcel' => 0    => 1);
26 check_version('Test::More'              => 0    => 0);
27 check_version('Test::Exception'         => 0    => 0);
28 check_version('Text::ParseWords'        => 0    => 0);
29 check_version('Text::RecordParser'      => 0.02 => 0);
30 check_version('XML::Writer'             => 0    => 1);
31 check_version('XML::XPath'              => 0    => 1);
32
33 print "\n";
34
35 if (@{$missing{'optional'}} + @{$missing{'required'}}) {
36     print "Some components might not work correctly:\n";
37     my $count;
38     if ($missing{'required'}) {
39         $count = scalar(@{$missing{'required'}});
40         printf "  You are missing %d required module%s: %s\n",
41             $count,
42             $count == 1 ? '' : 's',
43             join ', ', @{$missing{'required'}};
44     }
45     if ($missing{'optional'}) {
46         $count = scalar(@{$missing{'optional'}});
47         printf "  You are missing %d optional module%s: %s\n",
48             $count,
49             $count == 1 ? '' : 's',
50             join ', ', @{$missing{'optional'}};
51     }
52
53     print "\n";
54 }
55
56 WriteMakefile(
57     'NAME'         => __PACKAGE__,
58     'VERSION_FROM' => 'lib/SQL/Translator.pm',
59     'EXE_FILES'    => [
60         'bin/sqlt-diagram.pl',
61         'bin/sqlt-dumper.pl',
62         'bin/sqlt-graph.pl',
63         'bin/sql_translator.pl',
64     ],
65     'PREREQ_PM' => \%PREREQ_PM,
66     'clean' => {
67         FILES => '$(DISTVNAME).tar$(SUFFIX)',
68     },
69 );
70
71 # ----------------------------------------------------------------------
72 # check_version($module, $version, $optional)
73 #
74 # Takes a module name, optional version number, and a flag indicating
75 # whether the module is optional (default is no).
76 # ----------------------------------------------------------------------
77 sub check_version {
78     my ($module, $version, $optional) = @_;
79     my ($dots, $load);
80
81     if ($version) {
82         $load = "$module $version";
83     }
84     else {
85         $load = $module;
86     }
87
88     $dots = '.' x (36 - length($load));
89
90     eval "use $load;";
91     if ($@) {
92         if ($optional) {
93             push @{$missing{'optional'}}, $module;
94         }
95         else {
96             push @{$missing{'required'}}, $module;
97         }
98         print "$load $dots not found!";
99         if ($optional) {
100             print optional('not found!'), "\n";
101             return;
102         }
103         print required('not found!');
104         print "\n";
105     }
106     else {
107         no strict qw(refs);
108         my $version = ${"$module\::VERSION"};
109         print "$load $dots $version";
110         print $optional ? optional($version) : required($version);
111         print "\n";
112     }
113
114     $PREREQ_PM{$module} = $version;
115 }
116
117 sub optional { return _message("[optional]", @_) }
118 sub required { return _message("", @_) }
119
120 sub _message {
121     my ($message, $version) = @_;
122     my $size = 24 - (length "$version");
123     my $fmt = '%' . $size . 's';
124     sprintf $fmt => $message;
125 }