From a34d086a24b1e4519f8b31331d4c42b87b8e4a83 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 26 Oct 2017 16:28:02 +0000 Subject: [PATCH] Bug 19735: Move Perl deps definitions into a cpanfile cpanfile is a format for describing CPAN dependencies for Perl applications. It is more concise - thus easier to read and maintain - than C4::Installer::PerlDependencies, and allows to describe requirements more accurately (using version ranges or features for instance) Additionally it can be read by tools such as cpanm or carton for an easy way to install dependencies on non-Debian-based systems. For more information on cpanfile, see http://search.cpan.org/~miyagawa/Module-CPANfile-1.1002/lib/cpanfile.pod This patch replace C4::Installer::PerlDependencies by an equivalent cpanfile and update all scripts/modules that were using PerlDependencies It also removes dead code from C4::Installer::PerlModules (some subroutines were not used at all, except in unit tests) Added dependencies: - Module::CPANfile - CPAN::Meta (dependency of Module::CPANfile, but we need a more recent version than the one Module::CPANfile requires) Test plan: 1. Go to About page, tab Perl modules and keep this browser tab open 2. Apply patch 3. Install Module::CPANfile and CPAN::Meta a. On Debian-based systems: # will install libcpan-meta-perl as a dependency sudo apt install libmodule-cpanfile-perl b. Others: # will install CPAN::Meta as a dependency sudo cpanm Module::CPANfile 4. In a new browser tab, go to About page, tab Perl modules and compare the table with the one in the previous browser tab They should be identical, except for newly added dependencies (Module::CPANfile and CPAN::Meta) 5. Do a 'standard' install a. perl Makefile.PL (select 'standard') b. make c. sudo make install d. Configure your database, web server, ... and go through the web install process 6. Verify that the cpanfile got copied into PERL_MODULE_DIR (which should be /usr/share/koha/lib) 7. Go to the about page of this fresh install and compare it with your dev install 8. Verify that debian/list-deps still works This takes a lot of time and it may not be necessary to wait until the end. If you see some Debian package names that correspond to modules in cpanfile, it means it still works (you need apt-file for this script to work) 9. Verify that koha_perl_deps.pl still works 10. prove t/Installer_pm.t t/Installer_PerlModules.t Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- C4/Installer.pm | 1 - C4/Installer/PerlModules.pm | 181 ++++++++++---------------------- Makefile.PL | 3 +- about.pl | 2 +- cpanfile | 184 +++++++++++++++++++++++++++++++++ debian/list-deps | 112 ++++++++++---------- installer/install.pl | 1 + t/Installer_PerlDependencies.t | 14 --- t/Installer_PerlModules.t | 42 +------- t/Installer_pm.t | 12 +-- 10 files changed, 305 insertions(+), 247 deletions(-) create mode 100644 cpanfile delete mode 100755 t/Installer_PerlDependencies.t diff --git a/C4/Installer.pm b/C4/Installer.pm index 0a6fca8d9d..2180d859c2 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -22,7 +22,6 @@ use Modern::Perl; use Encode qw( encode is_utf8 ); use DBIx::RunSQL; use C4::Context; -use C4::Installer::PerlModules; use DBI; use Koha; diff --git a/C4/Installer/PerlModules.pm b/C4/Installer/PerlModules.pm index affcd78365..f76bb4a38b 100644 --- a/C4/Installer/PerlModules.pm +++ b/C4/Installer/PerlModules.pm @@ -4,11 +4,8 @@ use warnings; use strict; use File::Spec; - -use C4::Installer::PerlDependencies; - - -our $PERL_DEPS = $C4::Installer::PerlDependencies::PERL_DEPS; +use File::Basename; +use Module::CPANfile; sub new { my $invocant = shift; @@ -17,44 +14,34 @@ sub new { upgrade_pm => [], current_pm => [], }; + my $type = ref($invocant) || $invocant; bless ($self, $type); return $self; } -sub prereq_pm { +sub prereqs { my $self = shift; - my $prereq_pm = {}; - for (keys %$PERL_DEPS) { - $prereq_pm->{$_} = $PERL_DEPS->{$_}->{'min_ver'}; + + unless (defined $self->{prereqs}) { + my $filename = $INC{'C4/Installer/PerlModules.pm'}; + my $path = dirname(dirname(dirname($filename))); + $self->{prereqs} = Module::CPANfile->load("$path/cpanfile")->prereqs; } - return $prereq_pm; + + return $self->{prereqs}; } -sub required { +sub prereq_pm { my $self = shift; - my %params = @_; - if ($params{'module'}) { - return -1 unless grep {m/$params{'module'}/} keys(%$PERL_DEPS); - return $PERL_DEPS->{$params{'module'}}->{'required'}; - } - elsif ($params{'required'}) { - my $required_pm = []; - for (keys %$PERL_DEPS) { - push (@$required_pm, $_) if $PERL_DEPS->{$_}->{'required'} == 1; - } - return $required_pm; - } - elsif ($params{'optional'}) { - my $optional_pm = []; - for (keys %$PERL_DEPS) { - push (@$optional_pm, $_) if $PERL_DEPS->{$_}->{'required'} == 0; - } - return $optional_pm; - } - else { - return -1; # unrecognized parameter passed in + + my $prereq_pm = {}; + my $reqs = $self->prereqs->merged_requirements; + foreach my $module ($reqs->required_modules) { + $prereq_pm->{$module} = $reqs->requirements_for_module($module); } + + return $prereq_pm; } sub versions_info { @@ -65,58 +52,44 @@ sub versions_info { $self->{'upgrade_pm'} = []; $self->{'current_pm'} = []; - for my $module ( sort keys %$PERL_DEPS ) { - my $module_infos = $self->version_info($module); - my $status = $module_infos->{status}; - push @{ $self->{"${status}_pm"} }, { $module => $module_infos }; + foreach my $phase ($self->prereqs->phases) { + foreach my $type ($self->prereqs->types_in($phase)) { + my $reqs = $self->prereqs->requirements_for($phase, $type); + foreach my $module ($reqs->required_modules) { + no warnings; # perl throws warns for invalid $VERSION numbers which some modules use + + my $module_infos = { + cur_ver => 0, + min_ver => $reqs->requirements_for_module($module), + required => $type eq 'requires', + }; + + my $attr; + + $Readonly::XS::MAGIC_COOKIE="Do NOT use or require Readonly::XS unless you're me."; + eval "require $module"; + if ($@) { + $attr = 'missing_pm'; + } else { + my $pkg_version = $module->can("VERSION") ? $module->VERSION : 0; + $module_infos->{cur_ver} = $pkg_version; + if ($reqs->accepts_module($module => $pkg_version)) { + $attr = 'current_pm'; + } else { + $attr = 'upgrade_pm'; + } + } + + push @{ $self->{$attr} }, { $module => $module_infos }; + } + } } } -sub version_info { - no warnings - ; # perl throws warns for invalid $VERSION numbers which some modules use - my ( $self, $module ) = @_; - return -1 unless grep { /^$module$/ } keys(%$PERL_DEPS); - - $Readonly::XS::MAGIC_COOKIE="Do NOT use or require Readonly::XS unless you're me."; - eval "require $module"; - my $pkg_version = $module->can("VERSION") ? $module->VERSION : 0; - my $min_version = $PERL_DEPS->{$module}->{'min_ver'} // 0; - - my ( $cur_ver, $upgrade, $status ); - if ($@) { - ( $cur_ver, $upgrade, $status ) = ( 0, 0, 'missing' ); - } - elsif ( version->parse("$pkg_version") < version->parse("$min_version") ) { - ( $cur_ver, $upgrade, $status ) = ( $module->VERSION, 1, 'upgrade' ); - } - else { - ( $cur_ver, $upgrade, $status ) = ( $module->VERSION, 0, 'current' ); - } - - return { - cur_ver => $cur_ver, - min_ver => $PERL_DEPS->{$module}->{min_ver}, - required => $PERL_DEPS->{$module}->{required}, - usage => $PERL_DEPS->{$module}->{usage}, - upgrade => $upgrade, - status => $status, - }; -} - - sub get_attr { return $_[0]->{$_[1]}; } -sub module_count { - return scalar(keys(%$PERL_DEPS)); -} - -sub module_list { - return keys(%$PERL_DEPS); -} - 1; __END__ @@ -148,39 +121,16 @@ A module for manipulating Koha Perl dependency list objects. PREREQ_PM => $perl_modules->prereq_pm,> -=head2 required() - - This method accepts a single parameter with three possible values: a module name, the keyword 'required,' the keyword 'optional.' If passed the name of a module, a boolean value is returned indicating whether the module is required (1) or not (0). If on of the two keywords is passed in, it returns an arrayref to an array who's elements are the names of the modules specified either required or optional. - - example: - Crequired(module => 'CGI::Carp');> - - Crequired(optional => 1);> - -=head2 version_info() - - Depending on the parameters passed when invoking, this method will give the current status of modules currently used in Koha as well as the currently installed version if the module is installed, the current minimum required version, and the upgrade status. If passed C module_name>, the method evaluates only that module. If passed C 1>, all modules are evaluated. - example: - Cversion_info('foo');> - - This usage returns a hashref with a single key/value pair. The key is the module name. The value is an anonymous hash with the following keys: - - cur_ver = version number of the currently installed version (This is 0 if the module is not currently installed.) - min_ver = minimum version required by Koha - upgrade = upgrade status of the module relative to Koha's requirements (0 if the installed module does not need upgrading; 1 if it does) - required = 0 of the module is optional; 1 if required - - { - 'required' => 1, - 'cur_ver' => '1.30_01', - 'upgrade' => 0, - 'min_ver' => '1.29' - }; +=head2 versions_info - C<$perl_modules->version_info;> + C<$perl_modules->versions_info;> - This usage loads the same basic data as the previous usage into three accessors: missing_pm, upgrade_pm, and current_pm. Each of these may be accessed by using the C method. Each accessor returns an anonymous array who's elements are anonymous hashes. They follow this format (NOTE: Upgrade status is indicated by the accessor name.): + This loads info of required modules into three accessors: missing_pm, + upgrade_pm, and current_pm. Each of these may be accessed by using the + C method. Each accessor returns an anonymous array who's + elements are anonymous hashes. They follow this format (NOTE: Upgrade + status is indicated by the accessor name.): [ { @@ -212,23 +162,6 @@ A module for manipulating Koha Perl dependency list objects. example: Cget_attr('missing_pm');> -=head2 module_count - - Returns a scalar value representing the current number of Perl modules used by Koha. - - example: - Cmodule_count;> - -=head2 module_list - - Returns an array who's elements are the names of the Perl modules used by Koha. - - example: - Cmodule_list;> - - This is useful for commandline exercises such as: - - perl -MC4::Installer::PerlModules -e 'my $deps = C4::Installer::PerlModule->new; print (join("\n",$deps->module_list));' =head1 AUTHOR diff --git a/Makefile.PL b/Makefile.PL index 18ae802387..f65e832e8b 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -29,7 +29,7 @@ use FindBin; # we need to enforce which C4::Installer::PerlModule is used in cas use lib $FindBin::Bin; -use C4::Installer; +use C4::Installer::PerlModules; my $koha_pm = C4::Installer::PerlModules->new; @@ -314,6 +314,7 @@ my $target_map = { './circ' => 'INTRANET_CGI_DIR', './clubs' => 'INTRANET_CGI_DIR', './course_reserves' => 'INTRANET_CGI_DIR', + './cpanfile' => 'PERL_MODULE_DIR', './docs/history.txt' => { target => 'DOC_DIR', trimdir => -1 }, './docs/contributors.yaml' => { target => 'DOC_DIR', trimdir => -1 }, './docs/teams.yaml' => { target => 'DOC_DIR', trimdir => -1 }, diff --git a/about.pl b/about.pl index 42fe42f170..fa52ce41f0 100755 --- a/about.pl +++ b/about.pl @@ -37,7 +37,7 @@ use YAML qw/LoadFile/; use C4::Output; use C4::Auth; use C4::Context; -use C4::Installer; +use C4::Installer::PerlModules; use Koha; use Koha::DateUtils qw(dt_from_string output_pref); diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000000..13b3a2ba7e --- /dev/null +++ b/cpanfile @@ -0,0 +1,184 @@ +requires 'Algorithm::CheckDigits', '0.5'; +requires 'Authen::CAS::Client', '0.05'; +requires 'Biblio::EndnoteStyle', '0.05'; +requires 'Business::ISBN', '2.05'; +requires 'Business::ISSN', '0.91'; +requires 'Bytes::Random::Secure', '0.28'; +requires 'CGI', '3.15'; +requires 'CGI::Carp', '1.29'; +requires 'CGI::Compile', '0.17'; +requires 'CGI::Emulate::PSGI', '0.20'; +requires 'CGI::Session', '4.2'; +requires 'CGI::Session::Serialize::yaml', '4.2'; +requires 'CPAN::Meta', '2.150006'; +requires 'Cache::Memcached', '1.30'; +requires 'Class::Accessor', '0.3'; +requires 'Class::Factory::Util', '1.6'; +requires 'Class::Inspector', '1.31'; +requires 'Clone', '0.37'; +requires 'Crypt::Eksblowfish::Bcrypt', '0.008'; +requires 'DBD::Mock', '1.39'; +requires 'DBD::mysql', '4.004'; +requires 'DBI', '1.53'; +requires 'DBIx::Class::Schema::Loader', '0.07039'; +requires 'DBIx::RunSQL', '0.14'; +requires 'Data::Dumper', '2.121'; +requires 'Data::ICal', '0.13'; +requires 'Date::Calc', '5.4'; +requires 'Date::Manip', '5.44'; +requires 'DateTime', '0.58'; +requires 'DateTime::Event::ICal', '0.08'; +requires 'DateTime::Format::ICal', '0.09'; +requires 'DateTime::Format::MySQL', '0.04'; +requires 'DateTime::Set', '0.28'; +requires 'DateTime::TimeZone', '1.20'; +requires 'Digest::MD5', '2.36'; +requires 'Digest::SHA', '5.43'; +requires 'Email::Date', '1.103'; +requires 'Email::Valid', '0.190'; +requires 'Exception::Class', '1.38'; +requires 'File::Slurp', '9999.13'; +requires 'Font::TTF', '0.45'; +requires 'GD::Barcode::UPCE', '1.1'; +requires 'Getopt::Long', '2.35'; +requires 'Getopt::Std', '1.05'; +requires 'HTML::Entities', '3.69'; +requires 'HTML::FormatText', '1.23'; +requires 'HTML::Scrubber', '0.08'; +requires 'HTTP::Cookies', '1.39'; +requires 'HTTP::OAI', '3.2'; +requires 'HTTP::Request::Common', '1.26'; +requires 'IPC::Cmd', '0.46'; +requires 'JSON', '2.07'; +requires 'JSON::Validator', '0.97'; +requires 'LWP::Simple', '1.41'; +requires 'LWP::UserAgent', '2.033'; +requires 'Library::CallNumber::LC', '0.22'; +requires 'Lingua::Stem', '0.82'; +requires 'Lingua::Stem::Snowball', '0.952'; +requires 'List::MoreUtils', '0.21'; +requires 'List::Util', '1.18'; +requires 'Locale::Currency::Format', '1.28'; +requires 'Locale::Language', '2.07'; +requires 'Locale::Messages', '1.20'; +requires 'Locale::PO', '0.17'; +requires 'Log::Log4perl', '1.29'; +requires 'MARC::Charset', '0.98'; +requires 'MARC::File::XML', 'v1.0.1'; +requires 'MARC::Record', 'v2.0.6'; +requires 'MARC::Record::MiJ', '0.04'; +requires 'MIME::Base64', '3.07'; +requires 'MIME::Lite', '3'; +requires 'MIME::QuotedPrint', '3.07'; +requires 'Mail::Sendmail', '0.79'; +requires 'Modern::Perl', '1.03'; +requires 'Module::CPANfile', '1.1000'; +requires 'Mojolicious', '7.21'; +requires 'Mojolicious::Plugin::OpenAPI', '1.15'; +requires 'Net::CIDR', '0.17'; +requires 'Net::Netmask', '1.9022'; +requires 'Net::Z3950::ZOOM', '1.16'; +requires 'Number::Format', '1.52'; +requires 'OpenOffice::OODoc', '2.125'; +requires 'PDF::API2', '2'; +requires 'PDF::API2::Page', '2'; +requires 'PDF::API2::Simple', '1'; +requires 'PDF::API2::Util', '2'; +requires 'PDF::Reuse', '0.36'; +requires 'PDF::Reuse::Barcode', '0.05'; +requires 'PDF::Table', 'v0.9.3'; +requires 'POSIX', '1.09'; +requires 'Plack::Middleware::ReverseProxy', '0.14'; +requires 'Schedule::At', '1.06'; +requires 'Search::Elasticsearch', '5.01'; +requires 'Sereal::Decoder', '3.0'; +requires 'Sereal::Encoder', '3.0'; +requires 'Storable', '2.20'; +requires 'String::Random', '0.22'; +requires 'Template', '2.22'; +requires 'Template::Plugin::HtmlToText', '0.03'; +requires 'Template::Plugin::JSON::Escape', '0.02'; +requires 'Term::ANSIColor', '1.1'; +requires 'Test', '1.25'; +requires 'Test::Harness', '2.56'; +requires 'Test::MockModule', '0.05'; +requires 'Test::More', '1.302073'; +requires 'Text::Bidi', '0.03'; +requires 'Text::CSV', '0.01'; +requires 'Text::CSV::Encoded', '0.09'; +requires 'Text::CSV_XS', '0.32'; +requires 'Text::Iconv', '1.7'; +requires 'Text::PDF', '0.29'; +requires 'Text::Wrap', '2005.082401'; +requires 'Time::HiRes', '1.86'; +requires 'Time::localtime', '1.02'; +requires 'Try::Tiny', '0.22'; +requires 'UNIVERSAL::can', '1.10'; +requires 'URI::Escape', '3.31'; +requires 'UUID', '0.05'; +requires 'Unicode::Normalize', '0.32'; +requires 'WWW::CSRF', '1.00'; +requires 'XML::Dumper', '0.81'; +requires 'XML::LibXML', '1.59'; +requires 'XML::LibXSLT', '1.59'; +requires 'XML::RSS', '1.31'; +requires 'XML::SAX::ParserFactory', '1.01'; +requires 'XML::SAX::Writer', '0.44'; +requires 'XML::Simple', '2.14'; +requires 'YAML', '0.71'; +requires 'YAML::Syck', '0.71'; +recommends 'AnyEvent', '5.0'; +recommends 'AnyEvent::HTTP', '2.13'; +recommends 'Archive::Extract', '0.60'; +recommends 'Archive::Zip', '1.30'; +recommends 'Array::Utils', '0.5'; +recommends 'CGI::Session::Driver::memcached', '0.04'; +recommends 'Cache::FastMmap', '1.34'; +recommends 'Cache::Memcached::Fast', '0.19'; +recommends 'Cache::Memcached::Fast::Safe', '0.06'; +recommends 'DBD::SQLite2', '0.33'; +recommends 'Devel::Cover', '0.89'; +recommends 'File::Copy', '2.08'; +recommends 'File::Path', '2.07'; +recommends 'File::Temp', '0.22'; +recommends 'GD', '2.39'; +recommends 'Graphics::Magick', 'v1.3.5'; +recommends 'Gravatar::URL', '1.03'; +recommends 'HTTPD::Bench::ApacheBench', '0.73'; +recommends 'LWP::Protocol::https', '5.836'; +recommends 'Lingua::Ispell', '0.07'; +recommends 'Module::Bundled::Files', '0.03'; +recommends 'Module::Load::Conditional', '0.38'; +recommends 'Module::Pluggable', '3.9'; +recommends 'Moo', '1'; +recommends 'Net::LDAP', '0.33'; +recommends 'Net::LDAP::Filter', '0.14'; +recommends 'Net::OAuth2::AuthorizationServer', '0.16'; +recommends 'Net::SFTP::Foreign', '1.73'; +recommends 'Net::Server', '0.97'; +recommends 'Net::Z3950::SimpleServer', '1.15'; +recommends 'PDF::FromHTML', '0.31'; +recommends 'PPI', '1.215'; +recommends 'Parallel::ForkManager', '0.75'; +recommends 'Readonly', '0.01'; +recommends 'Readonly::XS', '0.01'; +recommends 'SMS::Send', '0.05'; +recommends 'Selenium::Remote::Driver', '1.27'; +recommends 'Sys::CPU', '0.52'; +recommends 'Template::Plugin::Stash', '1.006'; +recommends 'Test::DBIx::Class', '0.42'; +recommends 'Test::Deep', '0.106'; +recommends 'Test::Exception', '0.35'; +recommends 'Test::MockObject', '1.09'; +recommends 'Test::MockTime', '0.13'; +recommends 'Test::Strict', '0.14'; +recommends 'Test::WWW::Mechanize', '1.42'; +recommends 'Test::Warn', '0.21'; +recommends 'Test::YAML::Valid', '0.04'; +recommends 'Text::CSV::Unicode', '0.40'; +recommends 'Text::Unidecode', '0.04'; +recommends 'Time::Fake', '0.11'; +recommends 'UNIVERSAL::require', '0.13'; +recommends 'WWW::YouTube::Download', '0.56'; +recommends 'WebService::ILS', '0.17'; +recommends 'XML::Writer', '0.614'; diff --git a/debian/list-deps b/debian/list-deps index fb6e8c3a25..c9868d2b2d 100755 --- a/debian/list-deps +++ b/debian/list-deps @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# Write dependency list from Koha PerlDependencies.pm, in Debian format. +# Write dependency list from Koha cpanfile, in Debian format. # # Copyright 2010 Catalyst IT, Ltd # @@ -19,7 +19,7 @@ use Modern::Perl; -use C4::Installer::PerlDependencies; +use C4::Installer::PerlModules; # These are packages that may not be in the apt archive in a way that # apt-file can find, e.g. in the Koha repo rather than the regular @@ -39,61 +39,65 @@ my %ignore = ( 'CHI::Driver::Memcached' => 1, ); -my $deps = $C4::Installer::PerlDependencies::PERL_DEPS; - my $prefix = "^/usr/((lib|share)/perl5|(lib|share)/perl/[0-9.]+|(lib|share)/.*-linux-gnu.*/perl/[0-9.]+|(lib|share)/.*-linux-gnu.*/perl5/[0-9.]+)"; -foreach my $module ( keys %$deps ) { - next if $ignore{$module}; - my $ver = $deps->{$module}->{'min_ver'}; - my $subpath = $module; - $subpath =~ s,::,/,g; - my $output = qx(apt-file -l -x search "$prefix/$subpath.pm\$"); - my @temp = split( /\n/, $output ); - my @lines = (); +my $modules = C4::Installer::PerlModules->new(); +my $prereqs = $modules->prereqs; +foreach my $phase ($prereqs->phases) { + foreach my $type ($prereqs->types_in($phase)) { + my $reqs = $prereqs->requirements_for($phase, $type); + foreach my $module ( $reqs->required_modules ) { + next if $ignore{$module}; + my $subpath = $module; + $subpath =~ s,::,/,g; + my $output = qx(apt-file -l -x search "$prefix/$subpath.pm\$"); + my @temp = split( /\n/, $output ); + my @lines = (); - # Remove packages that are required/essential and always installed on - # a Debian system. Debian packages should not have unversioned - # dependencies on such packages. - foreach my $line (@temp) { - if ( $line ne "perl-base" ) { - @lines = ( @lines, $line ); - } - } - if ( exists $overrides{$module} ) { - print "$overrides{$module}\n"; - } - elsif ( scalar(@lines) == 1 && $lines[0] ne "" ) { - my $pkg = $lines[0]; - print "$pkg\n"; - } - elsif ( scalar(@lines) > 1 ) { - foreach my $pkg (@lines) { - print " | " if ( $pkg ne $lines[0] ); - print "$pkg"; - print " | $pkg" . "-5.22" if ( $pkg eq "perl-modules" ); - print " | $pkg" . "-5.24" if ( $pkg eq "perl-modules" ); - } - print "\n"; - } - elsif ( scalar(@temp) != 0 ) { + # Remove packages that are required/essential and always installed on + # a Debian system. Debian packages should not have unversioned + # dependencies on such packages. + foreach my $line (@temp) { + if ( $line ne "perl-base" ) { + @lines = ( @lines, $line ); + } + } + if ( exists $overrides{$module} ) { + print "$overrides{$module}\n"; + } + elsif ( scalar(@lines) == 1 && $lines[0] ne "" ) { + my $pkg = $lines[0]; + print "$pkg\n"; + } + elsif ( scalar(@lines) > 1 ) { + foreach my $pkg (@lines) { + print " | " if ( $pkg ne $lines[0] ); + print "$pkg"; + print " | $pkg" . "-5.22" if ( $pkg eq "perl-modules" ); + print " | $pkg" . "-5.24" if ( $pkg eq "perl-modules" ); + } + print "\n"; + } + elsif ( scalar(@temp) != 0 ) { - # I'm an Essential and I'm OK, - # I install all night, and work all day. - # I chomp up strings. I eat my bugs. - # I go to the base install. - # On Fridays I go drinking, - # and have buttered commits for git. - # (Beer O'Clock is more than two hours - # away. I don't even drink beer. There - # is no reason to be suspicious of this - # commit.) - # RM note: suspicious? me? always! - } - elsif ( ! $deps->{$module}->{'required'} ) { - # Ignore because we don't have it and we don't care. - } - else { - print "EEEK: unknown package for $module\n"; + # I'm an Essential and I'm OK, + # I install all night, and work all day. + # I chomp up strings. I eat my bugs. + # I go to the base install. + # On Fridays I go drinking, + # and have buttered commits for git. + # (Beer O'Clock is more than two hours + # away. I don't even drink beer. There + # is no reason to be suspicious of this + # commit.) + # RM note: suspicious? me? always! + } + elsif ( $type ne 'requires' ) { + # Ignore because we don't have it and we don't care. + } + else { + print "EEEK: unknown package for $module\n"; + } + } } } diff --git a/installer/install.pl b/installer/install.pl index bf9ccc4229..0b2a683a2d 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -29,6 +29,7 @@ use C4::Output; use C4::Templates; use C4::Languages qw(getAllLanguages getTranslatedLanguages); use C4::Installer; +use C4::Installer::PerlModules; use Koha; diff --git a/t/Installer_PerlDependencies.t b/t/Installer_PerlDependencies.t deleted file mode 100755 index 45dc1f1659..0000000000 --- a/t/Installer_PerlDependencies.t +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/perl -# -# This Koha test module is a stub! -# Add more tests here!!! - -use strict; -use warnings; - -use Test::More tests => 1; - -BEGIN { - use_ok('C4::Installer::PerlDependencies'); -} - diff --git a/t/Installer_PerlModules.t b/t/Installer_PerlModules.t index dad968fed6..ea1002b9bb 100755 --- a/t/Installer_PerlModules.t +++ b/t/Installer_PerlModules.t @@ -5,58 +5,18 @@ use Modern::Perl; -use Test::More tests => 22; +use Test::More tests => 6; BEGIN { use_ok('C4::Installer::PerlModules'); } -$C4::Installer::PerlModules::PERL_DEPS->{'Local::Module::Upgraded'} = { - 'required' => '1', - 'min_ver' => '0.9.3', - 'usage' => "Testing: make sure numbers are compared numerically and not lexicographically", -}; -$Local::Module::Upgraded::VERSION = '0.9.13'; -$INC{"Local/Module/Upgraded.pm"} = 1; -use_ok("Local::Module::Upgraded"); - -$C4::Installer::PerlModules::PERL_DEPS->{'Local::Module::NotUpgraded'} = { - 'required' => '1', - 'min_ver' => '0.9.3', - 'usage' => "Testing: make sure numbers are compared numerically and not lexicographically", -}; -$Local::Module::NotUpgraded::VERSION = '0.9.1'; -$INC{"Local/Module/NotUpgraded.pm"} = 1; -use_ok("Local::Module::NotUpgraded"); - my $modules; ok ($modules = C4::Installer::PerlModules->new(), 'Tests modules object'); my $prereq_pm = $modules->prereq_pm(); ok (exists($prereq_pm->{"DBI"}), 'DBI required for installer to run'); ok (exists($prereq_pm->{"CGI"}), 'CGI required for installer to run' ); ok (exists($prereq_pm->{"YAML"}), 'YAML required for installer to run'); -is ($modules->required('module'=>"DBI"),1, 'DBI should return 1 since required'); -is ($modules->required('module'=>"thisdoesn'texist"),-1, 'string should return -1 since not in hash'); -my $required = $modules->required('required'=>1); -my %params = map { $_ => 1 } @$required; -ok (exists($params{"DBI"}), 'DBI required for installer to run'); -my $optional = $modules->required('optional'=>1); -%params = map { $_ => 1 } @$optional; -ok (exists($params{"Test::Strict"}), 'test::strict optional for installer to run'); -is ($optional = $modules->required('spaghetti'=>1),-1, '-1 returned when parsing in unknown parameter'); -my $version_info = $modules->version_info('DBI'); -ok (exists($version_info->{"required"}), 'required exists'); -ok (exists($version_info->{"upgrade"}), 'upgrade exists'); -is ($modules->version_info("thisdoesn'texist"),-1, 'thisdoesntexist should return -1'); -ok ($modules->module_count() >10 , 'count should be greater than 10'); -my @module_list = $modules->module_list; -%params = map { $_ => 1 } @module_list; -ok (exists($params{"DBI"}), 'DBI exists in array'); -is ($modules->required('module'=>"String::Random"),1, 'String::Random should return 1 since required'); -is ($modules->version_info(), -1, "Testing empty modules"); - -is($modules->version_info("Local::Module::Upgraded")->{"upgrade"},0,"Version 0.9.13 is greater than 0.9.3, so no upgrade needed"); -is($modules->version_info("Local::Module::NotUpgraded")->{"upgrade"},1,"Version 0.9.1 is smaller than 0.9.1, so no upgrade needed"); subtest 'versions_info' => sub { plan tests => 4; diff --git a/t/Installer_pm.t b/t/Installer_pm.t index 73781724fb..0ed28ee0e5 100755 --- a/t/Installer_pm.t +++ b/t/Installer_pm.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 2; use Data::Dumper; BEGIN { @@ -13,13 +13,3 @@ BEGIN { my $obj = C4::Installer::PerlModules->new; isa_ok($obj,'C4::Installer::PerlModules'); - -my $module_info = $obj->version_info('Test::More'); - -my $control = $Test::More::VERSION; - -like($module_info->{cur_ver}, qr/\d/, 'returns numeric version'); - -is($module_info->{cur_ver}, $control, 'returns correct version'); - - -- 2.39.5