summaryrefslogtreecommitdiffstats
path: root/lib/App/ArchLinux/PackagerTools.pm
blob: d8cb89d7759816ccea57af414da2e124a5450988 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package App::ArchLinux::PackagerTools;
use v5.24;
use strictures;

our $VERSION = "0.01";

use autodie;
use Function::Parameters;
use Log::Any qw($log);

use App::ArchLinux::PackagerTools::Pacman;
use App::ArchLinux::PackagerTools::CPAN;

=encoding utf-8

=head1 NAME

App::ArchLinux::PackagerTools - It's new $module

=head1 SYNOPSIS

    use App::ArchLinux::PackagerTools;

=head1 DESCRIPTION

App::ArchLinux::PackagerTools is ...

=head1 METHODS

=head2 Constructors

=head3 new

 App::ArchLinux::PackagerTools->new();

Returns a new instance.

=cut
method new($class: $deps = {}) {
	$deps->{cpan} //= App::ArchLinux::PackagerTools::CPAN->new();
	$deps->{pacman} //= App::ArchLinux::PackagerTools::Pacman->new({$deps->%{cpan}});
	return $class->new_no_defaults($deps);
}

method new_no_defaults($class: $deps = {}) {
	my $self = {};
	bless $self, $class;
	$self->{deps} = $deps;
	return $self;
}

method get_distributions_in_repo() {
	return $self->{deps}->{pacman}->get_perl_distributions();
}

method get_updateable_packages($distribution_names) {
	my @packages;
	for my $dist_name ($distribution_names->@*) {
		my $repo_version = $self->{deps}->{pacman}->get_perl_distribution_version($dist_name);
		my $dist = $self->{deps}->{cpan}->get_dist($dist_name);
		if ($self->{deps}->{cpan}->is_newer_version_available($dist_name, $repo_version)) {
			$log->infof('New version available for dist \'%s\': %s', $dist_name, $dist->{version});
			push @packages, {
				dist_name => $dist_name,
				repo_version => $repo_version,
				cpan_version => $dist->{version},
				pkgname => $self->{deps}->{pacman}->get_perl_pkgname($dist_name),
			};
		} else {
			$log->debugf('Dist \'%s\' is already up to date with version %s', $dist_name, $dist->{version});
		}

	}
	return \@packages;
}

=head1 LICENSE

Copyright (C) 2018  Florian Pritz E<lt>bluewind@xinu.atE<gt>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.


=head1 AUTHOR

Florian Pritz E<lt>bluewind@xinu.atE<gt>

=cut

1;

__END__