File: | C4/Installer/PerlModules.pm |
Coverage: | 42.3% |
line | stmt | bran | cond | sub | time | code |
---|---|---|---|---|---|---|
1 | package C4::Installer::PerlModules; | |||||
2 | ||||||
3 | 6 6 6 | 88634 51 465 | use warnings; | |||
4 | 6 6 6 | 52 32 173 | use strict; | |||
5 | ||||||
6 | 6 6 6 | 46 29 209 | use File::Spec; | |||
7 | ||||||
8 | 6 6 6 | 1273 13 247 | use C4::Installer::PerlDependencies; | |||
9 | ||||||
10 | 6 6 6 | 738 10121 917 | use version; our $VERSION = qv('1.0.0_1'); | |||
11 | ||||||
12 | our $PERL_DEPS = $C4::Installer::PerlDependencies::PERL_DEPS; | |||||
13 | ||||||
14 | sub new { | |||||
15 | 2 | 383773 | my $invocant = shift; | |||
16 | 2 | 29 | my $self = { | |||
17 | missing_pm => [], | |||||
18 | upgrade_pm => [], | |||||
19 | current_pm => [], | |||||
20 | }; | |||||
21 | 2 | 52 | my $type = ref($invocant) || $invocant; | |||
22 | 2 | 33 | bless ($self, $type); | |||
23 | 2 | 47 | return $self; | |||
24 | } | |||||
25 | ||||||
26 | sub prereq_pm { | |||||
27 | 0 | 0 | my $self = shift; | |||
28 | 0 | 0 | my $prereq_pm = {}; | |||
29 | 0 | 0 | for (keys %$PERL_DEPS) { | |||
30 | 0 | 0 | $prereq_pm->{$_} = $PERL_DEPS->{$_}->{'min_ver'}; | |||
31 | } | |||||
32 | 0 | 0 | return $prereq_pm; | |||
33 | } | |||||
34 | ||||||
35 | sub required { | |||||
36 | 0 | 0 | my $self = shift; | |||
37 | 0 | 0 | my %params = @_; | |||
38 | 0 | 0 | if ($params{'module'}) { | |||
39 | 0 0 | 0 0 | return -1 unless grep {m/$params{'module'}/} keys(%$PERL_DEPS); | |||
40 | 0 | 0 | return $PERL_DEPS->{$params{'module'}}->{'required'}; | |||
41 | } | |||||
42 | elsif ($params{'required'}) { | |||||
43 | 0 | 0 | my $required_pm = []; | |||
44 | 0 | 0 | for (keys %$PERL_DEPS) { | |||
45 | 0 | 0 | push (@$required_pm, $_) if $PERL_DEPS->{$_}->{'required'} == 1; | |||
46 | } | |||||
47 | 0 | 0 | return $required_pm; | |||
48 | } | |||||
49 | elsif ($params{'optional'}) { | |||||
50 | 0 | 0 | my $optional_pm = []; | |||
51 | 0 | 0 | for (keys %$PERL_DEPS) { | |||
52 | 0 | 0 | push (@$optional_pm, $_) if $PERL_DEPS->{$_}->{'required'} == 0; | |||
53 | } | |||||
54 | 0 | 0 | return $optional_pm; | |||
55 | } | |||||
56 | else { | |||||
57 | 0 | 0 | return -1; # unrecognized parameter passed in | |||
58 | } | |||||
59 | } | |||||
60 | ||||||
61 | sub version_info { | |||||
62 | 6 6 6 | 2363 51 3524 | no warnings; # perl throws warns for invalid $VERSION numbers which some modules use | |||
63 | 2 | 1485 | my $self = shift; | |||
64 | # Reset these arrayref each pass through to ensure current information | |||||
65 | 2 | 18 | $self->{'missing_pm'} = []; | |||
66 | 2 | 17 | $self->{'upgrade_pm'} = []; | |||
67 | 2 | 14 | $self->{'current_pm'} = []; | |||
68 | 2 | 18 | my %params = @_; | |||
69 | 2 | 18 | if ($params{'module'}) { | |||
70 | 2 192 | 51 885 | return -1 unless grep {m/$params{'module'}/} keys(%$PERL_DEPS); | |||
71 | 2 | 185 | eval "require $params{'module'}"; | |||
72 | 2 | 242 | if ($@) { | |||
73 | 0 | 0 | return {$params{'module'} => {cur_ver => 0, min_ver => $PERL_DEPS->{$_}->{'min_ver'}, upgrade => 0, required => $PERL_DEPS->{$_}->{'required'}, usage => $PERL_DEPS->{$_}->{'usage'}}}; | |||
74 | } | |||||
75 | elsif ($params{'module'}->VERSION lt $PERL_DEPS->{$params{'module'}}->{'min_ver'}) { | |||||
76 | 0 | 0 | return {$params{'module'} => {cur_ver => $params{'module'}->VERSION, min_ver => $PERL_DEPS->{$params{'module'}}->{'min_ver'}, upgrade => 1, required => $PERL_DEPS->{$params{'module'}}->{'required'}, usage => $PERL_DEPS->{$_}->{'usage'}}}; | |||
77 | } | |||||
78 | else { | |||||
79 | 2 | 59 | return {$params{'module'} => {cur_ver => $params{'module'}->VERSION, min_ver => $PERL_DEPS->{$params{'module'}}->{'min_ver'}, upgrade => 0, required => $PERL_DEPS->{$params{'module'}}->{'required'}, usage => $PERL_DEPS->{$_}->{'usage'}}}; | |||
80 | } | |||||
81 | } | |||||
82 | else { | |||||
83 | 0 0 | for (sort keys(%{$PERL_DEPS})) { | ||||
84 | 0 | my $pkg = $_; # $_ holds the string | ||||
85 | 0 | eval "require $pkg"; | ||||
86 | 0 | if ($@) { | ||||
87 | 0 0 | push (@{$self->{'missing_pm'}}, {$_ => {cur_ver => 0, min_ver => $PERL_DEPS->{$_}->{'min_ver'}, required => $PERL_DEPS->{$_}->{'required'}, usage => $PERL_DEPS->{$_}->{'usage'}}}); | ||||
88 | } | |||||
89 | elsif ($pkg->VERSION lt $PERL_DEPS->{$_}->{'min_ver'}) { | |||||
90 | 0 0 | push (@{$self->{'upgrade_pm'}}, {$_ => {cur_ver => $pkg->VERSION, min_ver => $PERL_DEPS->{$_}->{'min_ver'}, required => $PERL_DEPS->{$_}->{'required'}, usage => $PERL_DEPS->{$_}->{'usage'}}}); | ||||
91 | } | |||||
92 | else { | |||||
93 | 0 0 | push (@{$self->{'current_pm'}}, {$_ => {cur_ver => $pkg->VERSION, min_ver => $PERL_DEPS->{$_}->{'min_ver'}, required => $PERL_DEPS->{$_}->{'required'}, usage => $PERL_DEPS->{$_}->{'usage'}}}); | ||||
94 | } | |||||
95 | } | |||||
96 | 0 | return; | ||||
97 | } | |||||
98 | } | |||||
99 | ||||||
100 | sub get_attr { | |||||
101 | 0 | return $_[0]->{$_[1]}; | ||||
102 | } | |||||
103 | ||||||
104 | sub module_count { | |||||
105 | 0 | return scalar(keys(%$PERL_DEPS)); | ||||
106 | } | |||||
107 | ||||||
108 | sub module_list { | |||||
109 | 0 | return keys(%$PERL_DEPS); | ||||
110 | } | |||||
111 | ||||||
112 | 1; |