Commit | Line | Data |
cfaf3de0 |
1 | package SQL::Translator; |
2 | |
3 | use strict; |
4 | use ExtUtils::MakeMaker; |
4b6a6341 |
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); |
2b2601b5 |
26 | check_version('Template' => 2.10 => 1); |
4b6a6341 |
27 | check_version('Test::More' => 0 => 0); |
f74c6517 |
28 | check_version('Test::Exception' => 0 => 0); |
5d6b7412 |
29 | check_version('Test::Differences' => 0 => 0); |
4b6a6341 |
30 | check_version('Text::ParseWords' => 0 => 0); |
31 | check_version('Text::RecordParser' => 0.02 => 0); |
32 | check_version('XML::Writer' => 0 => 1); |
0d0a615b |
33 | check_version('XML::XPath' => 1.13 => 1); |
4b6a6341 |
34 | |
35 | print "\n"; |
36 | |
37 | if (@{$missing{'optional'}} + @{$missing{'required'}}) { |
38 | print "Some components might not work correctly:\n"; |
39 | my $count; |
1ea530d4 |
40 | if (@{$missing{'required'}}) { |
4b6a6341 |
41 | $count = scalar(@{$missing{'required'}}); |
42 | printf " You are missing %d required module%s: %s\n", |
43 | $count, |
44 | $count == 1 ? '' : 's', |
45 | join ', ', @{$missing{'required'}}; |
46 | } |
1ea530d4 |
47 | if (@{$missing{'optional'}}) { |
4b6a6341 |
48 | $count = scalar(@{$missing{'optional'}}); |
49 | printf " You are missing %d optional module%s: %s\n", |
50 | $count, |
51 | $count == 1 ? '' : 's', |
52 | join ', ', @{$missing{'optional'}}; |
53 | } |
54 | |
55 | print "\n"; |
56 | } |
cfaf3de0 |
57 | |
58 | WriteMakefile( |
59 | 'NAME' => __PACKAGE__, |
d5a20e63 |
60 | 'VERSION_FROM' => 'lib/SQL/Translator.pm', |
cfaf3de0 |
61 | 'EXE_FILES' => [ |
9e09fe5a |
62 | 'bin/sqlt-diagram', |
63 | 'bin/sqlt-dumper', |
64 | 'bin/sqlt-graph', |
65 | 'bin/sqlt', |
cfaf3de0 |
66 | ], |
4b6a6341 |
67 | 'PREREQ_PM' => \%PREREQ_PM, |
68 | 'clean' => { |
69 | FILES => '$(DISTVNAME).tar$(SUFFIX)', |
7a8e1f51 |
70 | }, |
cfaf3de0 |
71 | ); |
4b6a6341 |
72 | |
73 | # ---------------------------------------------------------------------- |
74 | # check_version($module, $version, $optional) |
75 | # |
76 | # Takes a module name, optional version number, and a flag indicating |
77 | # whether the module is optional (default is no). |
78 | # ---------------------------------------------------------------------- |
79 | sub check_version { |
80 | my ($module, $version, $optional) = @_; |
81 | my ($dots, $load); |
82 | |
83 | if ($version) { |
5d6b7412 |
84 | $version = sprintf "%.02f", $version; |
4b6a6341 |
85 | $load = "$module $version"; |
86 | } |
87 | else { |
88 | $load = $module; |
89 | } |
90 | |
91 | $dots = '.' x (36 - length($load)); |
92 | |
93 | eval "use $load;"; |
94 | if ($@) { |
95 | if ($optional) { |
96 | push @{$missing{'optional'}}, $module; |
97 | } |
98 | else { |
99 | push @{$missing{'required'}}, $module; |
100 | } |
101 | print "$load $dots not found!"; |
102 | if ($optional) { |
103 | print optional('not found!'), "\n"; |
104 | return; |
105 | } |
106 | print required('not found!'); |
107 | print "\n"; |
108 | } |
109 | else { |
110 | no strict qw(refs); |
5d6b7412 |
111 | my $ver = sprintf "%.02f" => ${"$module\::VERSION"}; |
112 | print "$load $dots $ver"; |
113 | print $optional ? optional($ver) : required($ver); |
4b6a6341 |
114 | print "\n"; |
5d6b7412 |
115 | $version = $ver; |
4b6a6341 |
116 | } |
117 | |
118 | $PREREQ_PM{$module} = $version; |
119 | } |
120 | |
121 | sub optional { return _message("[optional]", @_) } |
122 | sub required { return _message("", @_) } |
123 | |
124 | sub _message { |
125 | my ($message, $version) = @_; |
126 | my $size = 24 - (length "$version"); |
127 | my $fmt = '%' . $size . 's'; |
128 | sprintf $fmt => $message; |
129 | } |