/usr/share/perl5/Inline.pm is in libinline-perl 0.53-1.
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 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 | package Inline;
use strict;
require 5.006;
$Inline::VERSION = '0.53';
$Inline::VERSION = eval $Inline::VERSION;
use AutoLoader 'AUTOLOAD';
use Inline::denter;
use Config;
use Carp;
use Cwd qw(abs_path cwd);
use File::Spec;
use File::Spec::Unix;
my %CONFIG = ();
my @DATA_OBJS = ();
my $INIT = 0;
my $version_requested = 0;
my $version_printed = 0;
my $untaint = 0;
my $safemode = 0;
$Inline::languages = undef; #needs to be global for AutoLoaded error messages
our $did = '_Inline'; # Default Inline Directory
# This is the config file written by create_config_file().
our $configuration_file = 'config-' . $Config::Config{'archname'} . '-' . $];
my %shortcuts =
(
NOCLEAN => [CLEAN_AFTER_BUILD => 0],
CLEAN => [CLEAN_BUILD_AREA => 1],
FORCE => [FORCE_BUILD => 1],
INFO => [PRINT_INFO => 1],
VERSION => [PRINT_VERSION => 1],
REPORTBUG => [REPORTBUG => 1],
UNTAINT => [UNTAINT => 1],
SAFE => [SAFEMODE => 1],
UNSAFE => [SAFEMODE => 0],
GLOBAL => [GLOBAL_LOAD => 1],
NOISY => [BUILD_NOISY => 1],
TIMERS => [BUILD_TIMERS => 1],
NOWARN => [WARNINGS => 0],
_INSTALL_ => [_INSTALL_ => 1],
SITE_INSTALL => undef, # No longer supported.
);
my $default_config =
{
NAME => '',
AUTONAME => -1,
VERSION => '',
DIRECTORY => '',
WITH => [],
USING => [],
CLEAN_AFTER_BUILD => 1,
CLEAN_BUILD_AREA => 0,
FORCE_BUILD => 0,
PRINT_INFO => 0,
PRINT_VERSION => 0,
REPORTBUG => 0,
UNTAINT => 0,
NO_UNTAINT_WARN => 0,
REWRITE_CONFIG_FILE => 0,
SAFEMODE => -1,
GLOBAL_LOAD => 0,
BUILD_NOISY => 0,
BUILD_TIMERS => 0,
WARNINGS => 1,
_INSTALL_ => 0,
_TESTING => 0,
};
sub UNTAINT {$untaint}
sub SAFEMODE {$safemode}
#==============================================================================
# This is where everything starts.
#==============================================================================
sub import {
local ($/, $") = ("\n", ' '); local ($\, $,);
my $o;
my ($pkg, $script) = caller;
# Not sure what this is for. Let's see what breaks.
# $pkg =~ s/^.*[\/\\]//;
my $class = shift;
if ($class ne 'Inline') {
croak M01_usage_use($class) if $class =~ /^Inline::/;
croak M02_usage();
}
$CONFIG{$pkg}{template} ||= $default_config;
return unless @_;
&create_config_file(), return 1 if $_[0] eq '_CONFIG_';
goto &maker_utils if $_[0] =~ /^(install|makedist|makeppd)$/i;
my $control = shift;
if ($control eq 'with') {
return handle_with($pkg, @_);
}
elsif ($control eq 'Config') {
return handle_global_config($pkg, @_);
}
elsif (exists $shortcuts{uc($control)}) {
handle_shortcuts($pkg, $control, @_);
$version_requested = $CONFIG{$pkg}{template}{PRINT_VERSION};
return;
}
elsif ($control =~ /^\S+$/ and $control !~ /\n/) {
my $language_id = $control;
my $option = shift || '';
my @config = @_;
my $next = 0;
for (@config) {
next if $next++ % 2;
croak M02_usage() if /[\s\n]/;
}
$o = bless {}, $class;
$o->{INLINE}{version} = $Inline::VERSION;
$o->{API}{pkg} = $pkg;
$o->{API}{script} = $script;
$o->{API}{language_id} = $language_id;
if ($option =~ /^(FILE|BELOW)$/ or
not $option and
defined $INC{File::Spec::Unix->catfile('Inline','Files.pm')} and
Inline::Files::get_filename($pkg)
) {
$o->read_inline_file;
$o->{CONFIG} = handle_language_config(@config);
}
elsif ($option eq 'DATA' or not $option) {
$o->{CONFIG} = handle_language_config(@config);
push @DATA_OBJS, $o;
return;
}
elsif ($option eq 'Config') {
$CONFIG{$pkg}{$language_id} = handle_language_config(@config);
return;
}
else {
$o->receive_code($option);
$o->{CONFIG} = handle_language_config(@config);
}
}
else {
croak M02_usage();
}
$o->glue;
}
#==============================================================================
# Run time version of import (public method)
#==============================================================================
sub bind {
local ($/, $") = ("\n", ' '); local ($\, $,);
my ($code, @config);
my $o;
my ($pkg, $script) = caller;
my $class = shift;
croak M03_usage_bind() unless $class eq 'Inline';
$CONFIG{$pkg}{template} ||= $default_config;
my $language_id = shift or croak M03_usage_bind();
croak M03_usage_bind()
unless ($language_id =~ /^\S+$/ and $language_id !~ /\n/);
$code = shift or croak M03_usage_bind();
@config = @_;
my $next = 0;
for (@config) {
next if $next++ % 2;
croak M03_usage_bind() if /[\s\n]/;
}
$o = bless {}, $class;
$o->{INLINE}{version} = $Inline::VERSION;
$o->{API}{pkg} = $pkg;
$o->{API}{script} = $script;
$o->{API}{language_id} = $language_id;
$o->receive_code($code);
$o->{CONFIG} = handle_language_config(@config);
$o->glue;
}
#==============================================================================
# Process delayed objects that don't have source code yet.
#==============================================================================
# This code is an ugly hack because of the fact that you can't use an
# INIT block at "run-time proper". So we kill the warning and tell users
# to use an Inline->init() call if they run into problems. (rare)
eval <<END;
no warnings;
\$INIT = \$INIT; # Needed by Sarathy's patch.
sub INIT {
\$INIT++;
&init;
}
END
sub init {
local ($/, $") = ("\n", ' '); local ($\, $,);
while (my $o = shift(@DATA_OBJS)) {
$o->read_DATA;
$o->glue;
}
}
sub END {
warn M51_unused_DATA() if @DATA_OBJS;
print_version() if $version_requested && not $version_printed;
}
#==============================================================================
# Print a small report about the version of Inline
#==============================================================================
sub print_version {
return if $version_printed++;
print STDERR <<END;
You are using Inline.pm version $Inline::VERSION
END
}
#==============================================================================
# Compile the source if needed and then dynaload the object
#==============================================================================
sub glue {
my $o = shift;
my ($pkg, $language_id) = @{$o->{API}}{qw(pkg language_id)};
my @config = (%{$CONFIG{$pkg}{template}},
%{$CONFIG{$pkg}{$language_id} || {}},
%{$o->{CONFIG} || {}},
);
@config = $o->check_config(@config);
$o->fold_options;
$o->check_installed;
$o->env_untaint if UNTAINT;
if (not $o->{INLINE}{object_ready}) {
$o->check_config_file; # Final DIRECTORY set here.
push @config, $o->with_configs;
my $language = $o->{API}{language};
croak M04_error_nocode($language_id) unless $o->{API}{code};
$o->check_module;
}
$o->env_untaint if UNTAINT;
$o->obj_untaint if UNTAINT;
print_version() if $version_requested;
$o->reportbug() if $o->{CONFIG}{REPORTBUG};
if (not $o->{INLINE}{object_ready}
or $o->{CONFIG}{PRINT_INFO}
) {
eval "require $o->{INLINE}{ILSM_module}";
croak M05_error_eval('glue', $@) if $@;
$o->push_overrides;
bless $o, $o->{INLINE}{ILSM_module};
$o->validate(@config);
}
else {
$o->{CONFIG} = {(%{$o->{CONFIG}}, @config)};
}
$o->print_info if $o->{CONFIG}{PRINT_INFO};
unless ($o->{INLINE}{object_ready} or
not length $o->{INLINE}{ILSM_suffix}) {
$o->build();
$o->write_inl_file() unless $o->{CONFIG}{_INSTALL_};
}
if ($o->{INLINE}{ILSM_suffix} ne 'so' and
$o->{INLINE}{ILSM_suffix} ne 'dll' and
$o->{INLINE}{ILSM_suffix} ne 'bundle' and
ref($o) eq 'Inline'
) {
eval "require $o->{INLINE}{ILSM_module}";
croak M05_error_eval('glue', $@) if $@;
$o->push_overrides;
bless $o, $o->{INLINE}{ILSM_module};
$o->validate(@config);
}
$o->load;
$o->pop_overrides;
}
#==============================================================================
# Set up the USING overrides
#==============================================================================
sub push_overrides {
my ($o) = @_;
my ($language_id) = $o->{API}{language_id};
my ($ilsm) = $o->{INLINE}{ILSM_module};
for (@{$o->{CONFIG}{USING}}) {
my $using_module = /^::/
? "Inline::$language_id$_"
: /::/
? $_
: "Inline::${language_id}::$_";
eval "require $using_module";
croak "Invalid module '$using_module' in USING list:\n$@" if $@;
my $register;
eval "\$register = $using_module->register";
croak "Invalid module '$using_module' in USING list:\n$@" if $@;
for my $override (@{$register->{overrides}}) {
no strict 'refs';
next if defined $o->{OVERRIDDEN}{$ilsm . "::$override"};
$o->{OVERRIDDEN}{$ilsm . "::$override"} =
\&{$ilsm . "::$override"};
{
no warnings 'redefine';
*{$ilsm . "::$override"} =
\&{$using_module . "::$override"};
}
}
}
}
#==============================================================================
# Restore the modules original methods
#==============================================================================
sub pop_overrides {
my $nowarn = $] >= 5.006 ? "no warnings 'redefine';" : '';
eval ($nowarn .
'my ($o) = @_;
for my $override (keys %{$o->{OVERRIDDEN}}) {
no strict "refs";
*{$override} = $o->{OVERRIDDEN}{$override};
}
delete $o->{OVERRIDDEN};')
}
#==============================================================================
# Get source from the DATA filehandle
#==============================================================================
my (%DATA, %DATA_read);
sub read_DATA {
require Socket;
my ($marker, $marker_tag);
my $o = shift;
my ($pkg, $language_id) = @{$o->{API}}{qw(pkg language_id)};
unless ($DATA_read{$pkg}++) {
no strict 'refs';
*Inline::DATA = *{$pkg . '::DATA'};
local ($/);
my ($CR, $LF) = (&Socket::CR, &Socket::LF);
(my $data = <Inline::DATA>) =~ s/$CR?$LF/\n/g;
@{$DATA{$pkg}} = split /(?m)^[ \t]{0,}(__\S+?__\n)/, $data;
shift @{$DATA{$pkg}} unless ($ {$DATA{$pkg}}[0] || '') =~ /__\S+?__\n/;
}
($marker, $o->{API}{code}) = splice @{$DATA{$pkg}}, 0, 2;
croak M08_no_DATA_source_code($language_id)
unless defined $marker;
($marker_tag = $marker) =~ s/__(\S+?)__\n/$1/;
croak M09_marker_mismatch($marker, $language_id)
unless $marker_tag eq $language_id;
}
#==============================================================================
# Validate and store the non language-specific config options
#==============================================================================
sub check_config {
my $o = shift;
my @others;
while (@_) {
my ($key, $value) = (shift, shift);
if (defined $default_config->{$key}) {
if ($key =~ /^(WITH|USING)$/) {
croak M10_usage_WITH_USING()
if (ref $value and ref $value ne 'ARRAY');
$value = [$value] unless ref $value;
$o->{CONFIG}{$key} = $value;
next;
}
$o->{CONFIG}{$key} = $value, next if not $value;
if ($key eq 'DIRECTORY') {
croak M11_usage_DIRECTORY($value) unless (-d $value);
$value = abs_path($value);
}
elsif ($key eq 'NAME') {
croak M12_usage_NAME($value)
unless $value =~ /^[a-zA-Z_](\w|::)*$/;
}
elsif ($key eq 'VERSION') {
croak M13_usage_VERSION($value) unless $value =~ /^\d\.\d\d*$/;
}
$o->{CONFIG}{$key} = $value;
}
else {
push @others, $key, $value;
}
}
return (@others);
}
#==============================================================================
# Set option defaults based on current option settings.
#==============================================================================
sub fold_options {
my $o = shift;
# The following small section of code seems, to me, to be unnecessary - which is the
# reason that I've commented it out. I've left it here (including its associated comments)
# in case it later becomes evident that there *is* good reason to include it. --sisyphus
#
## This bit tries to enable UNTAINT automatically if required when running the test suite.
# my $env_ha = $ENV{HARNESS_ACTIVE} || 0 ;
# my ($harness_active) = $env_ha =~ /(.*)/ ;
# if (($harness_active)&&(! $o->{CONFIG}{UNTAINT})){
# eval {
# require Scalar::Util;
# $o->{CONFIG}{UNTAINT} =
# (Scalar::Util::tainted(Cwd::cwd()) ? 1 : 0) ;
## Disable SAFEMODE in the test suite, we know what we are doing...
# $o->{CONFIG}{SAFEMODE} = 0 ;
# warn "\n-[tT] enabled for test suite.
#Automatically setting UNTAINT=1 and SAFEMODE=0.\n"
# unless $Inline::_TAINT_WARNING_ ;
# $Inline::_TAINT_WARNING_ = 1 ;
# } ;
# }
##
$untaint = $o->{CONFIG}{UNTAINT} || 0;
$safemode = (($o->{CONFIG}{SAFEMODE} == -1) ?
($untaint ? 1 : 0) :
$o->{CONFIG}{SAFEMODE}
);
if (UNTAINT and
SAFEMODE and
not $o->{CONFIG}{DIRECTORY}) {
croak M49_usage_unsafe(1) if ($< == 0 or $> == 0);
warn M49_usage_unsafe(0) if $^W;
}
if ($o->{CONFIG}{AUTONAME} == -1) {
$o->{CONFIG}{AUTONAME} = length($o->{CONFIG}{NAME}) ? 0 : 1;
}
$o->{API}{cleanup} =
($o->{CONFIG}{CLEAN_AFTER_BUILD} and not $o->{CONFIG}{REPORTBUG});
}
#==============================================================================
# Check if Inline extension is preinstalled
#==============================================================================
sub check_installed {
my $o = shift;
$o->{INLINE}{object_ready} = 0;
unless ($o->{API}{code} =~ /^[A-Fa-f0-9]{32}$/) {
require Digest::MD5;
$o->{INLINE}{md5} = Digest::MD5::md5_hex($o->{API}{code});
}
else {
$o->{INLINE}{md5} = $o->{API}{code};
}
return if $o->{CONFIG}{_INSTALL_};
return unless $o->{CONFIG}{VERSION};
croak M26_error_version_without_name()
unless $o->{CONFIG}{NAME};
my @pkgparts = split(/::/, $o->{API}{pkg});
my $realname = File::Spec->catfile(@pkgparts) . '.pm';
my $realname_unix = File::Spec::Unix->catfile(@pkgparts) . '.pm';
my $realpath = $INC{$realname_unix}
or croak M27_module_not_indexed($realname_unix);
my ($volume,$dir,$file) = File::Spec->splitpath($realpath);
my @dirparts = File::Spec->splitdir($dir);
pop @dirparts unless $dirparts[-1];
push @dirparts, $file;
my @endparts = splice(@dirparts, 0 - @pkgparts);
$dirparts[-1] = 'arch'
if $dirparts[-2] eq 'blib' && $dirparts[-1] eq 'lib';
File::Spec->catfile(@endparts) eq $realname
or croak M28_error_grokking_path($realpath);
$realpath =
File::Spec->catpath($volume,File::Spec->catdir(@dirparts),"");
$o->{API}{version} = $o->{CONFIG}{VERSION};
$o->{API}{module} = $o->{CONFIG}{NAME};
my @modparts = split(/::/,$o->{API}{module});
$o->{API}{modfname} = $modparts[-1];
$o->{API}{modpname} = File::Spec->catdir(@modparts);
my $suffix = $Config{dlext};
my $obj = File::Spec->catfile($realpath,'auto',$o->{API}{modpname},
"$o->{API}{modfname}.$suffix");
croak M30_error_no_obj($o->{CONFIG}{NAME}, $o->{API}{pkg},
$realpath) unless -f $obj;
@{$o->{CONFIG}}{qw( PRINT_INFO
REPORTBUG
FORCE_BUILD
_INSTALL_
)} = (0, 0, 0, 0);
$o->{install_lib} = $realpath;
$o->{INLINE}{ILSM_type} = 'compiled';
$o->{INLINE}{ILSM_module} = 'Inline::C';
$o->{INLINE}{ILSM_suffix} = $suffix;
$o->{INLINE}{object_ready} = 1;
}
#==============================================================================
# Dynamically load the object module
#==============================================================================
sub load {
my $o = shift;
if ($o->{CONFIG}{_INSTALL_}) {
my $inline = "$o->{API}{modfname}.inl";
open INLINE, "> $inline"
or croak M24_open_for_output_failed($inline);
print INLINE "*** AUTOGENERATED by Inline.pm ***\n\n";
print INLINE "This file satisfies the make dependency for ";
print INLINE "$o->{API}{modfname}.pm\n";
close INLINE;
return;
}
my ($pkg, $module) = @{$o->{API}}{qw(pkg module)};
croak M42_usage_loader() unless $o->{INLINE}{ILSM_type} eq 'compiled';
require DynaLoader;
@Inline::ISA = qw(DynaLoader);
my $global = $o->{CONFIG}{GLOBAL_LOAD} ? '0x01' : '0x00';
my $version = $o->{API}{version} || '0.00';
eval <<END;
package $pkg;
push \@$ {pkg}::ISA, qw($module)
unless \$module eq "$pkg";
local \$$ {module}::VERSION = '$version';
package $module;
push \@$ {module}::ISA, qw(Exporter DynaLoader);
sub dl_load_flags { $global }
${module}::->bootstrap;
END
croak M43_error_bootstrap($module, $@) if $@;
}
#==============================================================================
# Process the config options that apply to all Inline sections
#==============================================================================
sub handle_global_config {
my $pkg = shift;
while (@_) {
my ($key, $value) = (shift, shift);
croak M02_usage() if $key =~ /[\s\n]/;
$key = $value if $key =~ /^(ENABLE|DISABLE)$/;
croak M47_invalid_config_option($key)
unless defined $default_config->{$key};
if ($key eq 'ENABLE') {
$CONFIG{$pkg}{template}{$value} = 1;
}
elsif ($key eq 'DISABLE') {
$CONFIG{$pkg}{template}{$value} = 0;
}
else {
$CONFIG{$pkg}{template}{$key} = $value;
}
}
}
#==============================================================================
# Process the config options that apply to a particular language
#==============================================================================
sub handle_language_config {
my @values;
while (@_) {
my ($key, $value) = (shift, shift);
croak M02_usage() if $key =~ /[\s\n]/;
if ($key eq 'ENABLE') {
push @values, $value, 1;
}
elsif ($key eq 'DISABLE') {
push @values, $value, 0;
}
else {
push @values, $key, $value;
}
}
return {@values};
}
#==============================================================================
# Validate and store shortcut config options
#==============================================================================
sub handle_shortcuts {
my $pkg = shift;
for my $option (@_) {
my $OPTION = uc($option);
if ($OPTION eq 'SITE_INSTALL') {
croak M58_site_install();
}
elsif ($shortcuts{$OPTION}) {
my ($method, $arg) = @{$shortcuts{$OPTION}};
$CONFIG{$pkg}{template}{$method} = $arg;
}
else {
croak M48_usage_shortcuts($option);
}
}
}
#==============================================================================
# Process the with command
#==============================================================================
sub handle_with {
my $pkg = shift;
croak M45_usage_with() unless @_;
for (@_) {
croak M02_usage() unless /^[\w:]+$/;
eval "require $_;";
croak M46_usage_with_bad($_) . $@ if $@;
push @{$CONFIG{$pkg}{template}{WITH}}, $_;
}
}
#==============================================================================
# Perform cleanup duties
#==============================================================================
sub DESTROY {
my $o = shift;
$o->clean_build if $o->{CONFIG}{CLEAN_BUILD_AREA};
}
# Comment out the next 2 lines to stop autoloading of subroutines (testing)
1;
__END__
#==============================================================================
# Get the source code
#==============================================================================
sub receive_code {
my $o = shift;
my $code = shift;
croak M02_usage() unless (defined $code and $code);
if (ref $code eq 'CODE') {
$o->{API}{code} = &$code;
}
elsif (ref $code eq 'ARRAY') {
$o->{API}{code} = join '', @$code;
}
elsif ($code =~ m|[/\\:]| and
$code =~ m|^[/\\:\w.\-\ \$\[\]<>]+$|) {
if (-f $code) {
local ($/, *CODE);
open CODE, "< $code" or croak M06_code_file_failed_open($code);
$o->{API}{code} = <CODE>;
}
else {
croak M07_code_file_does_not_exist($code);
}
}
else {
$o->{API}{code} = $code;
}
}
#==============================================================================
# Get the source code from an Inline::Files filehandle
#==============================================================================
sub read_inline_file {
my $o = shift;
my ($lang, $pkg) = @{$o->{API}}{qw(language_id pkg)};
my $langfile = uc($lang);
croak M59_bad_inline_file($lang) unless $langfile =~ /^[A-Z]\w*$/;
croak M60_no_inline_files()
unless (defined $INC{File::Spec::Unix->catfile("Inline","Files.pm")} and
$Inline::Files::VERSION =~ /^\d\.\d\d$/ and
$Inline::Files::VERSION ge '0.51');
croak M61_not_parsed() unless $lang = Inline::Files::get_filename($pkg);
{
no strict 'refs';
local $/;
$Inline::FILE = \*{"${pkg}::$langfile"};
# open $Inline::FILE;
$o->{API}{code} = <$Inline::FILE>;
# close $Inline::FILE;
}
}
#==============================================================================
# Read the cached config file from the Inline directory. This will indicate
# whether the Language code is valid or not.
#==============================================================================
sub check_config_file {
my ($DIRECTORY, %config);
my $o = shift;
croak M14_usage_Config() if %main::Inline::Config::;
croak M63_no_source($o->{API}{pkg})
if $o->{INLINE}{md5} eq $o->{API}{code};
# First make sure we have the DIRECTORY
if ($o->{CONFIG}{_INSTALL_}) {
croak M15_usage_install_directory()
if $o->{CONFIG}{DIRECTORY};
my $cwd = Cwd::cwd();
$DIRECTORY =
$o->{INLINE}{DIRECTORY} = File::Spec->catdir($cwd, $did);
if (not -d $DIRECTORY) {
_mkdir($DIRECTORY, 0777)
or croak M16_DIRECTORY_mkdir_failed($DIRECTORY);
}
}
else {
$DIRECTORY = $o->{INLINE}{DIRECTORY} =
$o->{CONFIG}{DIRECTORY} || $o->find_temp_dir;
}
if($o->{CONFIG}{REWRITE_CONFIG_FILE}) {
if(-e File::Spec->catfile($DIRECTORY, $configuration_file)) {
my $unlink = unlink(File::Spec->catfile($DIRECTORY, $configuration_file));
if(!$unlink) {warn "REWRITE_CONFIG_FILE is set, but removal of config file failed"}
else {warn "config file removal successful\n" if $o->{CONFIG}{_TESTING}}
}
}
my $load_cfg = sub {
$o->create_config_file($DIRECTORY)
if not -e File::Spec->catfile($DIRECTORY, $configuration_file);
open CONFIG, "< ".File::Spec->catfile($DIRECTORY,$configuration_file)
or croak M17_config_open_failed($DIRECTORY);
my $config = join '', <CONFIG>;
close CONFIG;
unless($config =~ /^version :/) {
warn "\$load_cfg sub: \$config: *${config}*\n";
croak M62_invalid_config_file(File::Spec->catfile($DIRECTORY,$configuration_file));
}
if(UNTAINT) {
warn "In Inline::check_config_file(): Blindly untainting Inline configuration file information.\n"
unless $o->{CONFIG}{NO_UNTAINT_WARN};
($config) = $config =~ /(.*)/s;
}
%config = Inline::denter->new()->undent($config);
} ;
$load_cfg->() ;
if (! defined $config{languages}->{$o->{API}{language_id}}){
my $unlink = unlink(File::Spec->catfile($DIRECTORY, $configuration_file));
if(!$unlink) {warn "Failed to remove config file"}
else {warn "config file removed\n" if $o->{CONFIG}{_TESTING}}
$load_cfg->() ;
}
$Inline::languages = $config{languages};
{
no warnings ('numeric'); # These warnings were a pain with devel releases.
# If there's a problem with the version number, the
# error message will output $config{version} anyway.
croak M18_error_old_version($config{version}, $DIRECTORY)
unless (defined $config{version} and
$config{version} =~ /TRIAL/ or
$config{version} >= 0.40);
} # numeric warnings re-enabled.
croak M19_usage_language($o->{API}{language_id}, $DIRECTORY)
unless defined $config{languages}->{$o->{API}{language_id}};
$o->{API}{language} = $config{languages}->{$o->{API}{language_id}};
if ($o->{API}{language} ne $o->{API}{language_id}) {
if (defined $o->{$o->{API}{language_id}}) {
$o->{$o->{API}{language}} = $o->{$o->{API}{language_id}};
delete $o->{$o->{API}{language_id}};
}
}
$o->{INLINE}{ILSM_type} = $config{types}->{$o->{API}{language}};
$o->{INLINE}{ILSM_module} = $config{modules}->{$o->{API}{language}};
$o->{INLINE}{ILSM_suffix} = $config{suffixes}->{$o->{API}{language}};
}
#==============================================================================
# Auto-detect installed Inline language support modules
#==============================================================================
sub create_config_file {
my ($o, $dir) = @_;
# This subroutine actually fires off another instance of perl.
# with arguments that make this routine get called again.
# That way the queried modules don't stay loaded.
if (defined $o) {
($dir) = $dir =~ /(.*)/s if UNTAINT;
my $perl = $Config{perlpath};
$perl = $^X unless -f $perl;
($perl) = $perl =~ /(.*)/s if UNTAINT;
local $ENV{PERL5LIB} if defined $ENV{PERL5LIB};
local $ENV{PERL5OPT} if defined $ENV{PERL5OPT};
my $inline = $INC{'Inline.pm'};
$inline ||= File::Spec->curdir();
my($v,$d,$f) = File::Spec->splitpath($inline);
$f = "" if $f eq 'Inline.pm';
$inline = File::Spec->catpath($v,$d,$f);
# P::RD may be in a different PERL5LIB dir to Inline (as happens with cpan smokers).
# Therefore we need to grep for it - otherwise, if P::RD *is* in a different PERL5LIB
# directory the ensuing rebuilt @INC will not include that directory and attempts to use
# Inline::CPP (and perhaps other Inline modules) will fail because P::RD isn't found.
my @_inc = map { "-I$_" }
($inline,
grep {(-d File::Spec->catdir($_,"Inline") or -d File::Spec->catdir($_,"auto","Inline") or -e File::Spec->catdir($_,"Parse/RecDescent.pm"))} @INC);
system $perl, @_inc, "-MInline=_CONFIG_", "-e1", "$dir"
and croak M20_config_creation_failed($dir);
return;
}
my ($lib, $mod, $register, %checked,
%languages, %types, %modules, %suffixes);
LIB:
for my $lib (@INC) {
next unless -d File::Spec->catdir($lib,"Inline");
opendir LIB, File::Spec->catdir($lib,"Inline")
or warn(M21_opendir_failed(File::Spec->catdir($lib,"Inline"))), next;
while ($mod = readdir(LIB)) {
next unless $mod =~ /\.pm$/;
$mod =~ s/\.pm$//;
next LIB if ($checked{$mod}++);
if ($mod eq 'Config') { # Skip Inline::Config
warn M14_usage_Config();
next;
}
next if $mod =~ /^(MakeMaker|denter|messages)$/;
eval "require Inline::$mod;";
warn($@), next if $@;
eval "\$register=&Inline::${mod}::register";
next if $@;
my $language = ($register->{language})
or warn(M22_usage_register($mod)), next;
for (@{$register->{aliases}}) {
warn(M23_usage_alias_used($mod, $_, $languages{$_})), next
if defined $languages{$_};
$languages{$_} = $language;
}
$languages{$language} = $language;
$types{$language} = $register->{type};
$modules{$language} = "Inline::$mod";
$suffixes{$language} = $register->{suffix};
}
closedir LIB;
}
my $file = File::Spec->catfile($ARGV[0], $configuration_file);
open CONFIG, "> $file" or croak M24_open_for_output_failed($file);
flock(CONFIG, LOCK_EX);
print CONFIG Inline::denter->new()
->indent(*version => $Inline::VERSION,
*languages => \%languages,
*types => \%types,
*modules => \%modules,
*suffixes => \%suffixes,
);
flock(CONFIG, LOCK_UN);
close CONFIG;
exit 0;
}
#==============================================================================
# Check to see if code has already been compiled
#==============================================================================
sub check_module {
my ($module, $module2);
my $o = shift;
return $o->install if $o->{CONFIG}{_INSTALL_};
if ($o->{CONFIG}{NAME}) {
$module = $o->{CONFIG}{NAME};
}
elsif ($o->{API}{pkg} eq 'main') {
$module = $o->{API}{script};
my($v,$d,$file) = File::Spec->splitpath($module);
$module = $file;
$module =~ s|\W|_|g;
$module =~ s|^_+||;
$module =~ s|_+$||;
$module = 'FOO' if $module =~ /^_*$/;
$module = "_$module" if $module =~ /^\d/;
}
else {
$module = $o->{API}{pkg};
}
$o->{API}{suffix} = $o->{INLINE}{ILSM_suffix};
$o->{API}{directory} = $o->{INLINE}{DIRECTORY};
my $auto_level = 2;
while ($auto_level <= 5) {
if ($o->{CONFIG}{AUTONAME}) {
$module2 =
$module . '_' . substr($o->{INLINE}{md5}, 0, 2 + $auto_level);
$auto_level++;
} else {
$module2 = $module;
$auto_level = 6; # Don't loop on non-autoname objects
}
$o->{API}{module} = $module2;
my @modparts = split /::/, $module2;
$o->{API}{modfname} = $modparts[-1];
$o->{API}{modpname} = File::Spec->catdir(@modparts);
$o->{API}{build_dir} =
File::Spec->catdir($o->{INLINE}{DIRECTORY},
'build',$o->{API}{modpname});
$o->{API}{install_lib} =
File::Spec->catdir($o->{INLINE}{DIRECTORY}, 'lib');
my $inl = File::Spec->catfile($o->{API}{install_lib},"auto",
$o->{API}{modpname},"$o->{API}{modfname}.inl");
$o->{API}{location} =
File::Spec->catfile($o->{API}{install_lib},"auto",$o->{API}{modpname},
"$o->{API}{modfname}.$o->{INLINE}{ILSM_suffix}");
last unless -f $inl;
my %inl;
{ local ($/, *INL);
open INL, $inl or croak M31_inline_open_failed($inl);
%inl = Inline::denter->new()->undent(<INL>);
}
next unless ($o->{INLINE}{md5} eq $inl{md5});
next unless ($inl{inline_version} ge '0.40');
next unless ($inl{Config}{version} eq $Config::Config{version});
next unless ($inl{Config}{archname} eq $Config::Config{archname});
unless (-f $o->{API}{location}) {
warn <<END if $^W;
Missing object file: $o->{API}{location}
For Inline file: $inl
END
next;
}
$o->{INLINE}{object_ready} = 1 unless $o->{CONFIG}{FORCE_BUILD};
last;
}
unshift @::INC, $o->{API}{install_lib};
}
#==============================================================================
# Set things up so that the extension gets installed into the blib/arch.
# Then 'make install' will do the right thing.
#==============================================================================
sub install {
my ($module, $DIRECTORY);
my $o = shift;
croak M64_install_not_c($o->{API}{language_id})
unless uc($o->{API}{language_id}) =~ /^(C|CPP|Java|Python|Ruby|Lisp|Pdlpp)$/ ;
croak M36_usage_install_main()
if ($o->{API}{pkg} eq 'main');
croak M37_usage_install_auto()
if $o->{CONFIG}{AUTONAME};
croak M38_usage_install_name()
unless $o->{CONFIG}{NAME};
croak M39_usage_install_version()
unless $o->{CONFIG}{VERSION};
croak M40_usage_install_badname($o->{CONFIG}{NAME}, $o->{API}{pkg})
unless $o->{CONFIG}{NAME} eq $o->{API}{pkg};
# $o->{CONFIG}{NAME} =~ /^$o->{API}{pkg}::\w(\w|::)+$/
# );
my ($mod_name, $mod_ver, $ext_name, $ext_ver) =
($o->{API}{pkg}, $ARGV[0], @{$o->{CONFIG}}{qw(NAME VERSION)});
croak M41_usage_install_version_mismatch($mod_name, $mod_ver,
$ext_name, $ext_ver)
unless ($mod_ver eq $ext_ver);
$o->{INLINE}{INST_ARCHLIB} = $ARGV[1];
$o->{API}{version} = $o->{CONFIG}{VERSION};
$o->{API}{module} = $o->{CONFIG}{NAME};
my @modparts = split(/::/,$o->{API}{module});
$o->{API}{modfname} = $modparts[-1];
$o->{API}{modpname} = File::Spec->catdir(@modparts);
$o->{API}{suffix} = $o->{INLINE}{ILSM_suffix};
$o->{API}{build_dir} = File::Spec->catdir($o->{INLINE}{DIRECTORY},'build',
$o->{API}{modpname});
$o->{API}{directory} = $o->{INLINE}{DIRECTORY};
my $cwd = Cwd::cwd();
$o->{API}{install_lib} =
File::Spec->catdir($cwd,$o->{INLINE}{INST_ARCHLIB});
$o->{API}{location} =
File::Spec->catfile($o->{API}{install_lib},"auto",$o->{API}{modpname},
"$o->{API}{modfname}.$o->{INLINE}{ILSM_suffix}");
unshift @::INC, $o->{API}{install_lib};
$o->{INLINE}{object_ready} = 0;
}
#==============================================================================
# Create the .inl file for an object
#==============================================================================
sub write_inl_file {
my $o = shift;
my $inl =
File::Spec->catfile($o->{API}{install_lib},"auto",$o->{API}{modpname},
"$o->{API}{modfname}.inl");
open INL, "> $inl"
or croak "Can't create Inline validation file $inl: $!";
my $apiversion = $Config{apiversion} || $Config{xs_apiversion};
print INL Inline::denter->new()
->indent(*md5, $o->{INLINE}{md5},
*name, $o->{API}{module},
*version, $o->{CONFIG}{VERSION},
*language, $o->{API}{language},
*language_id, $o->{API}{language_id},
*installed, $o->{CONFIG}{_INSTALL_},
*date_compiled, scalar localtime,
*inline_version, $Inline::VERSION,
*ILSM, { map {($_, $o->{INLINE}{"ILSM_$_"})}
(qw( module suffix type ))
},
*Config, { (map {($_,$Config{$_})}
(qw( archname osname osvers
cc ccflags ld so version
))),
(apiversion => $apiversion),
},
);
close INL;
}
#==============================================================================
# Get config hints
#==============================================================================
sub with_configs {
my $o = shift;
my @configs;
for my $mod (@{$o->{CONFIG}{WITH}}) {
my $ref = eval {
no strict 'refs';
&{$mod . "::Inline"}($o->{API}{language});
};
croak M25_no_WITH_support($mod, $@) if $@;
push @configs, %$ref;
}
return @configs;
}
#==============================================================================
# Blindly untaint tainted fields in %ENV.
#==============================================================================
sub env_untaint {
my $o = shift;
warn "In Inline::env_untaint() : Blindly untainting tainted fields in %ENV.\n" unless $o->{CONFIG}{NO_UNTAINT_WARN};
{
no warnings ('uninitialized'); # In case $ENV{$_} is set to undef.
for (keys %ENV) {
($ENV{$_}) = $ENV{$_} =~ /(.*)/;
}
}
$ENV{PATH} = $^O eq 'MSWin32' ?
join ';', grep {not /^\./ and -d $_
} split /;/, $ENV{PATH}
:
join ':', grep {not /^\./ and -d $_ and
not ((stat($_))[2] & 0022)
} split /:/, $ENV{PATH};
map {($_) = /(.*)/} @INC;
}
#==============================================================================
# Blindly untaint tainted fields in Inline object.
#==============================================================================
sub obj_untaint {
my $o = shift;
warn "In Inline::obj_untaint() : Blindly untainting tainted fields in Inline object.\n" unless $o->{CONFIG}{NO_UNTAINT_WARN};
($o->{INLINE}{ILSM_module}) = $o->{INLINE}{ILSM_module} =~ /(.*)/;
($o->{API}{build_dir}) = $o->{API}{build_dir} =~ /(.*)/;
($o->{CONFIG}{DIRECTORY}) = $o->{CONFIG}{DIRECTORY} =~ /(.*)/;
($o->{API}{install_lib}) = $o->{API}{install_lib} =~ /(.*)/;
($o->{API}{modpname}) = $o->{API}{modpname} =~ /(.*)/;
($o->{API}{modfname}) = $o->{API}{modfname} =~ /(.*)/;
($o->{API}{language}) = $o->{API}{language} =~ /(.*)/;
($o->{API}{pkg}) = $o->{API}{pkg} =~ /(.*)/;
($o->{API}{module}) = $o->{API}{module} =~ /(.*)/;
}
#==============================================================================
# Clean the build directory from previous builds
#==============================================================================
sub clean_build {
use strict;
my ($prefix, $dir);
my $o = shift;
$prefix = $o->{INLINE}{DIRECTORY};
opendir(BUILD, $prefix)
or croak "Can't open build directory: $prefix for cleanup $!\n";
while ($dir = readdir(BUILD)) {
my $maybedir = File::Spec->catdir($prefix,$dir);
if (($maybedir and -d $maybedir) and ($dir =~ /\w{36,}/)) {
$o->rmpath($prefix,$dir);
}
}
close BUILD;
}
#==============================================================================
# Apply a list of filters to the source code
#==============================================================================
sub filter {
my $o = shift;
my $new_code = $o->{API}{code};
for (@_) {
croak M52_invalid_filter($_) unless ref;
if (ref eq 'CODE') {
$new_code = $_->($new_code);
}
else {
$new_code = $_->filter($o, $new_code);
}
}
return $new_code;
}
#==============================================================================
# User wants to report a bug
#==============================================================================
sub reportbug {
use strict;
my $o = shift;
return if $o->{INLINE}{reportbug_handled}++;
print STDERR <<END;
<-----------------------REPORTBUG Section------------------------------------->
REPORTBUG mode in effect.
Your Inline $o->{API}{language_id} code will be processed in the build directory:
$o->{API}{build_dir}
A perl-readable bug report including your perl configuration and run-time
diagnostics will also be generated in the build directory.
When the program finishes please bundle up the above build directory with:
tar czf Inline.REPORTBUG.tar.gz $o->{API}{build_dir}
and send "Inline.REPORTBUG.tar.gz" as an email attachment to the author
of the offending Inline::* module with the subject line:
REPORTBUG: Inline.pm
Include in the email, a description of the problem and anything else that
you think might be helpful. Patches are welcome! :-\)
<-----------------------End of REPORTBUG Section------------------------------>
END
my %versions;
{
no strict 'refs';
%versions = map {eval "use $_();"; ($_, $ {$_ . '::VERSION'})}
qw (Digest::MD5 Parse::RecDescent
ExtUtils::MakeMaker File::Path FindBin
Inline
);
}
$o->mkpath($o->{API}{build_dir});
open REPORTBUG, "> ".File::Spec->catfile($o->{API}{build_dir},"REPORTBUG")
or croak M24_open_for_output_failed
(File::Spec->catfile($o->{API}{build_dir},"REPORTBUG"));
%Inline::REPORTBUG_Inline_Object = ();
%Inline::REPORTBUG_Perl_Config = ();
%Inline::REPORTBUG_Module_Versions = ();
print REPORTBUG Inline::denter->new()
->indent(*REPORTBUG_Inline_Object, $o,
*REPORTBUG_Perl_Config, \%Config::Config,
*REPORTBUG_Module_Versions, \%versions,
);
close REPORTBUG;
}
#==============================================================================
# Print a small report if PRINT_INFO option is set.
#==============================================================================
sub print_info {
use strict;
my $o = shift;
print STDERR <<END;
<-----------------------Information Section----------------------------------->
Information about the processing of your Inline $o->{API}{language_id} code:
END
print STDERR <<END if ($o->{INLINE}{object_ready});
Your module is already compiled. It is located at:
$o->{API}{location}
END
print STDERR <<END if ($o->{INLINE}{object_ready} and $o->{CONFIG}{FORCE_BUILD});
But the FORCE_BUILD option is set, so your code will be recompiled.
I\'ll use this build directory:
$o->{API}{build_dir}
and I\'ll install the executable as:
$o->{API}{location}
END
print STDERR <<END if (not $o->{INLINE}{object_ready});
Your source code needs to be compiled. I\'ll use this build directory:
$o->{API}{build_dir}
and I\'ll install the executable as:
$o->{API}{location}
END
eval {
print STDERR $o->info;
};
print $@ if $@;
print STDERR <<END;
<-----------------------End of Information Section---------------------------->
END
}
#==============================================================================
# Hand off this invokation to Inline::MakeMaker
#==============================================================================
sub maker_utils {
require Inline::MakeMaker;
goto &Inline::MakeMaker::utils;
}
#==============================================================================
# Utility subroutines
#==============================================================================
#==============================================================================
# Make a path
#==============================================================================
sub mkpath {
use strict;
my ($o, $mkpath) = @_;
my($volume,$dirs,$nofile) = File::Spec->splitpath($mkpath,1);
my @parts = File::Spec->splitdir($dirs);
my @done;
foreach (@parts){
push(@done,$_);
my $path = File::Spec->catpath($volume,File::Spec->catdir(@done),"");
-d $path || _mkdir($path, 0777);
}
croak M53_mkdir_failed($mkpath)
unless -d $mkpath;
}
#==============================================================================
# Nuke a path (nicely)
#==============================================================================
sub rmpath {
use strict;
my ($o, $prefix, $rmpath) = @_;
# Nuke the target directory
_rmtree(File::Spec->catdir($prefix ? ($prefix,$rmpath) : ($rmpath)));
# Remove any empty directories underneath the requested one
my @parts = File::Spec->splitdir($rmpath);
while (@parts){
$rmpath = File::Spec->catdir($prefix ? ($prefix,@parts) : @parts);
($rmpath) = $rmpath =~ /(.*)/ if UNTAINT;
rmdir $rmpath
or last; # rmdir failed because dir was not empty
pop @parts;
}
}
sub _rmtree {
my($roots) = @_;
$roots = [$roots] unless ref $roots;
my($root);
foreach $root (@{$roots}) {
if ( -d $root ) {
my(@names,@paths);
if (opendir MYDIR, $root) {
@names = readdir MYDIR;
closedir MYDIR;
}
else {
croak M21_opendir_failed($root);
}
my $dot = File::Spec->curdir();
my $dotdot = File::Spec->updir();
foreach my $name (@names) {
next if $name eq $dot or $name eq $dotdot;
my $maybefile = File::Spec->catfile($root,$name);
push(@paths,$maybefile),next if $maybefile and -f $maybefile;
push(@paths,File::Spec->catdir($root,$name));
}
_rmtree(\@paths);
($root) = $root =~ /(.*)/ if UNTAINT;
rmdir($root) or croak M54_rmdir_failed($root);
}
else {
($root) = $root =~ /(.*)/ if UNTAINT;
unlink($root) or croak M55_unlink_failed($root);
}
}
}
#==============================================================================
# Find the 'Inline' directory to use.
#==============================================================================
my $TEMP_DIR;
sub find_temp_dir {
return $TEMP_DIR if $TEMP_DIR;
my ($temp_dir, $home, $bin, $cwd, $env);
$temp_dir = '';
$env = $ENV{PERL_INLINE_DIRECTORY} || '';
$home = $ENV{HOME} ? abs_path($ENV{HOME}) : '';
if ($env and
-d $env and
-w $env) {
$temp_dir = $env;
}
elsif ($cwd = abs_path('.') and
$cwd ne $home and
-d File::Spec->catdir($cwd,".Inline") and
-w File::Spec->catdir($cwd,".Inline")) {
$temp_dir = File::Spec->catdir($cwd,".Inline");
}
else {
require FindBin ;
if ($bin = $FindBin::Bin and
-d File::Spec->catdir($bin,".Inline") and
-w File::Spec->catdir($bin,".Inline")) {
$temp_dir = File::Spec->catdir($bin,".Inline");
}
elsif ($home and
-d File::Spec->catdir($home,".Inline") and
-w File::Spec->catdir($home,".Inline")) {
$temp_dir = File::Spec->catdir($home,".Inline");
}
elsif (defined $cwd and $cwd and
-d File::Spec->catdir($cwd, $did) and
-w File::Spec->catdir($cwd, $did)) {
$temp_dir = File::Spec->catdir($cwd, $did);
}
elsif (defined $bin and $bin and
-d File::Spec->catdir($bin, $did) and
-w File::Spec->catdir($bin, $did)) {
$temp_dir = File::Spec->catdir($bin, $did);
}
elsif (defined $cwd and $cwd and
-d $cwd and
-w $cwd and
_mkdir(File::Spec->catdir($cwd, $did), 0777)) {
$temp_dir = File::Spec->catdir($cwd, $did);
}
elsif (defined $bin and $bin and
-d $bin and
-w $bin and
_mkdir(File::Spec->catdir($bin, $did), 0777)) {
$temp_dir = File::Spec->catdir($bin, $did);
}
}
croak M56_no_DIRECTORY_found()
unless $temp_dir;
return $TEMP_DIR = abs_path($temp_dir);
}
sub _mkdir {
my $dir = shift;
my $mode = shift || 0777;
($dir) = ($dir =~ /(.*)/) if UNTAINT;
$dir =~ s|[/\\:]$||;
return mkdir($dir, $mode);
}
# Comment out the next 2 lines to stop autoloading of messages (for testing)
#1;
#__END__
#==============================================================================
# Error messages are autoloaded
#==============================================================================
sub M01_usage_use {
my ($module) = @_;
return <<END;
It is invalid to use '$module' directly. Please consult the Inline
documentation for more information.
END
}
sub M02_usage {
my $usage = <<END;
Invalid usage of Inline module. Valid usages are:
use Inline;
use Inline language => "source-string", config-pair-list;
use Inline language => "source-file", config-pair-list;
use Inline language => [source-line-list], config-pair-list;
use Inline language => 'DATA', config-pair-list;
use Inline language => 'Config', config-pair-list;
use Inline Config => config-pair-list;
use Inline with => module-list;
use Inline shortcut-list;
END
# This is broken ????????????????????????????????????????????????????
$usage .= <<END if defined $Inline::languages;
Supported languages:
${\ join(', ', sort keys %$Inline::languages)}
END
return $usage;
}
sub M03_usage_bind {
my $usage = <<END;
Invalid usage of the Inline->bind() function. Valid usages are:
Inline->bind(language => "source-string", config-pair-list);
Inline->bind(language => "source-file", config-pair-list);
Inline->bind(language => [source-line-list], config-pair-list);
END
$usage .= <<END if defined $Inline::languages;
Supported languages:
${\ join(', ', sort keys %$Inline::languages)}
END
return $usage;
}
sub M04_error_nocode {
my ($language) = @_;
return <<END;
No $language source code found for Inline.
END
}
sub M05_error_eval {
my ($subroutine, $msg) = @_;
return <<END;
An eval() failed in Inline::$subroutine:
$msg
END
}
sub M06_code_file_failed_open {
my ($file) = @_;
return <<END;
Couldn't open Inline code file '$file':
$!
END
#'
}
sub M07_code_file_does_not_exist {
my ($file) = @_;
return <<END;
Inline assumes '$file' is a filename,
and that file does not exist.
END
}
sub M08_no_DATA_source_code {
my ($lang) = @_;
return <<END;
No source code in DATA section for Inline '$lang' section.
END
}
sub M09_marker_mismatch {
my ($marker, $lang) = @_;
return <<END;
Marker '$marker' does not match Inline '$lang' section.
END
}
sub M10_usage_WITH_USING {
return <<END;
Config option WITH or USING must be a module name or an array ref
of module names.
END
}
sub M11_usage_DIRECTORY {
my ($value) = @_;
return <<END;
Invalid value '$value' for config option DIRECTORY
END
}
sub M12_usage_NAME {
my ($name) = @_;
return <<END;
Invalid value for NAME config option: '$name'
END
}
sub M13_usage_VERSION {
my ($version) = @_;
return <<END;
Invalid value for VERSION config option: '$version'
Must be of the form '#.##'.
(Should also be specified as a string rather than a floating point number)
END
}
sub M14_usage_Config {
return <<END;
As of Inline v0.30, use of the Inline::Config module is no longer supported
or allowed. If Inline::Config exists on your system, it can be removed. See
the Inline documentation for information on how to configure Inline.
(You should find it much more straightforward than Inline::Config :-)
END
}
sub M15_usage_install_directory {
return <<END;
Can't use the DIRECTORY option when installing an Inline extension module.
END
#'
}
sub M16_DIRECTORY_mkdir_failed {
my ($dir) = @_;
return <<END;
Can't mkdir $dir to build Inline code.
END
#'
}
sub M17_config_open_failed {
my ($dir) = @_;
my $file = File::Spec->catfile(${dir}, $configuration_file);
return <<END;
Can't open ${file} for input.
END
#'
}
sub M18_error_old_version {
my ($old_version, $directory) = @_;
$old_version ||= '???';
return <<END;
You are using Inline version $Inline::VERSION with a directory that was
configured by Inline version $old_version. This version is no longer supported.
Please delete the following directory and try again:
$directory
END
}
sub M19_usage_language {
my ($language, $directory) = @_;
require Config;
return <<END;
Error. You have specified '$language' as an Inline programming language.
I currently only know about the following languages:
${ defined $Inline::languages ?
\ join(', ', sort keys %$Inline::languages) : \ ''
}
If you have installed a support module for this language, try deleting the
config-${Config::Config{'archname'}}-$] file from the following Inline DIRECTORY, and run again:
$directory
(And if that works, please file a bug report.)
END
}
sub M20_config_creation_failed {
my ($dir) = @_;
my $file = File::Spec->catfile(${dir}, $configuration_file);
return <<END;
Failed to autogenerate ${file}.
END
}
sub M21_opendir_failed {
my ($dir) = @_;
return <<END;
Can't open directory '$dir'.
END
#'
}
sub M22_usage_register {
my ($language, $error) = @_;
return <<END;
The module Inline::$language does not support the Inline API, because it does
properly support the register() method. This module will not work with Inline
and should be uninstalled from your system. Please advise your sysadmin.
The following error was generating from this module:
$error
END
}
sub M23_usage_alias_used {
my ($new_mod, $alias, $old_mod) = @_;
return <<END;
The module Inline::$new_mod is attempting to define $alias as an alias.
But $alias is also an alias for Inline::$old_mod.
One of these modules needs to be corrected or removed.
Please notify the system administrator.
END
}
sub M24_open_for_output_failed {
my ($file) = @_;
return <<END;
Can't open $file for output.
$!
END
#'
}
sub M25_no_WITH_support {
my ($mod, $err) = @_;
return <<END;
You have requested "use Inline with => '$mod'"
but '$mod' does not work with Inline.
$err
END
}
sub M26_error_version_without_name {
return <<END;
Specifying VERSION option without NAME option is not permitted.
END
}
sub M27_module_not_indexed {
my ($mod) = @_;
return <<END;
You are attempting to load an extension for '$mod',
but there is no entry for that module in %INC.
END
}
sub M28_error_grokking_path {
my ($path) = @_;
return <<END;
Can't calculate a path from '$path' in %INC
END
}
sub M29_error_relative_path {
my ($name, $path) = @_;
return <<END;
Can't load installed extension '$name'
from relative path '$path'.
END
#'
}
sub M30_error_no_obj {
my ($name, $pkg, $path) = @_;
<<END;
The extension '$name' is not properly installed in path:
'$path'
If this is a CPAN/distributed module, you may need to reinstall it on your
system.
To allow Inline to compile the module in a temporary cache, simply remove the
Inline config option 'VERSION=' from the $pkg module.
END
}
sub M31_inline_open_failed {
my ($file) = @_;
return <<END;
Can't open Inline validate file:
$file
$!
END
#'
}
sub M32_error_md5_validation {
my ($md5, $inl) = @_;
return <<END;
The source code fingerprint:
$md5
does not match the one in:
$inl
This module needs to be reinstalled.
END
}
sub M33_error_old_inline_version {
my ($inl) = @_;
return <<END;
The following extension is not compatible with this version of Inline.pm.
$inl
You need to reinstall this extension.
END
}
sub M34_error_incorrect_version {
my ($inl) = @_;
return <<END;
The version of your extension does not match the one indicated by your
Inline source code, according to:
$inl
This module should be reinstalled.
END
}
sub M35_error_no_object_file {
my ($obj, $inl) = @_;
return <<END;
There is no object file:
$obj
For Inline validation file:
$inl
This module should be reinstalled.
END
}
sub M36_usage_install_main {
return <<END;
Can't install an Inline extension module from package 'main'.
END
#'
}
sub M37_usage_install_auto {
return <<END;
Can't install an Inline extension module with AUTONAME enabled.
END
#'
}
sub M38_usage_install_name {
return <<END;
An Inline extension module requires an explicit NAME.
END
}
sub M39_usage_install_version {
return <<END;
An Inline extension module requires an explicit VERSION.
END
}
sub M40_usage_install_badname {
my ($name, $pkg) = @_;
return <<END;
The NAME '$name' is illegal for this Inline extension.
The NAME must match the current package name:
$pkg
END
}
sub M41_usage_install_version_mismatch {
my ($mod_name, $mod_ver, $ext_name, $ext_ver) = @_;
<<END;
The version '$mod_ver' for module '$mod_name' doe not match
the version '$ext_ver' for Inline section '$ext_name'.
END
}
sub M42_usage_loader {
return <<END;
ERROR. The loader that was invoked is for compiled languages only.
END
}
sub M43_error_bootstrap {
my ($mod, $err) = @_;
return <<END;
Had problems bootstrapping Inline module '$mod'
$err
END
}
sub M45_usage_with {
return <<END;
Syntax error detected using 'use Inline with ...'.
Should be specified as:
use Inline with => 'module1', 'module2', ..., 'moduleN';
END
}
sub M46_usage_with_bad {
my $mod = shift;
return <<END;
Syntax error detected using 'use Inline with => "$mod";'.
'$mod' could not be found.
END
}
sub M47_invalid_config_option {
my ($option) = @_;
return <<END;
Invalid Config option '$option'
END
#'
}
sub M48_usage_shortcuts {
my ($shortcut) = @_;
return <<END;
Invalid shortcut '$shortcut' specified.
Valid shortcuts are:
VERSION, INFO, FORCE, NOCLEAN, CLEAN, UNTAINT, SAFE, UNSAFE,
GLOBAL, NOISY and REPORTBUG
END
}
sub M49_usage_unsafe {
my ($terminate) = @_;
return <<END .
You are using the Inline.pm module with the UNTAINT and SAFEMODE options,
but without specifying the DIRECTORY option. This is potentially unsafe.
Either use the DIRECTORY option or turn off SAFEMODE.
END
($terminate ? <<END : "");
Since you are running as a privileged user, Inline.pm is terminating.
END
}
sub M51_unused_DATA {
return <<END;
One or more DATA sections were not processed by Inline.
END
}
sub M52_invalid_filter {
my ($filter) = @_;
return <<END;
Invalid filter '$filter' is not a reference.
END
}
sub M53_mkdir_failed {
my ($dir) = @_;
return <<END;
Couldn't make directory path '$dir'.
END
#'
}
sub M54_rmdir_failed {
my ($dir) = @_;
return <<END;
Can't remove directory '$dir':
$!
END
#'
}
sub M55_unlink_failed {
my ($file) = @_;
return <<END;
Can't unlink file '$file':
$!
END
#'
}
sub M56_no_DIRECTORY_found {
return <<END;
Couldn't find an appropriate DIRECTORY for Inline to use.
END
#'
}
sub M57_wrong_architecture {
my ($ext, $arch, $thisarch) = @_;
return <<END;
The extension '$ext'
is built for perl on the '$arch' platform.
This is the '$thisarch' platform.
END
}
sub M58_site_install {
return <<END;
You have specified the SITE_INSTALL command. Support for this option has
been removed from Inline since version 0.40. It has been replaced by the
use of Inline::MakeMaker in your Makefile.PL. Please see the Inline
documentation for more help on creating and installing Inline based modules.
END
}
sub M59_bad_inline_file {
my ($lang) = @_;
return <<END;
Could not find any Inline source code for the '$lang' language using
the Inline::Files module.
END
}
sub M60_no_inline_files {
return <<END;
It appears that you have requested to use Inline with Inline::Files.
You need to explicitly 'use Inline::Files;' before your 'use Inline'.
END
}
sub M61_not_parsed {
return <<END;
It does not appear that your program has been properly parsed by Inline::Files.
END
}
sub M62_invalid_config_file {
my ($config) = @_;
return <<END;
You are using a config file that was created by an older version of Inline:
$config
This file and all the other components in its directory are no longer valid
for this version of Inline. The best thing to do is simply delete all the
contents of the directory and let Inline rebuild everything for you. Inline
will do this automatically when you run your programs.
END
}
sub M63_no_source {
my ($pkg) = @_;
return <<END;
This module $pkg can not be loaded and has no source code.
You may need to reinstall this module.
END
}
sub M64_install_not_c {
my ($lang) = @_;
return <<END;
Invalid attempt to install an Inline module using the '$lang' language.
Only C and CPP (C++) based modules are currently supported.
END
}
1;
__END__
|