apkbuild-cpan.in 17.8 KB
Newer Older
1 2 3 4 5
#!/usr/bin/perl
# apk add perl-libwww perl-json

use strict;
use warnings;
6 7 8 9
use 5.016;
use feature "switch";
no if $] >= 5.018, warnings => "experimental::smartmatch";

10 11 12 13 14 15 16
use LWP::UserAgent;
use LWP::ConnCache;
use CPAN::Meta;
use Module::CoreList;
use JSON;

my $license_mappings = {
17
	"perl_5" => "GPL-1.0-or-later OR Artistic-1.0-Perl",
18 19
	"artistic_2" => "Artistic-2.0",
	"gpl_3" => "GPL-3.0-only",
20
	"mit" => "MIT",
21 22 23 24
};

my $package_mappings = {
	"LWP" => "perl-libwww",
25
	"libwww-perl" => "perl-libwww",
26
	"TermReadKey" => "perl-term-readkey",
27
	"perl-ldap" => "perl-ldap",
28
	"PerlIO-gzip" => "perl-io-gzip",
29 30 31
};
our $packager = "";
my $template = <<'EOF';
32
# Automatically generated by apkbuild-cpan, template 3
33
[% authors %]
34
pkgname=[% pkgname %]
35
#_pkgreal is used by apkbuild-cpan to find modules at MetaCpan
36 37
_pkgreal=[% pkgreal %]
pkgver=[% pkgver %]
38
pkgrel=[% pkgrel %]
39
pkgdesc="Perl module for [% pkgreal %]"
40 41
provides="[% provides %]"
replaces="[% replaces %]"
Timothy Legge's avatar
Timothy Legge committed
42
url="https://metacpan.org/release/[% pkgreal %]/"
43
arch="noarch"
TBK's avatar
TBK committed
44
license="GPL-1.0-or-later OR Artistic-1.0-Perl"
45
depends="perl"
46 47
makedepends="perl-dev"
checkdepends=""
48 49
subpackages="$pkgname-doc"
source="[% source %]"
50
builddir="$srcdir/$_pkgreal-$pkgver"
51 52 53 54 55

build() {
	:
}

56
check() {
57 58 59
	:
}

60
package() {
61 62 63
	:
}

64 65 66 67 68 69 70
EOF

our $ua = LWP::UserAgent->new();
our $json = JSON->new;
$ua->env_proxy;
$ua->conn_cache(LWP::ConnCache->new());

71
sub read_file {
72 73 74 75 76 77 78 79
	my ($filename) = @_;
	local $/;
	open my $fh, "<", $filename or die "could not open $filename: $!";
	return <$fh>;
}

