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