# -*- Mode: perl; indent-tabs-mode: nil -*- # # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # implied. See the License for the specific language governing # rights and limitations under the License. # # The Original Code is the Bugzilla Bug Tracking System. # # Contributor(s): Max Kanat-Alexander package Bugzilla::Install::Requirements; # NOTE: This package MUST NOT "use" any Bugzilla modules other than # Bugzilla::Constants, anywhere. We may "use" standard perl modules. # # Subroutines may "require" and "import" from modules, but they # MUST NOT "use." use strict; use base qw(Exporter); our @EXPORT = qw( REQUIRED_MODULES OPTIONAL_MODULES MOD_PERL_MODULES vers_cmp have_vers install_command ); use Bugzilla::Constants; use constant REQUIRED_MODULES => [ { name => 'AppConfig', version => '1.52' }, { name => 'CGI', version => '2.93' }, { name => 'Data::Dumper', version => '0' }, { name => 'Date::Format', version => '2.21' }, { name => 'DBI', version => '1.41' }, { name => 'File::Spec', version => '0.84' }, { name => 'File::Temp', version => '0' }, { name => 'Template', version => '2.08' }, { name => 'Text::Wrap', version => '2001.0131' }, { name => 'Mail::Mailer', version => '1.67' }, { name => 'MIME::Base64', version => '3.01' }, { # MIME::Parser is packaged as MIME::Tools on ActiveState Perl name => $^O =~ /MSWin32/i ? 'MIME::Tools' : 'MIME::Parser', version => '5.406' }, { name => 'Storable', version => '0' }, ]; use constant OPTIONAL_MODULES => [ { name => 'GD', version => '1.20' }, { # This module tells us whether or not Template-GD is installed # on Template-Toolkits after 2.14, and still works with 2.14 and lower. name => 'Template::Plugin::GD::Image', version => 0 }, { name => 'Chart::Base', version => '1.0' }, { name => 'GD::Graph', version => 0 }, { name => 'GD::Text::Align', version => 0 }, { name => 'XML::Twig', version => 0 }, { name => 'LWP::UserAgent', version => 0 }, { name => 'PatchReader', version => '0.9.4' }, { name => 'Image::Magick', version => 0 }, { name => 'Net::LDAP', version => 0 }, ]; # These are only required if you want to use Bugzilla with # mod_perl. use constant MOD_PERL_MODULES => [ { name => 'mod_perl2', version => '1.999022' }, # Even very new releases of perl (5.8.5) don't come with this version, # so I didn't want to make it a general requirement just for # running under mod_cgi. { name => 'CGI', version => '3.11' }, { name => 'Apache::DBI', version => '0.96' }, ]; # Remember that you only have to add modules to this hash if their # names are significantly different on ActiveState than on normal perl. # If it's just a difference between "::" and "-" in the name, don't worry # about it--install_command() handles that automatically. use constant WIN32_MODULE_NAMES => { 'Chart::Base' => 'Chart', 'Date::Format' => 'TimeDate', 'Template' => 'Template-Toolkit', 'GD::Graph' => 'GDGraph', 'GD::Text::Align' => 'GDTextUtil', 'Mail::Mailer' => 'MailTools', # We provide Template 2.14 or lower for Win32, so it still includes # the GD plugin. 'Template::Plugin::GD' => 'Template', }; # This was originally clipped from the libnet Makefile.PL, adapted here to # use the below vers_cmp routine for accurate version checking. sub have_vers { my ($pkg, $wanted, $silent) = @_; my ($msg, $vnum, $vstr); no strict 'refs'; printf("Checking for %15s %-9s ", $pkg, !$wanted?'(any)':"(v$wanted)") unless $silent; # Modules may change $SIG{__DIE__} and $SIG{__WARN__}, so localise them here # so that later errors display 'normally' local $::SIG{__DIE__}; local $::SIG{__WARN__}; eval "require $pkg;"; # do this twice to avoid a "used only once" error for these vars $vnum = ${"${pkg}::VERSION"} || ${"${pkg}::Version"} || 0; $vnum = ${"${pkg}::VERSION"} || ${"${pkg}::Version"} || 0; $vnum = -1 if $@; # CGI's versioning scheme went 2.75, 2.751, 2.752, 2.753, 2.76 # That breaks the standard version tests, so we need to manually correct # the version if ($pkg eq 'CGI' && $vnum =~ /(2\.7\d)(\d+)/) { $vnum = $1 . "." . $2; } if ($vnum eq "-1") { # string compare just in case it's non-numeric $vstr = "not found"; } elsif (vers_cmp($vnum,"0") > -1) { $vstr = "found v$vnum"; } else { $vstr = "found unknown version"; } my $vok = (vers_cmp($vnum,$wanted) > -1); print ((($vok) ? "ok: " : " "), "$vstr\n") unless $silent; return $vok ? 1 : 0; } # This is taken straight from Sort::Versions 1.5, which is not included # with perl by default. sub vers_cmp { my ($a, $b) = @_; # Remove leading zeroes - Bug 344661 $a =~ s/^0*(\d.+)/$1/; $b =~ s/^0*(\d.+)/$1/; my @A = ($a =~ /([-.]|\d+|[^-.\d]+)/g); my @B = ($b =~ /([-.]|\d+|[^-.\d]+)/g); my ($A, $B); while (@A and @B) { $A = shift @A; $B = shift @B; if ($A eq '-' and $B eq '-') { next; } elsif ( $A eq '-' ) { return -1; } elsif ( $B eq '-') { return 1; } elsif ($A eq '.' and $B eq '.') { next; } elsif ( $A eq '.' ) { return -1; } elsif ( $B eq '.' ) { return 1; } elsif ($A =~ /^\d+$/ and $B =~ /^\d+$/) { if ($A =~ /^0/ || $B =~ /^0/) { return $A cmp $B if $A cmp $B; } else { return $A <=> $B if $A <=> $B; } } else { $A = uc $A; $B = uc $B; return $A cmp $B if $A cmp $B; } } @A <=> @B; } sub install_command { my $module = shift; if ($^O =~ /MSWin32/i) { return "ppm install " . WIN32_MODULE_NAMES->{$module} if WIN32_MODULE_NAMES->{$module}; $module =~ s/::/-/g; return "ppm install " . $module; } else { return "$^X -MCPAN -e 'install \"$module\"'"; } } 1; __END__ =head1 NAME Bugzilla::Install::Requirements - Functions and variables dealing with Bugzilla's perl-module requirements. =head1 DESCRIPTION This module is used primarily by C to determine whether or not all of Bugzilla's prerequisites are installed. (That is, all the perl modules it requires.) =head1 CONSTANTS =over 4 =item C An arrayref of hashrefs that describes the perl modules required by Bugzilla. The hashes have two keys, C and C, which represent the name of the module and the version that we require. =back =head1 SUBROUTINES =over 4 =item C Description: This is a comparison function, like you would use in C, except that it compares two version numbers. It's actually identical to versioncmp from L. Params: c<$a> and C<$b> are versions you want to compare. Returns: -1 if $a is less than $b, 0 if they are equal, and 1 if $a is greater than $b. =item C Description: Tells you whether or not you have the appropriate version of the module requested. It also prints out a message to the user explaining the check and the result. Params: C<$pkg> - A string, the name of the package you're checking. C<$wanted> - The version of the package you require. Set this to 0 if you don't require any particular version. C<$silent> - Set to true if you don't want this function to print out anything. Returns: C<1> if you have the module installed and you have the appropriate version. C<0> otherwise. =item C Description: Prints out the appropriate command to install the module specified, depending on whether you're on Windows or Linux. Params: C<$module> - The name of the module. Returns: nothing =back