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
|
|
84523
|
use strict; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
80
|
|
6
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
100
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
28
|
use Carp; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
191
|
|
11
|
3
|
|
|
3
|
|
478
|
use Moo; |
|
3
|
|
|
|
|
9305
|
|
|
3
|
|
|
|
|
17
|
|
12
|
3
|
|
|
3
|
|
2293
|
use Types::Standard qw(ArrayRef Str); |
|
3
|
|
|
|
|
62013
|
|
|
3
|
|
|
|
|
24
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
3553
|
use OPM::Installer::Utils::File; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
2912
|
|
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
|
305
|
my ($self, %param) = @_; |
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
|
|
9
|
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
|
|
|
|
|
75
|
Bind => [ \$param{package} ], |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
64
|
my %info; |
36
|
4
|
|
|
|
|
51
|
while ( my @row = $self->db->FetchrowArray() ) { |
37
|
3
|
|
|
|
|
92
|
%info = ( |
38
|
|
|
|
|
|
|
name => $row[0], |
39
|
|
|
|
|
|
|
version => $row[1], |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
4
|
100
|
|
|
|
54
|
return if !%info; |
44
|
|
|
|
|
|
|
|
45
|
3
|
50
|
|
|
|
7
|
return $info{version} if !$param{version}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $is_installed = $self->_check_version( |
48
|
|
|
|
|
|
|
installed => $info{version}, |
49
|
|
|
|
|
|
|
requested => $param{version}, |
50
|
3
|
|
|
|
|
9
|
); |
51
|
|
|
|
|
|
|
|
52
|
3
|
100
|
|
|
|
12
|
return $is_installed if $is_installed; |
53
|
1
|
|
|
|
|
4
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _check_version { |
57
|
3
|
|
|
3
|
|
8
|
my ($self, %param) = @_; |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
50
|
|
|
12
|
my @i_parts = split /\./, $param{installed} || 0; |
60
|
3
|
|
50
|
|
|
8
|
my @r_parts = split /\./, $param{requested} || 10000000; |
61
|
|
|
|
|
|
|
|
62
|
3
|
100
|
66
|
|
|
7
|
my $installed = sprintf "%03d%03d%03d", map{ $i_parts[$_] && $i_parts[$_] =~ m{\A[0-9]+\z} ? $i_parts[$_] : 0 }( 0 .. 2); |
|
9
|
|
|
|
|
50
|
|
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
|
|
|
|
|
37
|
|
64
|
|
|
|
|
|
|
|
65
|
3
|
100
|
|
|
|
12
|
return $installed if $installed >= $requested; |
66
|
1
|
|
|
|
|
3
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _get_db { |
70
|
1
|
|
|
1
|
|
12
|
my ($self) = @_; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
2
|
push @INC, @{ $self->inc }; |
|
1
|
|
|
|
|
14
|
|
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
7
|
my $object; |
75
|
1
|
50
|
|
|
|
2
|
eval { |
76
|
1
|
|
|
|
|
5
|
require Kernel::System::ObjectManager; |
77
|
1
|
|
|
|
|
3
|
$Kernel::OM = Kernel::System::ObjectManager->new; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
10
|
$object = $Kernel::OM->Get('Kernel::System::DB'); |
80
|
|
|
|
|
|
|
} or die $@; |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
17
|
$object; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _build_manager { |
86
|
1
|
|
|
1
|
|
12
|
my ($self) = @_; |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
2
|
push @INC, @{ $self->inc }; |
|
1
|
|
|
|
|
14
|
|
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
13
|
my $manager; |
91
|
1
|
50
|
|
|
|
2
|
eval { |
92
|
1
|
|
|
|
|
756
|
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
|
|
|
|
|
23
|
$manager; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _find_version { |
102
|
1
|
|
|
1
|
|
11
|
my ($self) = @_; |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
5
|
my $file = $self->path . '/RELEASE'; |
105
|
1
|
|
|
|
|
20
|
my $content = do { local ( @ARGV, $/ ) = $file; <> }; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
88
|
|
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
9
|
my ($version) = $content =~ m{VERSION \s+ = \s+ ([0-9.]+)}xms; |
108
|
1
|
|
|
|
|
7
|
return $version; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _build_inc { |
112
|
1
|
|
|
1
|
|
23
|
my ($self) = @_; |
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
|
|
2
|
return [ map{ $self->path . "/" . $_ }( '', 'Kernel/cpan-lib' ) ]; |
|
2
|
|
|
|
|
25
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub BUILDARGS { |
118
|
2
|
|
|
2
|
1
|
2207
|
my $class = shift; |
119
|
|
|
|
|
|
|
|
120
|
2
|
50
|
|
|
|
9
|
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
|
|
|
|
6
|
if ( !exists $args{path} ) { |
126
|
1
|
|
|
|
|
7
|
my $utils = OPM::Installer::Utils::Config->new; |
127
|
1
|
|
|
|
|
906
|
my $cfg = $utils->rc_config; |
128
|
|
|
|
|
|
|
|
129
|
1
|
50
|
|
|
|
12
|
$args{path} = $cfg->{path} if defined $cfg->{path}; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
2
|
|
|
|
|
35
|
return \%args; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub _os_env { |
136
|
2
|
100
|
|
2
|
|
1362
|
if ( $ENV{OPMINSTALLERTEST} ) { |
137
|
1
|
|
|
|
|
6
|
return 'OPM::Installer::Utils::Test'; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
else { |
140
|
1
|
|
|
|
|
6
|
return 'OPM::Installer::Utils::Linux'; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
__END__ |