/usr/share/perl5/DhMakePerl/Command/Packaging.pm is in dh-make-perl 0.94.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 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 297 298 299 300 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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 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 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 | package DhMakePerl::Command::Packaging;
use strict;
use warnings;
our $VERSION = '0.94';
use feature 'switch';
=head1 NAME
DhMakePerl::Command::Packaging - common routines for 'make' and 'refresh' dh-make-perl commands
=cut
use base 'DhMakePerl';
__PACKAGE__->mk_accessors(
qw( main_dir debian_dir
mod_cpan_version
meta perlname author
version rules docs examples copyright
control
dist_ini
)
);
use Array::Unique;
use Carp qw(confess);
use Config::INI::Reader ();
use CPAN ();
use CPAN::Meta;
use Cwd qw( getcwd );
use Debian::Control::FromCPAN;
use Debian::Dependencies;
use Debian::Rules;
use DhMakePerl::PodParser ();
use File::Basename qw(basename dirname);
use File::Find qw(find);
use File::Path ();
use File::Which;
use File::Spec::Functions qw(catfile catpath splitpath);
use Parse::DebianChangelog;
use Text::Balanced qw(extract_quotelike);
use Text::Wrap qw(fill);
use User::pwent;
use constant debstdversion => '3.9.8';
our %DEFAULTS = (
);
sub new {
my $class = shift;
$class = ref($class) if ref($class);
my $self = $class->SUPER::new(@_);
while( my( $k, $v ) = each %DEFAULTS ) {
$self->$k($v) unless defined $self->$k;
}
$self->cfg or die "cfg is mandatory";
my @docs;
tie @docs, 'Array::Unique';
$self->docs( \@docs );
my @examples;
tie @examples, 'Array::Unique';
$self->examples( \@examples );
$self->control( Debian::Control::FromCPAN->new )
unless $self->control;
return $self;
}
=head1 METHODS
=over
=item main_file(file_name)
Constructs a file name relative to the main source directory, L</main_dir>
=cut
sub main_file {
my( $self, $file ) = @_;
catfile( $self->main_dir, $file );
}
=item debian_file(file_name)
Constructs a file name relative to the debian/ sub-directory of the main source
directory.
=cut
sub debian_file {
my( $self, $file ) = @_;
catfile( $self->main_file('debian'), $file );
}
sub build_pl {
my ($self) = @_;
return $self->main_file('Build.PL');
}
sub makefile_pl {
my ($self) = @_;
return $self->main_file('Makefile.PL');
}
sub get_user {
return $ENV{LOGNAME} || $ENV{USER};
}
sub get_email {
my $self = shift;
my $email = $self->cfg->email;
$email ||= ( $ENV{DEBEMAIL} || $ENV{EMAIL} );
unless ($email) {
my $mailh;
chomp( $mailh = `cat /etc/mailname` );
$email = $self->get_user . '@' . $mailh;
}
$email =~ s/^(.*)\s+<(.*)>$/$2/;
return $email;
}
sub get_name {
my $self = shift;
my $name;
my $user = $self->get_user;
my $pwnam = getpwuid($<);
die "Cannot determine current user\n" unless $pwnam;
if ( defined $ENV{DEBFULLNAME} ) {
$name = $ENV{DEBFULLNAME};
}
else {
$name = $pwnam->gecos;
$name =~ s/,.*//;
}
$user ||= $pwnam->name;
$name ||= $user;
return $name;
}
sub get_developer {
my $self = shift;
return $self->get_name . " <" . $self->get_email . ">";
}
sub fill_maintainer {
my $self = shift;
my $src = $self->control->source;
my $maint = $self->get_developer;
if ( $self->cfg->pkg_perl ) {
my $pkg_perl_maint
= "Debian Perl Group <pkg-perl-maintainers\@lists.alioth.debian.org>";
unless ( ( $src->Maintainer // '' ) eq $pkg_perl_maint ) {
my $old_maint = $src->Maintainer;
$src->Maintainer($pkg_perl_maint);
$src->Uploaders->add($old_maint) if $old_maint;
}
$src->Uploaders->add($maint);
}
else {
$src->Maintainer($maint);
}
}
sub process_meta {
my ($self) = @_;
$self->meta({});
# Command line option nometa causes this function not to be run
if( $self->cfg->nometa ) {
return;
}
my $meta = $self->main_file('META.json');
if ( -e $meta ) {
print "Using META.json\n" if $self->cfg->verbose;
}
else {
$meta = $self->main_file('META.yml');
if ( -e $meta ) {
print "Using META.yml\n" if $self->cfg->verbose;
}
else {
print "WARNING: Neither META.json nor META.yml was found\n";
return;
}
}
$meta = CPAN::Meta->load_file($meta);
$self->meta( $meta->as_struct );
my $dist_ini_fn = $self->main_file('dist.ini');
$self->dist_ini( Config::INI::Reader->read_file($dist_ini_fn) )
if -e $dist_ini_fn;
}
sub set_package_name {
my $self = shift;
my $pkgname;
if (defined $self->cfg->packagename) {
$pkgname = $self->cfg->packagename;
}
else {
$pkgname = Debian::Control::FromCPAN->module_name_to_pkg_name( $self->perlname );
}
$self->control->source->Source($pkgname)
unless $self->control->source->Source;
$self->control->binary_tie->Push( $pkgname =>
Debian::Control::Stanza::Binary->new( { Package => $pkgname } ) )
unless $self->control->binary->{$pkgname};
}
sub pkgname {
@_ == 1 or die 'Syntax: $obj->pkgname()';
my $self = shift;
my $pkg = $self->control->binary_tie->Values(0)->Package;
defined($pkg) and $pkg ne ''
or confess "called before set_package_name()";
return $pkg;
}
sub srcname {
@_ == 1 or die 'Syntax: $obj->srcname()';
my $self = shift;
my $pkg = $self->control->source->Source;
defined($pkg) and $pkg ne ''
or confess "called before set_package_name()";
return $pkg;
}
sub get_wnpp {
my ( $self, $package ) = @_;
return undef unless $self->cfg->network;
my $wnpp = Debian::WNPP::Query->new(
{ cache_file => catfile( $self->cfg->home_dir, 'wnpp.cache' ) } );
my @bugs = $wnpp->bugs_for_package($package);
return $bugs[0];
}
sub extract_basic {
my ($self) = @_;
$self->extract_name_ver();
my $src = $self->control->source;
my $bin = $self->control->binary_tie->Values(0);
$src->Section('perl') unless defined $src->Section;
$src->Priority('optional') unless defined $src->Priority;
if ( $self->cfg->arch ) {
printf "Forcing architecture to '%s'\n", $self->cfg->arch;
$bin->Architecture( $self->cfg->arch );
}
else {
$bin->Architecture('all');
find( sub { $self->check_for_xs }, $self->main_dir );
}
$self->cfg->dh('9')
if not $self->cfg->_explicitly_set->{dh};
printf(
"Found: %s %s (%s arch=%s)\n",
$self->perlname, $self->version,
$self->pkgname, $bin->Architecture
) if $self->cfg->verbose;
$self->debian_dir( $self->main_file('debian') );
find(
{ no_chdir => 1,
wanted => sub {
return if $File::Find::name =~ $self->cfg->exclude;
if (/\.(pm|pod)$/) {
$self->extract_desc($_)
unless $bin->short_description
and $bin->long_description;
$self->extract_basic_copyright($_)
unless $self->author and $self->copyright;
}
},
},
$self->main_dir
);
}
sub sanitize_version {
my $self = shift;
my ($ver) = @_;
return undef unless defined($ver);
$ver =~ s/^v//;
$ver =~ s/[^-.+a-zA-Z0-9]+/-/g;
$ver = "0$ver" unless $ver =~ /^\d/;
return $ver;
}
sub extract_name_ver {
my ($self) = @_;
my ( $name, $ver );
if ( defined $self->meta->{name} and defined $self->meta->{version} ) {
$name = $self->meta->{name};
$ver = $self->meta->{version};
}
elsif ( defined $self->cfg->packagename and defined $self->cfg->version ) {
$name = $self->cfg->packagename;
$ver = $self->cfg->version;
}
else {
if ( -e $self->build_pl ) {
print "Extracting name and version from Build.PL\n";
$self->extract_name_ver_from_build( $self->build_pl );
}
elsif ( -e $self->makefile_pl ) {
print "Extracting name and version from Makefile.PL\n";
$self->extract_name_ver_from_makefile( $self->makefile_pl );
}
else {
if ( $self->cfg->cpan ) {
my $name = $self->cfg->cpan;
$name =~ s/::/-/g;
$self->perlname($name);
}
else {
die "Unable to determine dist name, no Build.PL, no Makefile.PL\nPlease use --cpan.\n";
}
}
$name = $self->perlname;
$ver = $self->version;
}
if ($self->cfg->version) {
#Version specified on command line trumps other versions
$ver = $self->cfg->version
} elsif ( $self->mod_cpan_version ) {
if ($self->mod_cpan_version != $ver) {
die "Version ambiguity, cpan has ".$self->mod_cpan_version.", module has ".$ver.". Please specify version with --version.\n";
}
}
# final sanitazing of name and version
$name =~ s/::/-/g if defined $name;
$ver = $self->sanitize_version($ver) if defined $ver && !$self->cfg->version;
defined($ver) and $ver ne ''
or die "Unable to determine dist version\. Please use --version.\n";
defined($name) and $name ne ''
or die "Unable to determine dist name\. Please use --packagename.\n";
$self->perlname($name);
$self->version($ver);
$self->set_package_name;
}
sub extract_name_ver_from_build {
my ( $self, $build ) = @_;
my ( $file, $name, $ver, $vfrom, $dir );
{
local $/ = undef;
my $fh = $self->_file_r($build);
$file = $fh->getline;
}
# Replace q[quotes] by "quotes"
$file =~ s/q\[(.+)]/'$1'/g;
# Get the name
if ($file =~ /([\'\"]?)
dist_name\1\s*
(=>|,)
\s*
([\'\"]?)
(\S+)\3/xs
)
{
$name = $4;
}
elsif (
$file =~ /([\'\"]?)
module_name\1\s*
(=>|,)
\s*
(\S+)/xs
)
{
$name = $self->unquote($3);
$name =~ s/::/-/g;
# just in case we need it later
$vfrom = $name;
$vfrom =~ s/-/::/g;
$vfrom =~s{::}{/}g;
$vfrom = "lib/$vfrom.pm";
}
return unless defined $name;
$name =~ s/,.*$//;
# band aid: need to find a solution also for build in directories
# warn "name is $name (cpan name: $self->cfg->cpan)\n";
$name = $self->cfg->cpan if ( $name eq '__PACKAGE__' && $self->cfg->cpan );
$name = $self->cfg->cpanplus if ( $name eq '__PACKAGE__' && $self->cfg->cpanplus );
# Get the version
if ( defined $self->cfg->version ) {
# Explicitly specified
$ver = $self->cfg->version;
}
elsif ( $file =~ /([\'\"]?)\sdist_version\1\s*(=>|,)\s*([\'\"]?)([^\s,]*)\3/s ) {
$ver = $4;
# Where is the version taken from?
$vfrom = $4
if $file
=~ /([\'\"]?)dist_version_from\1\s*(=>|,)\s*([\'\"]?)([^\s,]*)\3/s;
}
elsif ( $file =~ /([\'\"]?)dist_version_from\1\s*(=>|,)\s*([\'\"]?)([^\s,]*)\3/s )
{
$vfrom = $4;
}
$dir = dirname($build) || './';
for ( ( $name, $ver ) ) {
next unless defined;
next unless /^\$/;
# decode simple vars
s/(\$\w+).*/$1/;
if ( $file =~ /\Q$_\E\s*=\s*([\'\"]?)(\S+)\1\s*;/ ) {
$_ = $2;
}
}
unless ( defined $ver ) {
local $/ = "\n";
# apply the method used by makemaker
if ( defined $dir
and defined $vfrom
and -f "$dir/$vfrom"
and -r "$dir/$vfrom" )
{
my $fh = $self->_file_r("$dir/$vfrom");
while ( my $lin = $fh->getline ) {
if ( $lin =~ /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/ ) {
no strict;
#warn "ver: $lin";
$ver = ( eval $lin )[0];
last;
}
}
$fh->close;
}
else {
if ( $self->mod_cpan_version ) {
$ver = $self->mod_cpan_version;
warn "Cannot use internal module data to gather the "
. "version; using cpan_version\n";
}
else {
die "Cannot use internal module data to gather the "
. "version; use --cpan or --version\n";
}
}
}
$self->perlname($name);
$self->version($ver);
$self->set_package_name;
if ( defined($vfrom) ) {
$self->extract_desc("$dir/$vfrom");
$self->extract_basic_copyright("$dir/$vfrom");
}
}
sub extract_name_ver_from_makefile {
my ( $self, $makefile ) = @_;
my ( $file, $name, $ver, $vfrom, $dir );
{
local $/ = undef;
my $fh = $self->_file_r($makefile);
$file = $fh->getline;
}
# Get the name
if ($file =~ /([\'\"]?)
DISTNAME\1\s*
(=>|,)
\s*
(\S+)/xs
)
{
# Regular MakeMaker
$name = $self->unquote($3);
}
elsif (
$file =~ /([\'\"]?)
NAME\1\s*
(=>|,)
\s*
(\S+)\s*,?/xs
)
{
# Regular MakeMaker
$name = $self->unquote($3);
}
elsif (
$file =~ m{
name
\s*
(\S+) # Quoted name
\s*;
}xs
)
{
# Module::Install syntax
$name = $self->unquote($1);
}
return unless defined $name;
$name =~ s/,.*$//;
# band aid: need to find a solution also for build in directories
# warn "name is $name (cpan name: $self->cfg->cpan)\n";
$name = $self->cfg->cpan if ( $name eq '__PACKAGE__' && $self->cfg->cpan );
$name = $self->cfg->cpanplus if ( $name eq '__PACKAGE__' && $self->cfg->cpanplus );
# Get the version
if ( defined $self->cfg->version ) {
# Explicitly specified
$ver = $self->cfg->version;
}
elsif ( $file =~ /([\'\"]?)\bVERSION\1\s*(=>|,)\s*([\'\"]?)([^\s,]*)\3/s ) {
# Regular MakeMaker
$ver = $4;
# Where is the version taken from?
$vfrom = $4
if $file
=~ /([\'\"]?)VERSION_FROM\1\s*(=>|,)\s*([\'\"]?)([^\s,]*)\3/s;
}
elsif ( $file =~ /([\'\"]?)VERSION_FROM\1\s*(=>|,)\s*([\'\"]?)([^\s,]*)\3/s )
{
# Regular MakeMaker pointing to where the version is taken from
$vfrom = $4;
}
elsif (
$file =~ m{
\bversion\b\s* # The word version
\(?\s* # Optional open-parens
(['"]?) # Optional quotes
([\d_.]+) # The actual version.
\1 # Optional close-quotes
\s*\)? # Optional close-parenthesis.
}sx
) {
# Module::Install
$ver = $2;
}
$dir = dirname($makefile) || './';
for ( ( $name, $ver ) ) {
next unless defined;
next unless /^\$/;
# decode simple vars
s/(\$\w+).*/$1/;
if ( $file =~ /\Q$_\E\s*=\s*([\'\"]?)(\S+)\1\s*;/ ) {
$_ = $2;
}
}
unless ( defined $ver ) {
local $/ = "\n";
# apply the method used by makemaker
if ( defined $dir
and defined $vfrom
and -f "$dir/$vfrom"
and -r "$dir/$vfrom" )
{
my $fh = $self->_file_r("$dir/$vfrom");
while ( my $lin = $fh->getline ) {
if ( $lin =~ /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/ ) {
no strict;
#warn "ver: $lin";
$ver = ( eval $lin )[0];
last;
}
}
$fh->close;
}
else {
if ( $self->mod_cpan_version ) {
$ver = $self->mod_cpan_version;
warn "Cannot use internal module data to gather the "
. "version; using cpan_version\n";
}
else {
die "Cannot use internal module data to gather the "
. "version; use --cpan or --version\n";
}
}
}
$self->perlname($name);
$self->version($ver);
$self->set_package_name;
if ( defined($vfrom) ) {
$self->extract_desc("$dir/$vfrom");
$self->extract_basic_copyright("$dir/$vfrom");
}
}
sub extract_desc {
my ( $self, $file ) = @_;
my $bin = $self->control->binary_tie->Values(0);
my $short_desc = $bin->short_description;
$short_desc and return;
return unless -f $file;
my ( $parser, $modulename );
$parser = new DhMakePerl::PodParser;
$parser->set_names(qw(NAME DESCRIPTION DETAILS));
$parser->parse_from_file($file);
if ( $short_desc ) {
# No-op - We already have it, probably from the command line
}
elsif ( $self->meta->{abstract} ) {
# Get it from META.yml
$short_desc = $self->meta->{abstract};
}
elsif ( my $my_desc = $parser->get('NAME') ) {
# Parse it, fix it, send it!
$my_desc =~ s/^\s*\S+\s+-\s+//s;
$my_desc =~ s/^\s+//s;
$my_desc =~ s/\s+$//s;
$my_desc =~ s/^([^\s])/ $1/mg;
$my_desc =~ s/\n.*$//s;
$short_desc = $my_desc;
}
if ( defined($short_desc) ) {
# Replace linefeed (not followed by a space) in short description with
# spaces
$short_desc =~ s/\n(?=\S)/ /gs;
$short_desc =~ s/^\s+//; # strip leading spaces
$short_desc =~ s/^(?:(A|An|The))\s+//i; # strip leading article
}
# have a fall-back for the short description
$short_desc ||= '(no short description found)';
$bin->short_description($short_desc);
my $long_desc;
unless ( $bin->long_description ) {
$long_desc
= $parser->get('DESCRIPTION')
|| $parser->get('DETAILS')
|| '';
( $modulename = $self->perlname ) =~ s/-/::/g;
$long_desc =~ s/This (?:module|library|plugin)/$modulename/;
local ($Text::Wrap::columns) = 78;
$long_desc = fill( "", "", $long_desc );
}
if ( defined($long_desc) ) {
$long_desc =~ s/^[\s\n]+//s;
$long_desc =~ s/\s+$//s;
$long_desc =~ s/^\t/ /mg;
$long_desc =~ s/\r//g;
$long_desc = '(no description was found)' if $long_desc eq '';
$bin->long_description(
"$long_desc\n\nThis description was automagically extracted from the module by dh-make-perl.\n"
);
}
$parser->cleanup;
}
sub check_for_xs {
my ($self) = @_;
# we need the relative path here. Otherwise the check will give bogus
# results if the working dir matches the pattern
my $rel_path = substr( $File::Find::name, length( $self->main_dir ) );
( $rel_path !~ m{/(?:examples?|samples|eg|t|docs|win32?|demos?)/} )
and
( !$self->cfg->exclude or $rel_path !~ $self->cfg->exclude )
&& /\.(xs|c|cpp|cxx)$/i
&& do {
$self->control->binary_tie->Values(0)->Architecture('any');
};
}
sub extract_basic_copyright {
my ( $self, $file ) = @_;
for my $f ( map( $self->main_file($_), qw(LICENSE LICENCE COPYING) ) ) {
if ( -f $f ) {
my $fh = $self->_file_r($f);
$self->copyright( join( '', $fh->getlines ) );
}
}
if ( defined($file) ) {
my ( $parser, $modulename );
$parser = new DhMakePerl::PodParser;
return unless -f $file;
$parser->set_names(qw(COPYRIGHT AUTHOR AUTHORS));
$parser->parse_from_file($file);
$self->copyright( $parser->get('COPYRIGHT')
|| $parser->get('LICENSE')
|| $parser->get('COPYRIGHT & LICENSE') )
unless $self->copyright;
if ( !$self->author ) {
if ( ref $self->meta->{author} ) {
# Does the author information appear in META.yml?
$self->author( join( ', ', @{ $self->meta->{author} } ) );
}
else {
# Get it from the POD - and clean up
# trailing/preceding spaces!
my $a = $parser->get('AUTHOR') || $parser->get('AUTHORS');
$a =~ s/^\s*(\S.*\S)\s*$/$1/gs if $a;
$self->author($a);
}
}
$parser->cleanup;
}
}
sub extract_docs {
my ( $self ) = @_;
my $dir = $self->main_dir;
$dir .= '/' unless $dir =~ m(/$);
find(
{ preprocess => sub {
my $bn = basename $File::Find::dir;
return ()
if $bn eq '.svn-base'
or $bn eq '.svn'
or $bn eq '.git';
return @_;
},
wanted => sub {
push(
@{ $self->docs },
substr( $File::Find::name, length($dir) )
)
if (
$File::Find::name ne $self->main_dir . '/README'
and /^\b(README|TODO|BUGS|NEWS|ANNOUNCE|CONTRIBUTING)\b/i
and !/\.(pod|pm)$/
and ( !$self->cfg->exclude
or $File::Find::name !~ $self->cfg->exclude )
and !/\.svn-base$/
and $File::Find::name
!~ m{debian/README\.(?:source|[Dd]ebian)}
);
},
},
$dir
);
}
sub extract_examples {
my ( $self ) = @_;
my $dir = $self->main_dir;
$dir .= '/' unless $dir =~ m{/$};
find(
sub {
return if $_ eq '.'; # skip the directory itself
my $exampleguess = substr( $File::Find::name, length($dir) );
push( @{ $self->examples },
( -d $exampleguess ? $exampleguess . '/*' : $exampleguess ) )
if ( /^(examples?|eg|samples?)$/i
and ( !$self->cfg->exclude or $File::Find::name !~ $self->cfg->exclude )
);
},
$dir
);
}
sub read_rules {
my $self = shift;
return if $self->rules;
my $file = $self->debian_file('rules');
$self->rules( Debian::Rules->new($file) );
}
sub create_rules {
my ( $self ) = @_;
my $file = $self->debian_file('rules');
$self->rules( Debian::Rules->new($file) );
if ( $self->rules->is_dhtiny ) {
print "$file already uses dh tiny rules\n"
if $self->cfg->verbose;
return;
}
$self->backup_file($file);
my $rulesname = 'rules.dh.tiny';
for my $source (
catfile( $self->cfg->home_dir, $rulesname ),
catfile( $self->cfg->data_dir, $rulesname )
) {
if ( -e $source ) {
print "Using rules: $source\n" if $self->cfg->verbose;
$self->rules->read($source);
last;
};
}
$self->rules->write;
chmod( 0755, $file ) or die "chmod($file): $!";
}
sub create_compat {
my ( $self, $file ) = @_;
my $fh = $self->_file_w($file);
$fh->print( $self->cfg->dh, "\n" );
$fh->close;
}
sub update_file_list( $ % ) {
my ( $self, %p ) = @_;
my $pkgname = $self->pkgname;
while ( my ( $file, $new_content ) = each %p ) {
next unless @$new_content;
# pkgname.foo file
my $pkg_file = $self->debian_file("$pkgname.$file");
my %uniq_content;
my @existing_content;
# if a package.foo exists read its values first
if ( -r $pkg_file ) {
my $fh = $self->_file_r($pkg_file);
@existing_content = $fh->getlines;
chomp(@existing_content);
# make list of files for package.foo unique
$uniq_content{$_} = 1 for @existing_content;
}
$uniq_content{$_} = 1 for @$new_content;
# write package.foo file with unique entries
open F, '>', $pkg_file or die $!;
for ( @existing_content, @$new_content ) {
# we have the unique hash
# we delete from it each printed line
# so if a line is not in the hash, this means we have already
# printed it
next unless exists $uniq_content{$_};
delete $uniq_content{$_};
print F "$_\n";
}
close F;
}
}
sub create_copyright {
my ( $self, $filename ) = @_;
my ( $fh, %fields, @res, @incomplete, $year );
$fh = $self->_file_w($filename);
# In case author string spawns more than one line, indent them all.
my $cprt_author = $self->author || '(information incomplete)';
$cprt_author =~ s/\n/\n /gs;
$cprt_author =~ s/^\s*$/ ./gm;
push @res, 'Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/';
# Header section
%fields = (
'Upstream-Name' => $self->perlname,
'Upstream-Contact' => $cprt_author,
'Source' => $self->upsurl
);
for my $key ( sort keys %fields ) {
my $full = "$key";
if ( $fields{$key} ) {
push @res, "$full: $fields{$key}";
}
else {
push @incomplete, "Could not get the information for $full";
}
}
push( @res,
"DISCLAIMER: This copyright info was automatically extracted",
" from the perl module. It may not be accurate, so you better",
" check the module sources in order to ensure the module for its",
" inclusion in Debian or for general legal information. Please,",
" if licensing information is incorrectly generated, file a bug",
" on dh-make-perl.",
" NOTE: Don't forget to remove this disclaimer once you are happy",
" with this file." );
push @res, '';
# Files section - We cannot "parse" the module's licensing
# information for anything besides general information.
push @res, 'Files: *';
my $cprt_year;
if ( $self->dist_ini
and $self->dist_ini->{_}{copyright_year} )
{
$cprt_year = $self->dist_ini->{_}{copyright_year};
}
# Absence of author should have already been reported in the
# Header section
push @res,
"Copyright: " . ( $cprt_year ? "$cprt_year, " : '' ) . $cprt_author;
# This is far from foolproof, but usually works with most
# boilerplate-generated modules.
#
# We go over the most common combinations only
my ( %texts, %licenses );
%texts = (
'Artistic' =>
" This program is free software; you can redistribute it and/or modify\n"
. " it under the terms of the Artistic License, which comes with Perl.\n"
. " .\n"
. " On Debian systems, the complete text of the Artistic License can be\n"
. " found in `/usr/share/common-licenses/Artistic'.",
'Artistic-2.0' => do {
require Software::License::Artistic_2_0;
my $artistic2 = Software::License::Artistic_2_0->new(
{ holder => 'noname', } );
my $text = $artistic2->license;
$text =~ s/\n$//s;
$text =~ s/[ \t]+$//mg;
$text =~ s/^\n/.\n/mg;
$text =~ s/^/ /mg;
$text;
},
'GPL-1+' =>
" This program is free software; you can redistribute it and/or modify\n"
. " it under the terms of the GNU General Public License as published by\n"
. " the Free Software Foundation; either version 1, or (at your option)\n"
. " any later version.\n"
. " .\n"
. " On Debian systems, the complete text of version 1 of the GNU General\n"
. " Public License can be found in `/usr/share/common-licenses/GPL-1'.",
'GPL-2' =>
" This program is free software; you can redistribute it and/or modify\n"
. " it under the terms of the GNU General Public License as published by\n"
. " the Free Software Foundation; version 2 dated June, 1991.\n"
. " .\n"
. " On Debian systems, the complete text of version 2 of the GNU General\n"
. " Public License can be found in `/usr/share/common-licenses/GPL-2'.",
'GPL-2+' =>
" This program is free software; you can redistribute it and/or modify\n"
. " it under the terms of the GNU General Public License as published by\n"
. " the Free Software Foundation; version 2 dated June, 1991, or (at your\n"
. " option) any later version.\n"
. " .\n"
. " On Debian systems, the complete text of version 2 of the GNU General\n"
. " Public License can be found in `/usr/share/common-licenses/GPL-2'.",
'GPL-3' =>
" This program is free software; you can redistribute it and/or modify\n"
. " it under the terms of the GNU General Public License as published by\n"
. " the Free Software Foundation; version 3 dated June, 2007.\n"
. " .\n"
. " On Debian systems, the complete text of version 3 of the GNU General\n"
. " Public License can be found in `/usr/share/common-licenses/GPL-3'.",
'GPL-3+' =>
" This program is free software; you can redistribute it and/or modify\n"
. " it under the terms of the GNU General Public License as published by\n"
. " the Free Software Foundation; version 3 dated June, 2007, or (at your\n"
. " option) any later version.\n"
. " .\n"
. " On Debian systems, the complete text of version 3 of the GNU General\n"
. " Public License can be found in `/usr/share/common-licenses/GPL-3'.",
'Apache-2.0' =>
" Licensed under the Apache License, Version 2.0 (the \"License\");\n"
. " you may not use this file except in compliance with the License.\n"
. " You may obtain a copy of the License at\n"
. " http://www.apache.org/licenses/LICENSE-2.0\n"
. " Unless required by applicable law or agreed to in writing, software\n"
. " distributed under the License is distributed on an \"AS IS\" BASIS,\n"
. " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
. " See the License for the specific language governing permissions and\n"
. " limitations under the License.\n"
. " .\n"
. " On Debian systems, the complete text of the Apache License,\n"
. " Version 2.0 can be found in `/usr/share/common-licenses/Apache-2.0'.",
'unparsable' =>
" No known license could be automatically determined for this module.\n"
. " If this module conforms to a commonly used license, please report this\n"
. " as a bug in dh-make-perl. In any case, please find the proper license\n"
. " and fix this file!"
);
if ( $self->meta->{license} or $self->copyright ) {
my $mangle_cprt;
# Pre-mangle the copyright information for the common similar cases
$mangle_cprt = $self->copyright || ''; # avoid warning
$mangle_cprt =~ s/GENERAL PUBLIC LICENSE/GPL/g;
# Of course, more licenses (i.e. LGPL, BSD-like, Public
# Domain, etc.) could be added... Feel free to do so. Keep in
# mind that many licenses are not meant to be used as
# templates (i.e. you must add the author name and some
# information within the licensing text as such).
if ( $self->meta->{license} ) {
foreach ( @{ $self->meta->{license} } ) {
if (/apache_2_0/) { $licenses{'Apache-2.0'} = 1; next; }
if (/artistic_1/) { $licenses{'Artistic'} = 1; next; }
if (/artistic_2/) { $licenses{'Artistic-2.0'} = 1; next; }
# EU::MM and M::B converts the 'gpl' without a version to gpl_1.
# As GPL without a version means *any* GPL, I think it's safe to use GPL-1+ here
if (/gpl_1/) { $licenses{'GPL-1+'} = 1; next; }
if (/perl_5/) {
$licenses{'GPL-1+'} = 1;
$licenses{'Artistic'} = 1;
next;
}
}
}
else {
if ( $mangle_cprt =~ /terms\s*as\s*Perl\s*itself/is ) {
$licenses{'GPL-1+'} = 1;
$licenses{'Artistic'} = 1;
}
if ( $mangle_cprt =~ /[^L]GPL/ ) {
if ( $mangle_cprt =~ /GPL.*version\s*1.*later\s+version/is ) {
$licenses{'GPL-1+'} = 1;
}
elsif (
$mangle_cprt =~ /GPL.*version\s*2.*later\s+version/is )
{
$licenses{'GPL-2+'} = 1;
}
elsif ( $mangle_cprt =~ /GPL.*version\s*2/is ) {
$licenses{'GPL-2'} = 1;
}
elsif (
$mangle_cprt =~ /GPL.*version\s*3.*later\s+version/is )
{
$licenses{'GPL-3+'} = 1;
}
elsif ( $mangle_cprt =~ /GPL.*version\s*3/is ) {
$licenses{'GPL-3'} = 1;
}
}
if ( $mangle_cprt =~ /Artistic\s*License\s*2\.0/is ) {
$licenses{'Artistic-2.0'} = 1;
}
elsif ( $mangle_cprt =~ /Artistic\s*License/is ) {
$licenses{'Artistic'} = 1;
}
if ( $mangle_cprt =~ /Apache\s*License.*2\.0/is ) {
$licenses{'Apache-2.0'} = 1;
}
# Other licenses?
if ( !keys(%licenses) ) {
$licenses{unparsable} = 1;
push( @incomplete,
"Licensing information is present, but cannot be parsed"
);
}
}
push @res, "License: " . join( ' or ', sort keys %licenses );
}
else {
push @res, "License: ";
push @incomplete, 'No licensing information found';
}
# debian/* files information - We default to the module being
# licensed as the super-set of the module and Perl itself.
$licenses{'Artistic'} = $licenses{'GPL-1+'} = 1;
$year = (localtime)[5] + 1900;
push( @res, "", "Files: debian/*" );
if ( $self->cfg->command eq 'refresh' ) {
my @from_changelog
= $self->copyright_from_changelog( $self->get_developer, $year );
$from_changelog[0] = "Copyright:" . $from_changelog[0];
push @res, @from_changelog;
}
else {
push @res, "Copyright: $year, " . $self->get_developer;
}
push @res, "License: " . join( ' or ', sort keys %licenses );
map { $texts{$_} && push( @res, '', "License: $_", $texts{$_} ) }
sort keys %licenses;
$fh->print( join( "\n", @res, '' ) );
$fh->close;
$self->_warn_incomplete_copyright( join( "\n", @incomplete ) )
if @incomplete;
}
sub upsurl {
my $self = shift;
return sprintf( "https://metacpan.org/release/%s", $self->perlname );
}
my $ACTUAL_NAME_RE = '\pL[\s\pL\-\'\.]*\pL';
# See http://www.faqs.org/rfcs/rfc2822.html
# Section 3.4.1
use Email::Address;
my $EMAIL_RE = $Email::Address::addr_spec;
my $EMAIL_CHANGES_RE = qr{
^ # beginining of line
\s+\*\s # item marker
Email\schange:\s # email change token
($ACTUAL_NAME_RE) # actual name
\s+->\s+ # gap between name and email
($EMAIL_RE) # email address
$ # end of line
}xms;
my $PERSON_PARSE_RE = qr{
\A # beginining of string
($ACTUAL_NAME_RE) # actual name
\s # gap
\<$EMAIL_RE\> # logged email
\z # end of string
}xms;
# This is what needs fixing.
sub copyright_from_changelog {
my ( $self, $firstmaint, $firstyear ) = @_;
my %maintainers = ();
@{ $maintainers{$firstmaint} } = ($firstyear);
my $chglog = Parse::DebianChangelog->init(
{ infile => $self->debian_file('changelog') } );
my %email_changes = ();
foreach ( $chglog->data() ) {
my $person = $_->Maintainer;
my $date = $_->Date;
my @date_pieces = split( " ", $date );
my $year = $date_pieces[3];
if (my %changes = ($_->Changes =~ m/$EMAIL_CHANGES_RE/xmsg)) {
# This way round since we are going backward in time thru changelog
foreach my $p (keys %changes) {
$changes{$p} =~ s{[\s\n]+$}{}xms;
}
%email_changes = (
%changes,
%email_changes
);
}
if (my ($name) = ($person =~ $PERSON_PARSE_RE)) {
if (exists $email_changes{$name}) {
$person = "$name <$email_changes{$name}>";
}
}
if ( defined( $maintainers{$person} ) ) {
push @{ $maintainers{$person} }, $year;
@{ $maintainers{$person} } = sort( @{ $maintainers{$person} } );
}
else {
@{ $maintainers{$person} } = ($year);
}
}
my @strings;
foreach my $maint_name ( keys %maintainers ) {
my $str = " ";
my %uniq = map { $_ => 0 } @{ $maintainers{$maint_name} };
foreach ( sort keys %uniq ) {
$str .= $_;
$str .= ", ";
}
$str .= $maint_name;
push @strings, $str;
}
@strings = sort @strings;
return @strings;
}
sub _warn_incomplete_copyright {
my $self = shift;
print '*' x 10, '
Copyright information incomplete!
Upstream copyright information could not be automatically determined.
If you are building this package for your personal use, you might disregard
this information; however, if you intend to upload this package to Debian
(or in general, if you plan on distributing it), you must look into the
complete copyright information.
The causes for this warning are:
', @_, "\n";
}
sub write_source_format {
my ( $self, $path ) = @_;
my ( $vol, $dir, $file ) = splitpath($path);
$dir = catpath( $vol, $dir );
if ( $self->cfg->source_format eq '1.0' ) {
# this is the default, remove debian/source
File::Path::rmtree($dir);
}
else {
# make sure the directory exists
File::Path::mkpath($dir) unless -d $dir;
my $fh = $self->_file_w($path);
$fh->print( $self->cfg->source_format, "\n" );
$fh->close;
}
}
sub module_build {
my $self = shift;
# dehbelper prefers Makefile.PL over Build.PL unless the former is a
# Module::Build::Compat wrapper
return 'Module-Build' if $self->makefile_pl_is_MBC;
return 'MakeMaker' if -e $self->makefile_pl;
return ( -f $self->main_file('Build.PL') ) ? "Module-Build" : "MakeMaker";
}
=item explained_dependency I<$reason>, I<$dependencies>, I<@dependencies>
Adds the list of dependencies to I<$dependencies> and shows I<$reason> if in
verbose mode.
Used to both bump a dependency and tell the user why.
I<$dependencies> is an instance of L<Debian::Dependencies> class, and
I<@dependencies> is a list of L<Debian::Dependency> instances or strings.
The message printed looks like C<< $reason needs @dependencies >>.
=cut
sub explained_dependency {
my ( $self, $reason, $deps, @to_add ) = @_;
$deps->add(@to_add);
warn sprintf( "%s needs %s\n", $reason, join( ', ', @to_add ) );
}
=item configure_cpan
Configure CPAN module. It is safe to call this method more than once, it will
do nothing if CPAN is already configured.
=cut
sub configure_cpan {
my $self = shift;
return if $CPAN::Config_loaded;
my $save_cwd = getcwd();
CPAN::HandleConfig->load( be_silent => not $self->cfg->verbose )
if $self->cfg->network;
unshift( @{ $CPAN::Config->{'urllist'} }, $self->cfg->cpan_mirror )
if $self->cfg->cpan_mirror;
$CPAN::Config->{'tar_verbosity'} = $self->cfg->verbose ? 'v' : '';
$CPAN::Config->{'load_module_verbosity'}
= $self->cfg->verbose ? 'verbose' : 'silent';
$CPAN::Config->{build_requires_install_policy} = 'no';
$CPAN::Config->{prerequisites_policy} = 'ignore';
chdir $save_cwd;
}
=item discover_dependencies
Just a wrapper around $self->control->discover_dependencies which provides the
right parameters to it.
Returns a list of missing modules.
=cut
sub discover_dependencies {
my $self = shift;
if ( my $apt_contents = $self->get_apt_contents ) {
my $wnpp_query;
$wnpp_query
= Debian::WNPP::Query->new(
{ cache_file => catfile( $self->cfg->home_dir, 'wnpp.cache' ) } )
if $self->cfg->network;
# control->discover_dependencies needs configured CPAN
$self->configure_cpan;
# Attempt to get an instance of DPKG::Parse::Available. If this
# isn't available, warn the user, as versions of packages cannot
# be checked.
# Don't cache this in case we've built and installed a
# module in this instance.
my $dpkg_available;
if ( eval { require DPKG::Parse::Available } && DPKG::Parse->VERSION >= 0.02 ) {
$dpkg_available = DPKG::Parse::Available->new;
$dpkg_available->parse;
} else {
warn "DPKG::Parse v0.02 or higher not found.";
warn "Versions of required packages will not be checked.";
}
return $self->control->discover_dependencies(
{ dir => $self->main_dir,
verbose => $self->cfg->verbose,
apt_contents => $self->apt_contents,
dpkg_available => $dpkg_available,
require_deps => $self->cfg->requiredeps,
install_deps => $self->cfg->install_deps,
install_build_deps => $self->cfg->install_build_deps,
wnpp_query => $wnpp_query,
intrusive => $self->cfg->intrusive,
}
);
}
elsif (which('apt-file')) {
warn "No APT contents can be loaded but apt-file seems installed.\n";
warn "Please run 'apt-file update' as root.\n";
warn "(If that doesn't help, please report a bug against dh-make-perl.)\n";
warn "Dependencies not updated.\n";
return ();
}
else {
warn "No APT contents can be loaded.\n";
warn "Please install the 'apt-file' package (at least version 3) and\n";
warn "run 'apt-file update' as root.\n";
warn "Dependencies not updated.\n";
return ();
}
}
=item discover_utility_deps
Determines whether certain versions of L<debhelper(1)> and other packages are
needed by the build process.
The following special cases are detected:
=over
=item Module::Build::Tiny
if L<Module::Build::Tiny> is present in the build-dependencies, debhelper
dependency is raised to 9.20140227~.
=item dh --with=quilt
C<dh --with=quilt> needs quilt.
=item quilt.make
If F</usr/share/quilt/quilt.make> is included in F<debian/rules>, a
build-dependency on C<quilt> is added.
=item Module::Build
The proper build-dependency in this case is
perl
The on perl without a version is set as Lenny has already 5.10 which
includes first Module::Build.
=back
=cut
sub discover_utility_deps {
my ( $self, $control ) = @_;
my $build_deps = $control->source->Build_Depends;
my $build_deps_indep = $control->source->Build_Depends_Indep;
my $bin_deps = $control->binary_tie->Values(0)->Depends;
my $architecture = $control->binary_tie->Values(0)->Architecture;
# remove any existing dependencies
$build_deps->remove( 'quilt', 'debhelper' );
# start with the minimum
my $debhelper_version = $self->cfg->dh;
if ( $architecture eq 'all' ) {
$build_deps_indep->add('perl');
}
else {
$build_deps->add('perl');
}
$build_deps->add( Debian::Dependency->new( 'debhelper', $debhelper_version ) );
$self->explained_dependency( 'Module::Build::Tiny', $build_deps,
'debhelper (>= 9.20140227~)' )
if $build_deps->has('libmodule-build-tiny-perl');
for ( @{ $self->rules->lines } ) {
$self->explained_dependency(
'dh --with=quilt',
$build_deps, 'quilt',
) if /dh\s+.*--with[= ]quilt/;
$self->explained_dependency(
'dh --with=bash-completion',
$build_deps,
'bash-completion'
) if (/dh\s+.*--with[= ]bash[-_]completion/);
$self->explained_dependency(
'dh --with=perl_dbi',
$build_deps,
'libdbi-perl'
) if (/dh\s+.*--with[= ]perl[-_]dbi/);
$self->explained_dependency( 'quilt.make', $build_deps, 'quilt' )
if m{^include /usr/share/quilt/quilt.make};
}
# Ensure both libmodule-build-perl and perl are in B-D
# (and not in B-D-I).
if ( $self->module_build eq 'Module-Build' ) {
$build_deps_indep->remove('libmodule-build-perl');
$build_deps_indep->remove('perl');
$self->explained_dependency( 'Module::Build', $build_deps,
'libmodule-build-perl' );
$self->explained_dependency( 'Module::Build', $build_deps,
'perl' );
}
# some mandatory dependencies
$bin_deps += '${shlibs:Depends}' if $architecture eq 'any';
$bin_deps += '${misc:Depends}, ${perl:Depends}';
}
=item makefile_pl_is_MBC
Checks if F<Makefile.PL> is a compatibility wrapper around Build.PL provided by
Module::Build::Compat.
=cut
sub makefile_pl_is_MBC
{
my $self = shift;
my $mf = $self->makefile_pl;
return undef unless -e $mf;
my $fh = $self->_file_r($mf);
while( defined( $_ = <$fh> ) ) {
if ( /^[^#"]*Module::Build::Compat/ ) {
return 1;
}
}
return 0;
}
=item backup_file(file_name)
Creates a backup copy of the specified file by adding C<.bak> to its name. If
the backup already exists, it is overwritten.
Does nothing unless the C<backups> option is set.
=cut
sub backup_file {
my( $self, $file ) = @_;
if ( $self->cfg->backups ) {
warn "W: overwriting $file.bak\n"
if -e "$file.bak" and $self->cfg->verbose;
rename( $file, "$file.bak" );
}
}
=item unquote(I<string>)
Runs its argument through L<Text::Balanced>'s C<extract_quotelike> method and
returns the extracted content with quotes removed. Dies if C<extract_quotelike>
can't find quoted string.
=cut
sub unquote {
my ( $self, $input ) = @_;
my $unquoted = (extract_quotelike($input))[5];
die "Unable to find quoted string in [$input]" unless defined $unquoted;
return $unquoted;
}
=item create_upstream_metadata
Populates F<debian/upstream/metadata> with information from F<META>.
=cut
sub create_upstream_metadata {
my $self = shift;
my $meta = $self->meta;
return unless %$meta;
require YAML::XS;
my %upstream;
$upstream{"Archive"} = 'CPAN';
$upstream{"Name"} = $meta->{name};
$upstream{"Contact"} = join( ', ', @{ $meta->{author} } );
# $upstream{"Homepage"} = $meta->{resources}->{homepage};
$upstream{"Bug-Database"} = $meta->{resources}->{bugtracker}->{web};
$upstream{"Bug-Submit"} = $meta->{resources}->{bugtracker}->{mailto};
$upstream{"Repository"} = $meta->{resources}->{repository}->{url};
$upstream{"Repository-Browse"} = $meta->{resources}->{repository}->{web};
foreach ( keys %upstream ) {
delete $upstream{$_} unless defined $upstream{$_};
}
my $dir = File::Spec->catdir( $self->main_dir, 'debian', 'upstream' );
mkdir($dir);
YAML::XS::DumpFile( File::Spec->catfile( $dir, 'metadata' ), \%upstream );
}
=back
=cut
sub _file_r {
my ( $self, $filename ) = @_;
my $fh = IO::File->new( $filename, 'r' )
or die "Cannot open $filename: $!\n";
return $fh;
}
sub _file_w {
my ( $self, $filename ) = @_;
my $fh = IO::File->new( $filename, 'w' )
or die "Cannot open $filename: $!\n";
return $fh;
}
=head1 COPYRIGHT & LICENSE
=over 4
=item Copyright (C) 2000, 2001 Paolo Molaro <lupus@debian.org>
=item Copyright (C) 2002, 2003, 2008 Ivan Kohler <ivan-debian@420.am>
=item Copyright (C) 2003, 2004 Marc 'HE' Brockschmidt <he@debian.org>
=item Copyright (C) 2005-2007 Gunnar Wolf <gwolf@debian.org>
=item Copyright (C) 2006 Frank Lichtenheld <djpig@debian.org>
=item Copyright (C) 2007-2015 gregor herrmann <gregoa@debian.org>
=item Copyright (C) 2007-2013 Damyan Ivanov <dmn@debian.org>
=item Copyright (C) 2008, Roberto C. Sanchez <roberto@connexer.com>
=item Copyright (C) 2009-2011, Salvatore Bonaccorso <carnil@debian.org>
=item Copyright (C) 2011, Nicholas Bamber <nicholas@periapt.co.uk>
=item Copyright (c) 2016, Nick Morrott <knowledgejunkie@gmail.com>
=back
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License version 2 as published by the Free
Software Foundation.
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, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301 USA.
=cut
1;
|