line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OPM::Installer::Utils::TS; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: class that provides helper functionality regarding the addon installation |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
84753
|
use strict; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
74
|
|
6
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
96
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0.0'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
27
|
use Carp; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
143
|
|
11
|
3
|
|
|
3
|
|
479
|
use Moo; |
|
3
|
|
|
|
|
9216
|
|
|
3
|
|
|
|
|
16
|
|
12
|
3
|
|
|
3
|
|
2251
|
use Types::Standard qw(ArrayRef Str); |
|
3
|
|
|
|
|
61497
|
|
|
3
|
|
|
|
|
23
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
3363
|
use OPM::Installer::Utils::File; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
2815
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has path => ( is => 'ro' ); |
17
|
|
|
|
|
|
|
has os_env => ( is => 'ro', lazy => 1, default => \&_os_env ); |
18
|
|
|
|
|
|
|
has framework_version => ( is => 'rwp', lazy => 1, default => \&_find_version); |
19
|
|
|
|
|
|
|
has inc => ( is => 'rwp', lazy => 1, default => \&_build_inc ); |
20
|
|
|
|
|
|
|
has manager => ( is => 'rwp', lazy => 1, default => \&_build_manager ); |
21
|
|
|
|
|
|
|
has db => ( is => 'rwp', lazy => 1, default => \&_get_db ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub is_installed { |
24
|
4
|
|
|
4
|
1
|
303
|
my ($self, %param) = @_; |
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
|
|
7
|
my $sql = 'SELECT name, version FROM package_repository WHERE name = ?'; |
27
|
|
|
|
|
|
|
|
28
|
4
|
50
|
|
|
|
73
|
return if !$self->db; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$self->db->Prepare( |
31
|
|
|
|
|
|
|
SQL => $sql, |
32
|
4
|
|
|
|
|
73
|
Bind => [ \$param{package} ], |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
63
|
my %info; |
36
|
4
|
|
|
|
|
50
|
while ( my @row = $self->db->FetchrowArray() ) { |
37
|
3
|
|
|
|
|
92
|
%info = ( |
38
|
|
|
|
|
|
|
name => $row[0], |
39
|
|
|
|
|
|
|
version => $row[1], |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
4
|
100
|
|
|
|
57
|
return if !%info; |
44
|
|
|
|
|
|
|
|
45
|
3
|
50
|
|
|
|
6
|
return $info{version} if !$param{version}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $is_installed = $self->_check_version( |
48
|
|
|
|
|
|
|
installed => $info{version}, |
49
|
|
|
|
|
|
|
requested => $param{version}, |
50
|
3
|
|
|
|
|
8
|
); |
51
|
|
|
|
|
|
|
|
52
|
3
|
100
|
|
|
|
12
|
return $is_installed if $is_installed; |
53
|
1
|
|
|
|
|
3
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _check_version { |
57
|
3
|
|
|
3
|
|
7
|
my ($self, %param) = @_; |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
50
|
|
|
10
|
my @i_parts = split /\./, $param{installed} || 0; |
60
|
3
|
|
50
|
|
|
8
|
my @r_parts = split /\./, $param{requested} || 10000000; |
61
|
|
|
|
|
|
|
|
62
|
3
|
100
|
66
|
|
|
6
|
my $installed = sprintf "%03d%03d%03d", map{ $i_parts[$_] && $i_parts[$_] =~ m{\A[0-9]+\z} ? $i_parts[$_] : 0 }( 0 .. 2); |
|
9
|
|
|
|
|
48
|
|
63
|
3
|
100
|
66
|
|
|
7
|
my $requested = sprintf "%03d%03d%03d", map{ $r_parts[$_] && $r_parts[$_] =~ m{\A[0-9]+\z} ? $r_parts[$_] : 0 }( 0 .. 2); |
|
9
|
|
|
|
|
35
|
|
64
|
|
|
|
|
|
|
|
65
|
3
|
100
|
|
|
|
11
|
return $installed if $installed >= $requested; |
66
|
1
|
|
|
|
|
3
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _get_db { |
70
|
1
|
|
|
1
|
|
9
|
my ($self) = @_; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
2
|
push @INC, @{ $self->inc }; |
|
1
|
|
|
|
|
14
|
|
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
7
|
my $object; |
75
|
1
|
50
|
|
|
|
1
|
eval { |
76
|
1
|
|
|
|
|
5
|
require Kernel::System::ObjectManager; |
77
|
1
|
|
|
|
|
3
|
$Kernel::OM = Kernel::System::ObjectManager->new; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
9
|
$object = $Kernel::OM->Get('Kernel::System::DB'); |
80
|
|
|
|
|
|
|
} or die $@; |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
17
|
$object; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _build_manager { |
86
|
1
|
|
|
1
|
|
9
|
my ($self) = @_; |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
3
|
push @INC, @{ $self->inc }; |
|
1
|
|
|
|
|
14
|
|
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
7
|
my $manager; |
91
|
1
|
50
|
|
|
|
1
|
eval { |
92
|
1
|
|
|
|
|
765
|
require Kernel::System::ObjectManager; |
93
|
1
|
|
|
|
|
14
|
$Kernel::OM = Kernel::System::ObjectManager->new; |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
6
|
$manager = $Kernel::OM->Get('Kernel::System::Package'); |
96
|
|
|
|
|
|
|
} or die $@; |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
22
|
$manager; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _find_version { |
102
|
1
|
|
|
1
|
|
10
|
my ($self) = @_; |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
4
|
my $file = $self->path . '/RELEASE'; |
105
|
1
|
|
|
|
|
17
|
my $content = do { local ( @ARGV, $/ ) = $file; <> }; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
79
|
|
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
8
|
my ($version) = $content =~ m{VERSION \s+ = \s+ ([0-9.]+)}xms; |
108
|
1
|
|
|
|
|
7
|
return $version; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _build_inc { |
112
|
1
|
|
|
1
|
|
21
|
my ($self) = @_; |
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
|
|
3
|
return [ map{ $self->path . "/" . $_ }( '', 'Kernel/cpan-lib' ) ]; |
|
2
|
|
|
|
|
23
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub BUILDARGS { |
118
|
2
|
|
|
2
|
1
|
2026
|
my $class = shift; |
119
|
|
|
|
|
|
|
|
120
|
2
|
50
|
|
|
|
8
|
if ( @_ % 2 != 0 ) { |
121
|
0
|
|
|
|
|
0
|
croak 'Check the parameters for ' . __PACKAGE__ . '. You have to pass a hash.'; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
2
|
|
|
|
|
5
|
my %args = @_; |
125
|
2
|
100
|
|
|
|
5
|
if ( !exists $args{path} ) { |
126
|
1
|
|
|
|
|
6
|
my $utils = OPM::Installer::Utils::Config->new; |
127
|
1
|
|
|
|
|
898
|
my $cfg = $utils->rc_config; |
128
|
|
|
|
|
|
|
|
129
|
1
|
50
|
|
|
|
10
|
$args{path} = $cfg->{path} if defined $cfg->{path}; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
2
|
|
|
|
|
33
|
return \%args; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub _os_env { |
136
|
2
|
100
|
|
2
|
|
742
|
if ( $ENV{OPMINSTALLERTEST} ) { |
137
|
1
|
|
|
|
|
5
|
return 'OPM::Installer::Utils::Test'; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
else { |
140
|
1
|
|
|
|
|
6
|
return 'OPM::Installer::Utils::Linux'; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
__END__ |