sub read_assignments_from_file {
	my ($filename) = @_;
80
	return () if ( ! -e $filename );
81 82 83 84
	my $text = read_file($filename);
	my %sline = $text =~ /^(\w+)\s*=\s*([^\"\n]*)$/mg;
	my %mline = $text =~ /^(\w+)\s*=\s*\"([^\"]*)\"$/mg;
	my %hash = ( %sline, %mline );
85 86 87 88

	my $authors = join("\n", $text =~ /^# Contributor: .*$/mg, $text =~ /^# Maintainer: .*$/mg);
	$hash{'authors'} = $authors if length($authors) > 1;

89 90 91 92 93 94
	my $provides = $text =~ m/^provides=\"(.*)\"".*$/mg;
	$hash{'provides'} = $1 if length($provides) >= 1;

	my $requires = $text =~ m/^requires=\"(.*)\"".*$/mg;
	$hash{'requires'} = $1 if length($requires) >= 1;

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	return \%hash;
}

sub map_cpan_to_apk {
	my ($cpan_distrib) = @_;
	return $package_mappings->{$cpan_distrib} if exists $package_mappings->{$cpan_distrib};
	# most packages are named according to the
	# distribution name
	return 'perl-' . lc $cpan_distrib;
}

sub read_apkbuild {
	return read_assignments_from_file("APKBUILD");
}

sub write_apkbuild {
111
	my ($distdata, $apkbuild, $moddata) = @_;
112

113
	my $cpanid = $distdata->{id};
114
	$cpanid = substr($cpanid, 0, 1) . "/" . substr($cpanid, 0, 2) . "/$cpanid";
115

116 117 118 119 120 121 122 123 124 125 126 127 128
	my $authors = undef;
	my $replaces = undef;
	my $provides = undef;
	my $pkgrel = 0;
	if (defined $apkbuild) {
		$authors = $apkbuild->{authors};
		$provides = $apkbuild->{provides};
		$replaces = $apkbuild->{replaces};
		$pkgrel = $apkbuild->{pkgrel};
		if ($apkbuild->{pkgver} eq $moddata->{version}) {
			$pkgrel++;
		}
	}
129
	my %repl = (
130
		authors  => ($authors or "# Contributor: $packager\n# Maintainer: $packager"),
131
		pkgname  => map_cpan_to_apk($moddata->{distribution}),
132
		pkgreal  => $moddata->{distribution},
133
		pkgver  => $moddata->{version} =~ s/^[^0-9]+//r,
134
		pkgrel	 => $pkgrel,
135
		source   => $moddata->{download_url},
136
		pkgdesc  => $distdata->{abstract},
137 138
		provides => ($provides or ''),
		replaces => ($replaces or ''),
139
	);
140
	$repl{source} =~ s/-$repl{pkgver}/-\$pkgver/g;
141 142 143 144 145 146 147 148 149 150 151 152 153 154
	$template =~ s/\[% (.*?) %\]/$repl{$1}/g;

	open my $fh, '>', "APKBUILD" or die;
	print $fh $template;
	close $fh;

	say "Wrote $repl{pkgname}/APKBUILD";
}

sub parse_deps {
	my ($reqs) = @_;
	my $distfiles = {};
	my $response;
	my $deps = "";
155
	my $reqmodlist = "";
156

157
	#Get list of unique required modules from all parameters
158 159
	foreach $reqs (@_) {
		for my $module ($reqs->required_modules) {
160
			$reqmodlist .= "$module " unless $reqmodlist =~ m/$module/;
161 162
		}
	}
163 164 165 166 167 168

	# Check add the require module to $dep if not part of core perl
	foreach my $module (split " ",  $reqmodlist) {
		next if $module eq 'perl';
		if (Module::CoreList->is_core($module)) {
			my $perlver = Module::CoreList->first_release($module);
169
			say "    $module is part of core perl since $perlver.";
170 171 172 173 174 175 176 177 178 179
			next;
		}
		# map module name to package name
		$response = $ua->get("https://fastapi.metacpan.org/module/$module");
		$response->is_success or die $response->status_line;
		my $moddata = $json->decode($response->decoded_content);
		$moddata->{error} and die "Error trying to locate $module: $moddata->{error}\n";
		$distfiles->{$module} = $moddata->{distribution};
	}

180
	# map package names to alpine packages
181
	foreach ( keys %{ $distfiles } ) {
182
		$response = $ua->get("https://fastapi.metacpan.org/module/$_");
183 184 185 186
		$response->is_success or die $response->status_line;
		my $distdata = $json->decode($response->decoded_content);
		$distdata->{error} and die "Error trying to locate $_: $distdata->{error}\n";

187
		my $pkgname = map_cpan_to_apk($distdata->{distribution});
188
		$deps .= "$pkgname " unless $deps =~ m/$pkgname/;
189
	}
190 191
	$deps =~ s/\h+/ /g;
	$deps =~ s/ $//;
192 193 194 195 196 197 198 199 200 201 202 203 204
	return $deps;

}

sub prepare_tree {
	system("abuild checksum unpack prepare") == 0 or
		die "abuild checksum failed";
}

sub update_functions {
	my $apkbuild = read_apkbuild;
	my $metaprefix = "src/" . $apkbuild->{'_pkgreal'} . "-" . $apkbuild->{'pkgver'} . "/";
	my $build_func;
205
	my $check_func;
206 207 208 209 210 211
	my $package_func;

	my $text = read_file "APKBUILD";
	if (-e "$metaprefix/Build.PL" ) {
		$build_func = <<'EOF';
build() {
212
	export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
213
	perl Build.PL --installdirs=vendor
214
	./Build
215 216 217 218
}
EOF
		$package_func = <<'EOF';
package() {
219
	./Build install --destdir="$pkgdir"
220 221
	find "$pkgdir" \( -name perllocal.pod -o -name .packlist \) -delete
}
222 223 224 225 226
EOF
		$check_func = <<'EOF';
check() {
	./Build test
}
227 228 229 230
EOF
	} else {
		$build_func = <<'EOF';
build() {
231
	export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
232
	PERL_MM_USE_DEFAULT=1 perl -I. Makefile.PL INSTALLDIRS=vendor
233
	make
234 235 236 237
}
EOF
		$package_func = <<'EOF';
package() {
tmpfile's avatar
tmpfile committed
238
	make DESTDIR="$pkgdir" install
239 240
	find "$pkgdir" \( -name perllocal.pod -o -name .packlist \) -delete
}
241 242 243 244 245 246
EOF
		$check_func = <<'EOF';
check() {
	export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
	make test
}
247 248 249 250 251 252 253
EOF
	}

	$text =~ s/^build\(\) \{.*?^\}\n/$build_func/smg or
		die "Can't replace build function APKBUILD";
	$text =~ s/^package\(\) \{.*?^\}\n/$package_func/smg or
		die "Can't replace package function APKBUILD";
254 255
	$text =~ s/^check\(\) \{.*?^\}\n/$check_func/smg or
		die "Can't replace check function APKBUILD";
256 257 258 259 260 261

	open my $fh, '>', "APKBUILD" or die;
	print $fh $text;
	close $fh;
}

262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
sub sort_pkgs_by_orig {
    my $sort_order = shift;
    my @array_to_sort = split / /, shift;;

    s/[\t\n\r\f]/ /g for $sort_order;  # remove embedded new lines from sort order
    s/\h+/ /g for $sort_order;          # remove embedded spaces from sort order

    my @sort_order = split / /, $sort_order;

    #get order of order by string
    my $count = 0;
    my %position_of;
    $position_of{$_} = $count++ for @sort_order;

    my %sorted;         # holds the position of array to sort

    foreach (@array_to_sort) {
        my $pos = $position_of{$_};
        if (!defined $pos) {
            # not found in sort order so add to the end
            $sorted{$_} = $count;
            $count++;
        } else {
            $sorted{$_} = $pos;
        }
    }

    my @tmp;    # hold array of sorted in position order

    foreach my $name (sort { $sorted{$a} <=> $sorted{$b} } keys %sorted) {
            push @tmp, $name;
    }

    return join(" ", @tmp);
}
297

298 299
sub do_depends {
        my $oldapkbuild = shift;
300
	my $apkbuild = read_apkbuild;
301

302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
	my $metaprefix = '';
	if ( exists $apkbuild->{'_realname'} ) {
		$metaprefix = "src/" . $apkbuild->{'_realname'} . "-" . $apkbuild->{'pkgver'} . "/";
	}
	elsif ( exists $apkbuild->{'_pkgreal'} ) {
		$metaprefix = "src/" . $apkbuild->{'_pkgreal'} . "-" . $apkbuild->{'pkgver'} . "/";
	}
	elsif ( exists $apkbuild->{'_pkgname'} ) {
		$metaprefix = "src/" . $apkbuild->{'_pkgname'} . "-" . $apkbuild->{'pkgver'} . "/";
	}
	elsif ( exists $apkbuild->{'_name'} ) {
		$metaprefix = "src/" . $apkbuild->{'_name'} . "-" . $apkbuild->{'pkgver'} . "/";
	}
	elsif ( exists $apkbuild->{'_realpkgname'} ) {
		$metaprefix = "src/" . $apkbuild->{'_realpkgname'} . "-" . $apkbuild->{'pkgver'} . "/";
	}
	elsif ( exists $apkbuild->{'_pkg_real'} ) {
		$metaprefix = "src/" . $apkbuild->{'_pkg_real'} . "-" . $apkbuild->{'pkgver'} . "/";
	}
	else {
		die "Unable to find meta file directory - check APKBUILD Perl Module Name";
	}

	$metaprefix =~ s/-\$pkgver//g;

327 328 329 330 331 332 333 334 335 336 337 338 339 340
	my $meta;

	foreach my $metafile ("MYMETA.json", "META.json", "MYMETA.yml", "META.yml") {
		if (-e "$metaprefix$metafile") {
			say "Using meta information from $metafile";
			$meta = CPAN::Meta->load_file("$metaprefix$metafile");
			last;
		}
	}
	die "No dependency meta file found" unless $meta;

	my $abstract = $meta->abstract;
	say "Abstract: $abstract";

341
	my $license = join " OR ", map {$license_mappings->{$_} or $_} $meta->license;
342 343 344
	say "License: $license";

	my $deps = parse_deps $meta->effective_prereqs->requirements_for('runtime', 'requires');
345

346 347 348 349
        if (defined $oldapkbuild->{'depends'}){
            if (defined $oldapkbuild->{'cpandepends'}) {
                $oldapkbuild->{'depends'} =~ s/\$cpandepends/$oldapkbuild->{'cpandepends'}/g;
            }
350 351 352 353
            my $libs = $oldapkbuild->{'depends'};
            $libs =~ s/perl\-\w+[-\w+]+//g;
            $libs =~ s/perl//g;
            $deps = $deps . " " .$libs;
354 355 356
            $deps = sort_pkgs_by_orig ($oldapkbuild->{'depends'}, $deps);
        }

357 358 359 360 361
	if ($deps eq '') {
		$deps = "perl";
	} else {
		$deps = "perl " . $deps;
	}
362 363 364

	say "CPAN runtime Required: $deps";
	say "CPAN runtime Recommended: " . parse_deps $meta->effective_prereqs->requirements_for('runtime', 'recommends');
365

366 367 368 369 370 371
	my $makedeps = parse_deps(
		$meta->effective_prereqs->requirements_for('configure', 'requires'),
		$meta->effective_prereqs->requirements_for('configure', 'recommends'),
		$meta->effective_prereqs->requirements_for('build', 'requires'),
		$meta->effective_prereqs->requirements_for('build', 'recommends')
	);
372 373 374 375 376

	if (-e "$metaprefix/Build.PL" ) {
		$makedeps = "$makedeps perl-module-build";
	}

377 378 379 380
        if (defined $oldapkbuild->{'makedepends'}){
            if (defined $oldapkbuild->{'cpanmakedepends'}) {
                $oldapkbuild->{'makedepends'} =~ s/\$cpanmakedepends/$oldapkbuild->{'cpanmakedepends'}/g;
            }
381 382 383
            my $libs = $oldapkbuild->{'makedepends'};
            $libs =~ s/perl\-\w+[-\w+]+//g;
            $makedeps = $makedeps . " " .$libs;
384 385 386
            $makedeps = sort_pkgs_by_orig ($oldapkbuild->{'makedepends'}, $makedeps);
        }

387 388 389 390 391
	if ($makedeps eq '') {
		$makedeps = "perl-dev";
	} else {
		$makedeps = "perl-dev " . $makedeps;
	}
392

393
	say "CPAN build deps: $makedeps";
394 395
	say "    CPAN build requires: " . parse_deps($meta->effective_prereqs->requirements_for('configure', 'requires'), $meta->effective_prereqs->requirements_for('build', 'requires'));
	say "    CPAN build recommends: " . parse_deps($meta->effective_prereqs->requirements_for('configure', 'recommends'), $meta->effective_prereqs->requirements_for('build', 'recommends'));
396 397

	my $checkdeps = parse_deps($meta->effective_prereqs->requirements_for('test', 'requires'), $meta->effective_prereqs->requirements_for('test', 'recommends'));
398 399 400 401 402

        if (defined $oldapkbuild->{'checkdepends'}){
            if (defined $oldapkbuild->{'cpancheckdepends'}) {
                $oldapkbuild->{'checkdepends'} =~ s/\$cpancheckdepends/$oldapkbuild->{'cpancheckdepends'}/g;
            }
403 404 405
            my $libs = $oldapkbuild->{'checkdepends'};
            $libs =~ s/perl\-\w+[-\w+]+//g;
            $checkdeps = $checkdeps . " " .$libs;
406 407 408
            $checkdeps = sort_pkgs_by_orig ($oldapkbuild->{'checkdepends'}, $checkdeps);
        }

409
	say "CPAN check deps: $checkdeps";
410 411

	my $text = read_file "APKBUILD";
412
	if ($abstract && $abstract ne 'unknown') {
413
		$text =~ s/^pkgdesc=\"([^\"]*)\"$/pkgdesc=\"$abstract\"/mg or
414
			die "Can't find pkgdesc line in APKBUILD";
415
	}
416 417 418 419
	if (length(`find $metaprefix -name '*.xs'`)) {
		$text =~ s/^arch=\"([^\"]*)\"$/arch="all"/mg or
			die "Can't find arch line in APKBUILD";
	}
420 421 422 423
	if ($license ne 'unknown') {
		$text =~ s/^license=\"([^\"]*)\"$/license=\"$license\"/mg or
			die "Can't find license line in APKBUILD";
	}
424
	$text =~ s/^depends=\"([^\"]*)\"$/depends=\"$deps\"/mg or
425 426 427
		$text =~ s/(license=.*\n)/$1depends=\"$deps\"\n/gm or
			die "Can't insert depends line in APKBUILD";

428
	$text =~ s/^makedepends=\"([^\"]*)\"$/makedepends=\"$makedeps\"/mg or
429 430 431
		$text =~ s/(depends=.*\n)/$1makedepends=\"$makedeps\"\n/gm or
			die "Can't insert makedepends line in APKBUILD";

432
	$text =~ s/^checkdepends=\"([^\"]*)\"$/checkdepends=\"$checkdeps\"/mg or
433 434 435 436 437
		$text =~ s/(makedepends=.*\n)/$1checkdepends=\"$checkdeps\"\n/gm or
			die "Can't insert checkdepends line in APKBUILD";

	# remove empty variables
	$text =~ s/.*=""\n//g;
438 439 440 441 442 443

	open my $fh, '>', "APKBUILD" or die;
	print $fh $text;
	close $fh;
}

444 445
sub get_data {
	my $apkbuild = read_apkbuild;
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
	my $pkgreal = '';

	if (exists $apkbuild->{_realname}) {
		$pkgreal = $apkbuild->{_realname};
	} elsif (exists $apkbuild->{_pkgreal}) {
		$pkgreal = $apkbuild->{_pkgreal};
	} elsif (exists $apkbuild->{_pkgname}) {
		$pkgreal = $apkbuild->{_pkgname};
	} elsif (exists $apkbuild->{_name}) {
		$pkgreal = $apkbuild->{_name};
	} elsif (exists $apkbuild->{_realpkgname}) {
		$pkgreal = $apkbuild->{_realpkgname};
	} elsif (exists $apkbuild->{_pkg_real}) {
		$pkgreal = $apkbuild->{_pkg_real};
	} else {
		my $module = '';
		my $distribution = '';
		while ((my $key, my $value ) = each (%$apkbuild)) {
			# Do not parse any depends lines to not find incorrect module
			if ($key =~ m/.*depends.*/) {
				next;
			}
			# Try to find a perl module name in APKBUILD
			if ($value=~m/((\w+::)+\w+)/g) {
				# Match Perl Module names containing ::
				$module .= "$1 " unless $module =~ m/$1/;
			}
			elsif ($value =~ m/(([A-Z]\w+-)+\w+)/) {
				# Match possible distribution names with -
				$distribution .= "$1 " unless $distribution =~ m/ *$1 /;
			}
			elsif ( $value =~ m/.*release\/([A-Z]\w+).*/ ) {
				# Match Single Word Perl Module Name after release in URL?
				$distribution .= "$1 " unless $distribution =~ m/ *$1 /;
			}
		}

		# Want to try the traditional Module::Name first
		my $list = $module . $distribution;
		foreach (split / /, $list) {
			my $type = '';
			if( $_ =~ m/::/ ) {
				$type = 'module';
			} else {
				$type = 'release';
			}

			my $response = $ua->get("https://fastapi.metacpan.org/$type/$_");
			$response->is_success or next;;

			my $moddata = $json->decode($response->decoded_content);
			$moddata->{error} and next;

			$pkgreal = $moddata->{distribution};
			last;
		}
	}

	$pkgreal =~ s/-\$pkgver//g;

	my $response = $ua->get("https://fastapi.metacpan.org/release/$pkgreal");
	$response->is_success or
		die $response->status_line . " unable to find $pkgreal verify Perl Module name in APKBUILD\n";
509
	my $distdata = $json->decode($response->decoded_content);
510
	$distdata->{error} and die "Error trying to locate $pkgreal: $distdata->{error}\n";
511

512 513 514 515 516 517
	$response = $ua->get("https://fastapi.metacpan.org/module/$distdata->{main_module}");
	$response->is_success or die $response->status_line;
	my $moddata = $json->decode($response->decoded_content);
	$moddata->{error} and die "Error trying to locate $distdata->{main_module}: $moddata->{error}\n";

	return ($apkbuild, $distdata, $moddata);
518 519
}

520 521 522
my $abuild_conf = read_assignments_from_file("/etc/abuild.conf");
$packager = $abuild_conf->{PACKAGER} if $abuild_conf->{PACKAGER};

523 524 525
my $user_abuild_conf = read_assignments_from_file($ENV{"HOME"} . "/.abuild/abuild.conf");
$packager = $user_abuild_conf->{PACKAGER} if $user_abuild_conf->{PACKAGER};

526 527 528 529 530
given ( $ARGV[0] ) {
	when ("create") {
		my $module = $ARGV[1];
		$module or die "Module name is a mandatory argument";

531
		my $response = $ua->get("https://fastapi.metacpan.org/module/$module");
532 533 534 535
		$response->is_success or die $response->status_line;
		my $moddata = $json->decode($response->decoded_content);
		$moddata->{error} and die "Error trying to locate $module: $moddata->{error}\n";

Timothy Legge's avatar
Timothy Legge committed
536
		$response = $ua->get("https://fastapi.metacpan.org/release/$moddata->{distribution}");
537 538 539 540
		$response->is_success or die $response->status_line;
		my $distdata = $json->decode($response->decoded_content);
		$distdata->{error} and die "Error trying to locate $module: $distdata->{error}\n";

Timothy Legge's avatar
Timothy Legge committed
541
		my $apkname = map_cpan_to_apk $distdata->{metadata}{name};
542 543
		mkdir $apkname;
		chdir $apkname;
544
		write_apkbuild($distdata, undef, $moddata);
545 546 547 548 549
		prepare_tree;
		update_functions;
		do_depends;
	}
	when ("recreate") {
550
		#TODO: likely should keep pkgrel the same on recreate
551
		my ($apkbuild, $distdata, $moddata) = get_data;
552 553 554 555 556 557
		my $pkgver = $moddata->{version} =~ s/^[^0-9]+//r;
		if ($pkgver ne $apkbuild->{pkgver}) {
			#Reset pkgrel on upgrade on recreate
			say "Upgrading CPAN module from $apkbuild->{pkgver} to $pkgver";
			$apkbuild->{pkgrel}=0;
		}
558
		write_apkbuild($distdata, $apkbuild, $moddata);
559 560
		prepare_tree;
		update_functions;
561
		do_depends($apkbuild);
562 563
	}
	when ("upgrade") {
564
		my ($apkbuild, $distdata, $moddata) = get_data;
565

566
		my $pkgver = $moddata->{version} =~ s/^[^0-9]+//r;
567
		if ($pkgver ne $apkbuild->{pkgver}) {
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
			say "Upgrading CPAN module from $apkbuild->{pkgver} to $pkgver";

			my $text = read_file "APKBUILD";
			$text =~ s/^pkgver=(.*)$/pkgver=$pkgver/mg or
				die "Can't find pkgver line in APKBUILD";
			$text =~ s/^pkgrel=(.*)$/pkgrel=0/mg;
			open my $fh, '>', "APKBUILD" or die;
			say $fh $text;
			close $fh;

			prepare_tree;
			do_depends;
		} else {
			say "Up-to-data with CPAN";
		}
	}
584
	when ('check') {
585
		my ($apkbuild, $distdata, $moddata) = get_data;
586
		my $pkgver = $moddata->{version} =~ s/^[^0-9]+//r;
587 588 589 590
		say "$apkbuild->{pkgname}: Latest version: $pkgver Packaged version: $apkbuild->{pkgver}";
		if ($pkgver ne $apkbuild->{pkgver}) {
			exit(1);
		}
591
	}
592 593 594 595 596
	when ("update") {
		prepare_tree;
		do_depends;
	}
	default {
597
		say "Usage: apkbuild-cpan [create <Module::Name> | check | recreate | update | upgrade]";
598 599 600
		exit;
	}
}