1 package C4::Installer::PerlModules;
6 use File::Basename qw( dirname );
17 my $type = ref($invocant) || $invocant;
25 unless (defined $self->{prereqs}) {
26 my $filename = $INC{'C4/Installer/PerlModules.pm'};
27 my $path = dirname(dirname(dirname($filename)));
28 $self->{prereqs} = Module::CPANfile->load("$path/cpanfile")->prereqs;
31 return $self->{prereqs};
38 my $reqs = $self->prereqs->merged_requirements;
39 foreach my $module ($reqs->required_modules) {
40 $prereq_pm->{$module} = $reqs->requirements_for_module($module);
49 # Reset these arrayref each pass through to ensure current information
50 $self->{'missing_pm'} = [];
51 $self->{'upgrade_pm'} = [];
52 $self->{'current_pm'} = [];
54 foreach my $phase ($self->prereqs->phases) {
55 foreach my $type ($self->prereqs->types_in($phase)) {
56 my $reqs = $self->prereqs->requirements_for($phase, $type);
57 foreach my $module (sort $reqs->required_modules) {
60 required => $type eq 'requires',
63 my $vers = $reqs->structured_requirements_for_module($module);
64 for my $req (@$vers) {
65 if ( $req->[0] eq '>=' || $req->[0] eq '>' ) {
66 $module_infos->{min_ver} = $req->[1];
67 } elsif ( $req->[0] eq '<=' || $req->[0] eq '<' ) {
68 $module_infos->{max_ver} = $req->[1];
70 push @{$module_infos->{exc_ver}}, $req->[1];
76 # ignore warnings from noisy modules
77 local $SIG{__WARN__} = sub {};
78 eval "require $module";
83 my $pkg_version = $module->can("VERSION") ? $module->VERSION : 0;
84 $module_infos->{cur_ver} = $pkg_version;
85 if ($reqs->accepts_module($module => $pkg_version)) {
92 push @{ $self->{$attr} }, { $module => $module_infos };
99 return $_[0]->{$_[1]};
107 C4::Installer::PerlModules
111 A module for manipulating Koha Perl dependency list objects.
117 Creates a new PerlModules object
120 C<my $perl_modules = C4::Installer::PerlModules->new;>
124 Returns a hashref of a hash of module information suitable for use in Makefile.PL
127 C<my $perl_modules = C4::Installer::PerlModules->new;
131 PREREQ_PM => $perl_modules->prereq_pm,>
136 C<$perl_modules->versions_info;>
138 This loads info of required modules into three accessors: missing_pm,
139 upgrade_pm, and current_pm. Each of these may be accessed by using the
140 C<get_attr> method. Each accessor returns an anonymous array who's
141 elements are anonymous hashes. They follow this format (NOTE: Upgrade
142 status is indicated by the accessor name.):
146 'Text::CSV::Encoded' => {
153 'Biblio::EndnoteStyle' => {
161 =head2 get_attr(attr_name)
163 Returns an anonymous array containing the contents of the passed in accessor. Valid accessors are:
165 missing_pm - Perl modules used by Koha but not currently installed.
167 upgrade_pm - Perl modules currently installed but below the minimum version required by Koha.
169 current_pm - Perl modules currently installed and up to date as required by Koha.
172 C<my $missing_pm = $perl_modules->get_attr('missing_pm');>
177 Chris Nighswonger <cnighswonger AT foundations DOT edu>
181 Copyright 2010 Foundations Bible College.
185 This file is part of Koha.
187 Koha is free software; you can redistribute it and/or modify it
188 under the terms of the GNU General Public License as published by
189 the Free Software Foundation; either version 3 of the License, or
190 (at your option) any later version.
192 Koha is distributed in the hope that it will be useful, but
193 WITHOUT ANY WARRANTY; without even the implied warranty of
194 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
195 GNU General Public License for more details.
197 You should have received a copy of the GNU General Public License
198 along with Koha; if not, see <http://www.gnu.org/licenses>.
200 =head1 DISCLAIMER OF WARRANTY
202 Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
203 A PARTICULAR PURPOSE. See the GNU General Public License for more details.