/usr/share/perl5/CPANPLUS/Shell/Default.pm is in libcpanplus-perl 0.9144-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 | package CPANPLUS::Shell::Default;
use strict;
use CPANPLUS::Error;
use CPANPLUS::Backend;
use CPANPLUS::Configure::Setup;
use CPANPLUS::Internals::Constants;
use CPANPLUS::Internals::Constants::Report qw[GRADE_FAIL];
use Cwd;
use IPC::Cmd;
use Term::UI;
use Data::Dumper;
use Term::ReadLine;
use Module::Load qw[load];
use Params::Check qw[check];
use Module::Load::Conditional qw[can_load check_install];
use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
local $Params::Check::VERBOSE = 1;
local $Data::Dumper::Indent = 1; # for dumpering from !
BEGIN {
use vars qw[ $VERSION @ISA ];
@ISA = qw[ CPANPLUS::Shell::_Base::ReadLine ];
$VERSION = "0.9144";
}
load CPANPLUS::Shell;
my $map = {
'm' => '_search_module',
'a' => '_search_author',
'!' => '_bang',
'?' => '_help',
'h' => '_help',
'q' => '_quit',
'r' => '_readme',
'v' => '_show_banner',
'w' => '__display_results',
'd' => '_fetch',
'z' => '_shell',
'f' => '_distributions',
'x' => '_reload_indices',
'i' => '_install',
't' => '_install',
'l' => '_details',
'p' => '_print',
's' => '_set_conf',
'o' => '_uptodate',
'b' => '_autobundle',
'u' => '_uninstall',
'/' => '_meta', # undocumented for now
'c' => '_reports',
'e' => '_reload_shell',
};
### free letters: e g j k n y ###
### will be filled if you have a .default-shell.rc and
### Config::Auto installed
my $rc = {};
### the shell object, scoped to the file ###
my $Shell;
my $Brand = loc('CPAN Terminal');
my $Prompt = $Brand . '> ';
=pod
=head1 NAME
CPANPLUS::Shell::Default - the default CPANPLUS shell
=head1 SYNOPSIS
### loading the shell:
$ cpanp # run 'cpanp' from the command line
$ perl -MCPANPLUS -eshell # load the shell from the command line
use CPANPLUS::Shell qw[Default]; # load this shell via the API
# always done via CPANPLUS::Shell
my $ui = CPANPLUS::Shell->new;
$ui->shell; # run the shell
$ui->dispatch_on_input( input => 'x'); # update the source using the
# dispatch method
### when in the shell:
### Note that all commands can also take options.
### Look at their underlying CPANPLUS::Backend methods to see
### what options those are.
cpanp> h # show help messages
cpanp> ? # show help messages
cpanp> m Acme # find acme modules, allows regexes
cpanp> a KANE # find modules by kane, allows regexes
cpanp> f Acme::Foo # get a list of all releases of Acme::Foo
cpanp> i Acme::Foo # install Acme::Foo
cpanp> i Acme-Foo-1.3 # install version 1.3 of Acme::Foo
cpanp> i <URI> # install from URI, like ftp://foo.com/X.tgz
cpanp> i <DIR> # install from an absolute or relative directory
cpanp> i 1 3..5 # install search results 1, 3, 4 and 5
cpanp> i * # install all search results
cpanp> a KANE; i *; # find modules by kane, install all results
cpanp> t Acme::Foo # test Acme::Foo, without installing it
cpanp> u Acme::Foo # uninstall Acme::Foo
cpanp> d Acme::Foo # download Acme::Foo
cpanp> z Acme::Foo # download & extract Acme::Foo, then open a
# shell in the extraction directory
cpanp> c Acme::Foo # get a list of test results for Acme::Foo
cpanp> l Acme::Foo # view details about the Acme::Foo package
cpanp> r Acme::Foo # view Acme::Foo's README file
cpanp> o # get a list of all installed modules that
# are out of date
cpanp> o 1..3 # list uptodateness from a previous search
cpanp> s conf # show config settings
cpanp> s conf md5 1 # enable md5 checks
cpanp> s program # show program settings
cpanp> s edit # edit config file
cpanp> s reconfigure # go through initial configuration again
cpanp> s selfupdate # update your CPANPLUS install
cpanp> s save # save config to disk
cpanp> s mirrors # show currently selected mirrors
cpanp> ! [PERL CODE] # execute the following perl code
cpanp> b # create an autobundle for this computers
# perl installation
cpanp> x # reload index files (purges cache)
cpanp> x --update_source # reload index files, get fresh source files
cpanp> p [FILE] # print error stack (to a file)
cpanp> v # show the banner
cpanp> w # show last search results again
cpanp> q # quit the shell
cpanp> e # exit the shell and reload
cpanp> /plugins # list available plugins
cpanp> /? PLUGIN # list help test of <PLUGIN>
### common options:
cpanp> i ... --skiptest # skip tests
cpanp> i ... --force # force all operations
cpanp> i ... --verbose # run in verbose mode
=head1 DESCRIPTION
This module provides the default user interface to C<CPANPLUS>. You
can start it via the C<cpanp> binary, or as detailed in the L<SYNOPSIS>.
=cut
sub new {
my $class = shift;
my $cb = CPANPLUS::Backend->new( @_ );
my $self = $class->SUPER::_init(
brand => $Brand,
term => Term::ReadLine->new( $Brand ),
prompt => $Prompt,
backend => $cb,
format => "%4s %-55s %8s %-10s\n",
dist_format => "%4s %-42s %-12s %8s %-10s\n",
);
### make it available package wide ###
$Shell = $self;
my $rc_file = File::Spec->catfile(
$cb->configure_object->get_conf('base'),
DOT_SHELL_DEFAULT_RC,
);
if( -e $rc_file && -r _ ) {
$rc = $self->_read_configuration_from_rc( $rc_file );
}
### register install callback ###
$cb->_register_callback(
name => 'install_prerequisite',
code => \&__ask_about_install,
);
### execute any login commands specified ###
$self->dispatch_on_input( input => $rc->{'login'} )
if defined $rc->{'login'};
### register test report callbacks ###
$cb->_register_callback(
name => 'edit_test_report',
code => \&__ask_about_edit_test_report,
);
$cb->_register_callback(
name => 'send_test_report',
code => \&__ask_about_send_test_report,
);
$cb->_register_callback(
name => 'proceed_on_test_failure',
code => \&__ask_about_test_failure,
);
### load all the plugins
$self->_plugins_init;
if (my $histfile = $cb->configure_object->get_conf( 'histfile' )) {
my $term = $self->term;
if ($term->can('AddHistory')) {
if (open my $fh, '<', $histfile) {
local $/ = "\n";
while (my $line = <$fh>) {
chomp($line);
$term->AddHistory($line);
}
close($fh);
}
}
}
return $self;
}
sub shell {
my $self = shift;
my $term = $self->term;
my $conf = $self->backend->configure_object;
$self->_show_banner;
$self->__print( "*** Type 'p' now to show start up log\n" ); # XXX add to banner?
$self->_show_random_tip if $conf->get_conf('show_startup_tip');
$self->_input_loop && $self->__print( "\n" );
$self->_quit;
}
sub _input_loop {
my $self = shift;
my $term = $self->term;
my $cb = $self->backend;
my $normal_quit = 0;
while (
defined (my $input = eval { $term->readline($self->prompt) } )
or $self->_signals->{INT}{count} == 1
) {
### re-initiate all signal handlers
while (my ($sig, $entry) = each %{$self->_signals} ) {
$SIG{$sig} = $entry->{handler} if exists($entry->{handler});
}
$self->__print( "\n" );
last if $self->dispatch_on_input( input => $input );
### flush the lib cache ###
$cb->_flush( list => [qw|lib load|] );
} continue {
### clear the sigint count
$self->_signals->{INT}{count}--
if $self->_signals->{INT}{count};
### reset the 'install prereq?' cached answer
$self->settings->{'install_all_prereqs'} = undef;
}
return 1;
}
### return 1 to quit ###
sub dispatch_on_input {
my $self = shift;
my $conf = $self->backend->configure_object();
my $term = $self->term;
my %hash = @_;
my($string, $noninteractive);
my $tmpl = {
input => { required => 1, store => \$string },
noninteractive => { required => 0, store => \$noninteractive },
};
check( $tmpl, \%hash ) or return;
### indicates whether or not the user will receive a shell
### prompt after the command has finished.
$self->noninteractive($noninteractive) if defined $noninteractive;
my $rv = 1;
my @cmds = split ';', $string;
while( my $input = shift @cmds ) {
### to send over the socket ###
my $org_input = $input;
my $key; my $options;
{ ### make whitespace not count when using special chars
{ $input =~ s|^\s*([!?/])|$1 |; }
### get the first letter of the input
$input =~ s|^\s*([\w\?\!/])\w*||;
chomp $input;
$key = lc($1);
### we figured out what the command was...
### if we have more input, that DOES NOT start with a white
### space char, we misparsed.. like 'Test::Foo::Bar', which
### would turn into 't', '::Foo::Bar'...
if( $input and $input !~ s/^\s+// ) {
$self->__print( loc("Could not understand command: %1\n".
"Possibly missing command before argument(s)?\n",
$org_input) );
return;
}
### allow overrides from the config file ###
if( defined $rc->{$key} ) {
$input = $rc->{$key} . $input;
}
### grab command line options like --no-force and --verbose ###
($options,$input) = $term->parse_options($input)
unless $key eq '!';
}
### empty line? ###
return unless $key;
### time to quit ###
return 1 if $key eq 'q';
my $method = $map->{$key};
### dispatch meta locally at all times ###
if( $key eq '/' ) {
### keep track of failures
$rv *= length $self->$method(input => $input, options => $options);
next;
}
### flush unless we're trying to print the stack
CPANPLUS::Error->flush unless $key eq 'p';
### connected over a socket? ###
if( $self->remote ) {
### unsupported commands ###
if( $key eq 'z' or
($key eq 's' and $input =~ /^\s*edit/)
) {
$self->__print( "\n",
loc( "Command '%1' not supported over remote connection",
join ' ', $key, $input
), "\n\n" );
} else {
my($status,$buff) = $self->__send_remote_command($org_input);
$self->__print( "\n", loc("Command failed!"), "\n\n" )
unless $status;
### keep track of failures
$rv *= length $status;
$self->_pager_open if $buff =~ tr/\n// > $self->_term_rowcount;
$self->__print( $buff );
$self->_pager_close;
}
### or just a plain local shell? ###
} else {
unless( $self->can($method) ) {
$self->__print(loc("Unknown command '%1'. Usage:", $key), "\n");
$self->_help;
} else {
### some methods don't need modules ###
my @mods;
@mods = $self->_select_modules($input)
unless grep {$key eq $_} qw[! m a v w x p s b / ? h];
### keep track of failures
$rv *= defined eval { $self->$method(
modules => \@mods,
options => $options,
input => $input,
choice => $key )
};
error( $@ ) if $@;
}
}
}
### outside the shell loop, we can return the actual return value;
return $rv if $self->noninteractive;
return;
}
sub _select_modules {
my $self = shift;
my $input = shift or return;
my $cache = $self->cache;
my $cb = $self->backend;
### expand .. in $input
$input =~ s{\b(\d+)\s*\.\.\s*(\d+)\b}
{join(' ', ($1 < 1 ? 1 : $1) .. ($2 > $#{$cache} ? $#{$cache} : $2))}eg;
$input = join(' ', 1 .. $#{$cache}) if $input eq '*';
$input =~ s/'/::/g; # perl 4 convention
my @rv;
for my $mod (split /\s+/, $input) {
### it's a cache look up ###
if( $mod =~ /^\d+/ and $mod > 0 ) {
unless( scalar @$cache ) {
$self->__print( loc("No search was done yet!"), "\n" );
} elsif ( my $obj = $cache->[$mod] ) {
push @rv, $obj;
} else {
$self->__print( loc("No such module: %1", $mod), "\n" );
}
} else {
my $obj = $cb->parse_module( module => $mod );
unless( $obj ) {
$self->__print( loc("No such module: %1", $mod), "\n" );
} else {
push @rv, $obj;
}
}
}
unless( scalar @rv ) {
$self->__print( loc("No modules found to operate on!\n") );
return;
} else {
return @rv;
}
}
sub _format_version {
my $self = shift;
my $version = shift || 0;
### fudge $version into the 'optimal' format
$version = 0 if $version eq 'undef';
$version =~ s/_//g; # everything after gets stripped off otherwise
### allow 6 digits after the dot, as that's how perl stringifies
### x.y.z numbers.
$version = sprintf('%3.6f', $version);
$version = '' if $version == '0.00';
$version =~ s/(00{0,3})$/' ' x (length $1)/e;
return $version;
}
sub __display_results {
my $self = shift;
my $cache = $self->cache;
my @rv = @$cache;
if( scalar @rv ) {
$self->_pager_open if $#{$cache} >= $self->_term_rowcount;
my $i = 1;
for my $mod (@rv) {
next unless $mod; # first one is undef
# humans start counting at 1
### for dists only -- we have checksum info
if( $mod->mtime ) {
$self->__printf(
$self->dist_format,
$i,
$mod->module,
$mod->mtime,
$self->_format_version( $mod->version ),
$mod->author->cpanid
);
} else {
$self->__printf(
$self->format,
$i,
$mod->module,
$self->_format_version( $mod->version ),
$mod->author->cpanid
);
}
$i++;
}
$self->_pager_close;
} else {
$self->__print( loc("No results to display"), "\n" );
}
return 1;
}
sub _quit {
my $self = shift;
my $term = $self->term;
$self->dispatch_on_input( input => $rc->{'logout'} )
if defined $rc->{'logout'};
if ($term->can('GetHistory')) {
my @history = $term->GetHistory;
my $histfile = $self->backend->configure_object->get_conf('histfile');
if (open my $fh, '>', $histfile) {
foreach my $line (@history) {
print {$fh} "$line\n";
}
close($fh);
}
else {
warn "Cannot open history file '$histfile' - $!";
}
}
$self->__print( loc("Exiting CPANPLUS shell"), "\n" );
return 1;
}
###########################
### actual command subs ###
###########################
### print out the help message ###
### perhaps, '?' should be a slightly different version ###
{ my @help;
sub _help {
my $self = shift;
my %hash = @_;
my $input;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
input => { required => 0, store => \$input }
};
my $args = check( $tmpl, \%hash ) or return;
}
@help = (
loc('[General]' ),
loc(' h | ? # display help' ),
loc(' q # exit' ),
loc(' e # exit and reload' ),
loc(' v # version information' ),
loc('[Search]' ),
loc(' a AUTHOR ... # search by author(s)' ),
loc(' m MODULE ... # search by module(s)' ),
loc(' f MODULE ... # list all releases of a module' ),
loc(" o [ MODULE ... ] # list installed module(s) that aren't up to date" ),
loc(' w # display the result of your last search again' ),
loc('[Operations]' ),
loc(' i MODULE | NUMBER ... # install module(s), by name or by search number' ),
loc(' i URI | ... # install module(s), by URI (ie http://foo.com/X.tgz)' ),
loc(' i DIR | ... # install module(s), by path (ie ./Module-1.0)' ),
loc(' t MODULE | NUMBER ... # test module(s), by name or by search number' ),
loc(' u MODULE | NUMBER ... # uninstall module(s), by name or by search number' ),
loc(' d MODULE | NUMBER ... # download module(s)' ),
loc(' l MODULE | NUMBER ... # display detailed information about module(s)' ),
loc(' r MODULE | NUMBER ... # display README files of module(s)' ),
loc(' c MODULE | NUMBER ... # check for module report(s) from cpan-testers' ),
loc(' z MODULE | NUMBER ... # extract module(s) and open command prompt in it' ),
loc('[Local Administration]' ),
loc(' b # write a bundle file for your configuration' ),
loc(' s program [OPT VALUE] # set program locations for this session' ),
loc(' s conf [OPT VALUE] # set config options for this session' ),
loc(' s mirrors # show currently selected mirrors' ),
loc(' s reconfigure # reconfigure settings ' ),
loc(' s selfupdate # update your CPANPLUS install '),
loc(' s save [user|system] # save settings for this user or systemwide' ),
loc(' s edit [user|system] # open configuration file in editor and reload' ),
loc(' ! EXPR # evaluate a perl statement' ),
loc(' p [FILE] # print the error stack (optionally to a file)' ),
loc(' x # reload CPAN indices (purges cache)' ),
loc(' x --update_source # reload CPAN indices, get fresh source files' ),
loc('[Common Options]' ),
loc(' i ... --skiptest # skip tests' ),
loc(' i ... --force # force all operations' ),
loc(' i ... --verbose # run in verbose mode' ),
loc('[Plugins]' ),
loc(' /plugins # list available plugins' ),
loc(' /? [PLUGIN NAME] # show usage for (a particular) plugin(s)' ),
) unless @help;
$self->_pager_open if (@help >= $self->_term_rowcount);
### XXX: functional placeholder for actual 'detailed' help.
$self->__print( "Detailed help for the command '$input' is " .
"not available.\n\n" ) if length $input;
$self->__print( map {"$_\n"} @help );
$self->__print( $/ );
$self->_pager_close;
return 1;
}
}
### eval some code ###
sub _bang {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $input;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
input => { required => 1, store => \$input }
};
my $args = check( $tmpl, \%hash ) or return;
}
local $Data::Dumper::Indent = 1; # for dumpering from !
eval $input;
error( $@ ) if $@;
$self->__print( "\n" );
return if $@;
return 1;
}
sub _search_module {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $args;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
input => { required => 1, },
options => { default => { } },
};
$args = check( $tmpl, \%hash ) or return;
}
my @regexes = map { qr/$_/i } split /\s+/, $args->{'input'};
### XXX this is rather slow, because (probably)
### of the many method calls
### XXX need to profile to speed it up =/
### find the modules ###
my @rv = sort { $a->module cmp $b->module }
$cb->search(
%{$args->{'options'}},
type => 'module',
allow => \@regexes,
);
### store the result in the cache ###
$self->cache([undef,@rv]);
$self->__display_results;
return 1;
}
sub _search_author {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $args;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
input => { required => 1, },
options => { default => { } },
};
$args = check( $tmpl, \%hash ) or return;
}
my @regexes = map { qr/$_/i } split /\s+/, $args->{'input'};
my @rv;
for my $type (qw[author cpanid]) {
push @rv, $cb->search(
%{$args->{'options'}},
type => $type,
allow => \@regexes,
);
}
my %seen;
my @list = sort { $a->module cmp $b->module }
grep { defined }
map { $_->modules }
grep { not $seen{$_}++ } @rv;
$self->cache([undef,@list]);
$self->__display_results;
return 1;
}
sub _readme {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $args; my $mods; my $opts;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
modules => { required => 1, store => \$mods },
options => { default => { }, store => \$opts },
};
$args = check( $tmpl, \%hash ) or return;
}
return unless scalar @$mods;
$self->_pager_open;
for my $mod ( @$mods ) {
$self->__print( $mod->readme( %$opts ) );
}
$self->_pager_close;
return 1;
}
sub _fetch {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $args; my $mods; my $opts;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
modules => { required => 1, store => \$mods },
options => { default => { }, store => \$opts },
};
$args = check( $tmpl, \%hash ) or return;
}
$self->_pager_open if @$mods >= $self->_term_rowcount;
my $rv = 1;
for my $mod (@$mods) {
my $where = $mod->fetch( %$opts );
$rv *= length $where;
$self->__print(
$where
? loc("Successfully fetched '%1' to '%2'",
$mod->module, $where )
: loc("Failed to fetch '%1'", $mod->module)
);
$self->__print( "\n" );
}
$self->_pager_close;
return 1 if $rv;
return;
}
sub _shell {
my $self = shift;
my $cb = $self->backend;
my $conf = $cb->configure_object;
my %hash = @_;
my $shell = $conf->get_program('shell');
unless( $shell ) {
$self->__print(
loc("Your config does not specify a subshell!"), "\n",
loc("Perhaps you need to re-run your setup?"), "\n"
);
return;
}
my $args; my $mods; my $opts;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
modules => { required => 1, store => \$mods },
options => { default => { }, store => \$opts },
};
$args = check( $tmpl, \%hash ) or return;
}
my $cwd = Cwd::cwd();
for my $mod (@$mods) {
$mod->fetch( %$opts ) or next;
$mod->extract( %$opts ) or next;
$cb->_chdir( dir => $mod->status->extract() ) or next;
#local $ENV{PERL5OPT} = CPANPLUS::inc->original_perl5opt;
if( system($shell) and $! ) {
$self->__print(
loc("Error executing your subshell '%1': %2",
$shell, $!),"\n"
);
next;
}
}
$cb->_chdir( dir => $cwd );
return 1;
}
sub _distributions {
my $self = shift;
my $cb = $self->backend;
my $conf = $cb->configure_object;
my %hash = @_;
my $args; my $mods; my $opts;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
modules => { required => 1, store => \$mods },
options => { default => { }, store => \$opts },
};
$args = check( $tmpl, \%hash ) or return;
}
my @list;
for my $mod (@$mods) {
push @list, sort { $a->version <=> $b->version }
grep { defined } $mod->distributions( %$opts );
}
my @rv = sort { $a->module cmp $b->module } @list;
$self->cache([undef,@rv]);
$self->__display_results;
return 1;
}
sub _reload_indices {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $args; my $opts;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
options => { default => { }, store => \$opts },
};
$args = check( $tmpl, \%hash ) or return;
}
my $rv = $cb->reload_indices( %$opts );
### so the update failed, but you didn't give it any options either
if( !$rv and !(keys %$opts) ) {
$self->__print(
"\nFailure may be due to corrupt source files\n" .
"Try this:\n\tx --update_source\n\n" );
}
return $rv;
}
sub _install {
my $self = shift;
my $cb = $self->backend;
my $conf = $cb->configure_object;
my %hash = @_;
my $args; my $mods; my $opts; my $choice;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
modules => { required => 1, store => \$mods },
options => { default => { }, store => \$opts },
choice => { required => 1, store => \$choice,
allow => [qw|i t|] },
};
$args = check( $tmpl, \%hash ) or return;
}
unless( scalar @$mods ) {
$self->__print( loc("Nothing done\n") );
return;
}
my $target = $choice eq 'i' ? TARGET_INSTALL : TARGET_CREATE;
my $prompt = $choice eq 'i' ? loc('Installing ') : loc('Testing ');
my $action = $choice eq 'i' ? 'install' : 'test';
my $status = {};
### first loop over the mods to install them ###
for my $mod (@$mods) {
$self->__print( $prompt, $mod->module, " (".$mod->version.")", "\n" );
my $log_length = length CPANPLUS::Error->stack_as_string;
### store the status for look up when we're done with all
### install calls
$status->{$mod} = $mod->install( %$opts, target => $target );
### would you like a log file of what happened?
if( $conf->get_conf('write_install_logs') ) {
if ( ON_WIN32 and !check_install(
module => 'IPC::Run', version => 0.55 )
) {
error(loc("IPC::Run version '%1' is required on MSWin32"
. " in order to capture buffers."
. " The logfile generated may not contain"
. " any useful data, until it is installed", 0.55));
}
my $dir = File::Spec->catdir(
$conf->get_conf('base'),
$conf->_get_build('install_log_dir'),
);
### create the dir if it doesn't exit yet
$cb->_mkdir( dir => $dir ) unless -d $dir;
my $file = File::Spec->catfile(
$dir,
INSTALL_LOG_FILE->( $mod )
);
if ( open my $fh, ">$file" ) {
my $stack = CPANPLUS::Error->stack_as_string;
### remove everything in the log that was there *before*
### we started this install
substr( $stack, 0, $log_length, '' );
print $fh $stack;
close $fh;
$self->__print(
loc("*** Install log written to:\n %1\n\n", $file)
);
} else {
warn "Could not open '$file': $!\n";
next;
}
}
}
my $flag;
### then report whether all this went ok or not ###
for my $mod (@$mods) {
# if( $mod->status->installed ) {
if( $status->{$mod} ) {
$self->__print(
loc("Module '%1' %tense(%2,past) successfully\n",
$mod->module, $action)
);
} else {
$flag++;
$self->__print(
loc("Error %tense(%1,present) '%2'\n", $action, $mod->module)
);
}
}
if( !$flag ) {
$self->__print(
loc("No errors %tense(%1,present) all modules", $action), "\n"
);
} else {
$self->__print(
loc("Problem %tense(%1,present) one or more modules", $action)
);
$self->__print( "\n" );
$self->__print(
loc("*** You can view the complete error buffer by pressing ".
"'%1' ***\n", 'p')
) unless $conf->get_conf('verbose') || $self->noninteractive;
}
$self->__print( "\n" );
return !$flag;
}
sub __ask_about_install {
my $mod = shift or return;
my $prereq = shift or return;
my $term = $Shell->term;
$Shell->__print( "\n" );
$Shell->__print( loc("Module '%1' requires '%2' to be installed",
$mod->module, $prereq->module ) );
$Shell->__print( "\n\n" );
### previously cached answer?
return $Shell->settings->{'install_all_prereqs'}
if defined $Shell->settings->{'install_all_prereqs'};
$Shell->__print(
loc( "If you don't wish to see this question anymore\n".
"you can disable it by entering the following ".
"commands on the prompt:\n '%1'",
's conf prereqs 1; s save' ) );
$Shell->__print("\n\n");
my $yes = loc("Yes");
my $no = loc("No");
my $all = loc("Yes to all (for this module)");
my $none = loc("No to all (for this module)");
my $reply = $term->get_reply(
prompt => loc("Should I install this module?"),
choices => [ $yes, $no, $all, $none ],
default => $yes,
);
### if 'all' or 'none', save this, so we can apply it to
### other prereqs in this chain.
$Shell->settings->{'install_all_prereqs'} =
$reply eq $all ? 1 :
$reply eq $none ? 0 :
undef;
### if 'yes' or 'all', the user wants it installed
return $reply eq $all ? 1 :
$reply eq $yes ? 1 :
0;
}
sub __ask_about_send_test_report {
my($mod, $grade) = @_;
return 1 unless $grade eq GRADE_FAIL;
my $term = $Shell->term;
$Shell->__print( "\n" );
$Shell->__print(
loc("Test report prepared for module '%1'.\n Would you like to ".
"send it? (You can edit it if you like)", $mod->module ) );
$Shell->__print( "\n\n" );
my $bool = $term->ask_yn(
prompt => loc("Would you like to send the test report?"),
default => 'n'
);
return $bool;
}
sub __ask_about_edit_test_report {
my($mod, $grade) = @_;
return 0 unless $grade eq GRADE_FAIL;
my $term = $Shell->term;
$Shell->__print( "\n" );
$Shell->__print(
loc("Test report prepared for module '%1'. You can edit this ".
"report if you would like", $mod->module ) );
$Shell->__print("\n\n");
my $bool = $term->ask_yn(
prompt => loc("Would you like to edit the test report?"),
default => 'y'
);
return $bool;
}
sub __ask_about_test_failure {
my $mod = shift;
my $captured = shift || '';
my $term = $Shell->term;
$Shell->__print( "\n" );
$Shell->__print(
loc( "The tests for '%1' failed. Would you like me to proceed ".
"anyway or should we abort?", $mod->module ) );
$Shell->__print( "\n\n" );
my $bool = $term->ask_yn(
prompt => loc("Proceed anyway?"),
default => 'n',
);
return $bool;
}
sub _details {
my $self = shift;
my $cb = $self->backend;
my $conf = $cb->configure_object;
my %hash = @_;
my $args; my $mods; my $opts;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
modules => { required => 1, store => \$mods },
options => { default => { }, store => \$opts },
};
$args = check( $tmpl, \%hash ) or return;
}
### every module has about 10 lines of details
### maybe more later with Module::CPANTS etc
$self->_pager_open if scalar @$mods * 10 > $self->_term_rowcount;
my $format = "%-24s %-45s\n";
my $cformat = "%-24s %-45s %-10s\n";
for my $mod (@$mods) {
my $href = $mod->details( %$opts );
my @list = sort { $a->module cmp $b->module } $mod->contains;
unless( $href ) {
$self->__print(
loc("No details for %1 - it might be outdated.",
$mod->module), "\n" );
next;
} else {
$self->__print( loc( "Details for '%1'\n", $mod->module ) );
for my $item ( sort keys %$href ) {
$self->__printf( $format, $item, $href->{$item} );
}
my $showed;
for my $item ( @list ) {
$self->__printf(
$cformat, ($showed ? '' : 'Contains:'),
$item->module, $item->version
);
$showed++;
}
$self->__print( "\n" );
}
}
$self->_pager_close;
$self->__print( "\n" );
return 1;
}
sub _print {
my $self = shift;
my %hash = @_;
my $args; my $opts; my $file;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
options => { default => { }, store => \$opts },
input => { default => '', store => \$file },
};
$args = check( $tmpl, \%hash ) or return;
}
my $old; my $fh;
if( $file ) {
$fh = FileHandle->new( ">$file" )
or( warn loc("Could not open '%1': '%2'", $file, $!),
return
);
$old = select $fh;
}
$self->_pager_open if !$file;
$self->__print( CPANPLUS::Error->stack_as_string );
$self->_pager_close;
select $old if $old;
$self->__print( "\n" );
return 1;
}
sub _set_conf {
my $self = shift;
my %hash = @_;
my $cb = $self->backend;
my $conf = $cb->configure_object;
### possible options
### XXX hard coded, not optimal :(
my %types = (
reconfigure => '',
save => q([user | system | boxed]),
edit => '',
program => q([key => val]),
conf => q([key => val]),
mirrors => '',
selfupdate => '', # XXX add all opts here?
);
my $args; my $opts; my $input;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
options => { default => { }, store => \$opts },
input => { default => '', store => \$input },
};
$args = check( $tmpl, \%hash ) or return;
}
my ($type,$key,$value) = $input =~ m/(\w+)\s*(\w*)\s*(.*?)$/;
$value =~ s/\s+$//g if $value;
$type = '' unless defined $type;
$type = lc $type;
if( $type eq 'reconfigure' ) {
my $setup = CPANPLUS::Configure::Setup->new(
configure_object => $conf,
term => $self->term,
backend => $cb,
);
return $setup->init;
} elsif ( $type eq 'save' ) {
my $where = {
user => CONFIG_USER,
system => CONFIG_SYSTEM,
boxed => CONFIG_BOXED,
}->{ $key } || CONFIG_USER;
### boxed is special, so let's get its value from %INC
### so we can tell it where to save
### XXX perhaps this logic should be generic for all
### types, and put in the ->save() routine
my $dir;
if( $where eq CONFIG_BOXED ) {
my $file = join( '/', split( '::', CONFIG_BOXED ) ) . '.pm';
my $file_re = quotemeta($file);
my $path = $INC{$file} || '';
$path =~ s/$file_re$//;
$dir = $path;
}
my $rv = $cb->configure_object->save( $where => $dir );
$self->__print(
$rv
? loc("Configuration successfully saved to %1\n (%2)\n",
$where, $rv)
: loc("Failed to save configuration\n" )
);
return $rv;
} elsif ( $type eq 'edit' ) {
my $editor = $conf->get_program('editor')
or( print(loc("No editor specified")), return );
my $where = {
user => CONFIG_USER,
system => CONFIG_SYSTEM,
}->{ $key } || CONFIG_USER;
my $file = $conf->_config_pm_to_file( $where );
system($editor,$file);
### now reload it
### disable warnings for this
{ require Module::Loaded;
Module::Loaded::mark_as_unloaded( $where );
### reinitialize the config
local $^W;
$conf->init;
}
return 1;
} elsif ( $type eq 'mirrors' ) {
$self->__print(
loc("Readonly list of mirrors (in order of preference):\n\n" ) );
my $i;
for my $host ( @{$conf->get_conf('hosts')} ) {
my $uri = $cb->_host_to_uri( %$host );
$i++;
$self->__print( "\t[$i] $uri\n" );
}
$self->__print(
loc("\nTo edit this list, please type: '%1'\n", 's edit') );
} elsif ( $type eq 'selfupdate' ) {
my %valid = map { $_ => $_ }
$cb->selfupdate_object->list_categories;
unless( $valid{$key} ) {
$self->__print(
loc( "To update your current CPANPLUS installation, ".
"choose one of the these options:\n%1",
( join $/, map {
sprintf "\ts selfupdate %-17s " .
"[--latest=0] [--dryrun]", $_
} sort keys %valid )
)
);
} else {
my %update_args = (
update => $key,
latest => 1,
%$opts
);
my %list = $cb->selfupdate_object
->list_modules_to_update( %update_args );
$self->__print(loc("The following updates will take place:"),$/.$/);
for my $feature ( sort keys %list ) {
my $aref = $list{$feature};
### is it a 'feature' or a built in?
$self->__print(
$valid{$feature}
? " " . ucfirst($feature) . ":\n"
: " Modules for '$feature' support:\n"
);
### show what modules would be installed
$self->__print(
scalar @$aref
? map { sprintf " %-42s %-6s -> %-6s \n",
$_->name, $_->installed_version, $_->version
} @$aref
: " No upgrades required\n"
);
$self->__print( $/ );
}
unless( $opts->{'dryrun'} ) {
$self->__print( loc("Updating your CPANPLUS installation\n") );
$cb->selfupdate_object->selfupdate( %update_args );
}
}
} else {
if ( $type eq 'program' or $type eq 'conf' ) {
my $format = {
conf => '%-25s %s',
program => '%-12s %s',
}->{ $type };
unless( $key ) {
my @list = grep { $_ ne 'hosts' }
$conf->options( type => $type );
my $method = 'get_' . $type;
local $Data::Dumper::Indent = 0;
for my $name ( @list ) {
my $val = $conf->$method($name) || '';
($val) = ref($val)
? (Data::Dumper::Dumper($val) =~ /= (.*);$/)
: "'$val'";
$self->__printf( " $format\n", $name, $val );
}
} elsif ( $key eq 'hosts' or $key eq 'lib' ) {
$self->__print(
loc( "Setting %1 is not trivial.\n" .
"It is suggested you use '%2' and edit the " .
"configuration file manually", $key, 's edit')
);
} else {
my $method = 'set_' . $type;
$conf->$method( $key => defined $value ? $value : '' )
and $self->__print( loc("Key '%1' was set to '%2'", $key,
defined $value ? $value : 'EMPTY STRING') );
}
} else {
$self->__print( loc("Unknown type '%1'",$type || 'EMPTY' ) );
$self->__print( $/ );
$self->__print( loc("Try one of the following:") );
$self->__print( $/, join $/,
map { sprintf "\t%-11s %s", $_, $types{$_} }
sort keys %types );
}
}
$self->__print( "\n" );
return 1;
}
sub _uptodate {
my $self = shift;
my %hash = @_;
my $cb = $self->backend;
my $conf = $cb->configure_object;
my $opts; my $mods;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
options => { default => { }, store => \$opts },
modules => { required => 1, store => \$mods },
};
check( $tmpl, \%hash ) or return;
}
### long listing? short is default ###
my $long = $opts->{'long'} ? 1 : 0;
my @list = scalar @$mods ? @$mods : @{$cb->_all_installed};
my @rv; my %seen;
for my $mod (@list) {
### skip this mod if it's up to date ###
next if $mod->is_uptodate;
### skip this mod if it's core ###
next if $mod->package_is_perl_core;
if( $long or !$seen{$mod->package}++ ) {
push @rv, $mod;
}
}
@rv = sort { $a->module cmp $b->module } @rv;
$self->cache([undef,@rv]);
$self->_pager_open if scalar @rv >= $self->_term_rowcount;
my $format = "%5s %12s %12s %-36s %-10s\n";
my $i = 1;
for my $mod ( @rv ) {
$self->__printf(
$format,
$i,
$self->_format_version($mod->installed_version) || 'Unparsable',
$self->_format_version( $mod->version ),
$mod->module,
$mod->author->cpanid
);
$i++;
}
$self->_pager_close;
return 1;
}
sub _autobundle {
my $self = shift;
my %hash = @_;
my $cb = $self->backend;
my $conf = $cb->configure_object;
my $opts; my $input;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
options => { default => { }, store => \$opts },
input => { default => '', store => \$input },
};
check( $tmpl, \%hash ) or return;
}
$opts->{'path'} = $input if $input;
my $where = $cb->autobundle( %$opts );
$self->__print(
$where
? loc("Wrote autobundle to '%1'", $where)
: loc("Could not create autobundle" )
);
$self->__print( "\n" );
return $where ? 1 : 0;
}
sub _uninstall {
my $self = shift;
my %hash = @_;
my $cb = $self->backend;
my $term = $self->term;
my $conf = $cb->configure_object;
my $opts; my $mods;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
options => { default => { }, store => \$opts },
modules => { default => [], store => \$mods },
};
check( $tmpl, \%hash ) or return;
}
my $force = $opts->{'force'} || $conf->get_conf('force');
unless( $force ) {
my $list = join "\n", map { ' ' . $_->module } @$mods;
$self->__print( loc("
This will uninstall the following modules:
%1
Note that if you installed them via a package manager, you probably
should use the same package manager to uninstall them
", $list) );
return unless $term->ask_yn(
prompt => loc("Are you sure you want to continue?"),
default => 'n',
);
}
### first loop over all the modules to uninstall them ###
for my $mod (@$mods) {
$self->__print( loc("Uninstalling '%1'", $mod->module), "\n" );
$mod->uninstall( %$opts );
}
my $flag;
### then report whether all this went ok or not ###
for my $mod (@$mods) {
if( $mod->status->uninstall ) {
$self->__print(
loc("Module '%1' %tense(uninstall,past) successfully\n",
$mod->module ) );
} else {
$flag++;
$self->__print(
loc("Error %tense(uninstall,present) '%1'\n", $mod->module) );
}
}
if( !$flag ) {
$self->__print(
loc("All modules %tense(uninstall,past) successfully"), "\n" );
} else {
$self->__print(
loc("Problem %tense(uninstall,present) one or more modules" ),
"\n" );
$self->__print(
loc("*** You can view the complete error buffer by pressing '%1'".
"***\n", 'p') ) unless $conf->get_conf('verbose');
}
$self->__print( "\n" );
return !$flag;
}
sub _reports {
my $self = shift;
my %hash = @_;
my $cb = $self->backend;
my $term = $self->term;
my $conf = $cb->configure_object;
my $opts; my $mods;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
options => { default => { }, store => \$opts },
modules => { default => '', store => \$mods },
};
check( $tmpl, \%hash ) or return;
}
### XXX might need to be conditional ###
$self->_pager_open;
for my $mod (@$mods) {
my @list = $mod->fetch_report( %$opts )
or( print(loc("No reports available for this distribution.")),
next
);
@list = reverse
map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [$_, $_->{'dist'}.':'.$_->{'platform'}] } @list;
### XXX this may need to be sorted better somehow ###
my $url;
my $format = "%8s %s %s\n";
my %seen;
for my $href (@list ) {
$self->__print(
"[" . $mod->author->cpanid .'/'. $href->{'dist'} . "]\n"
) unless $seen{ $href->{'dist'} }++;
$self->__printf(
$format,
$href->{'grade'},
$href->{'platform'},
($href->{'details'} ? '(*)' : '')
);
$url ||= $href->{'details'};
}
$self->__print( "\n==> $url\n" ) if $url;
$self->__print( "\n" );
}
$self->_pager_close;
return 1;
}
### Load plugins
{ my @PluginModules;
my %Dispatch = (
showtip => [ __PACKAGE__, '_show_random_tip'],
plugins => [ __PACKAGE__, '_list_plugins' ],
'?' => [ __PACKAGE__, '_plugins_usage' ],
);
sub plugin_modules { return @PluginModules }
sub plugin_table { return %Dispatch }
my $init_done;
sub _plugins_init {
### only initialize once
return if $init_done++;
### find all plugins first
if( check_install( module => 'Module::Pluggable', version => '2.4') ) {
require Module::Pluggable;
my $only_re = __PACKAGE__ . '::Plugins::\w+$';
Module::Pluggable->import(
sub_name => '_plugins',
search_path => __PACKAGE__,
only => qr/$only_re/,
#except => [ INSTALLER_MM, INSTALLER_SAMPLE ]
);
push @PluginModules, __PACKAGE__->_plugins;
}
### now try to load them
for my $p ( __PACKAGE__->plugin_modules ) {
my %map = eval { load $p; $p->import; $p->plugins };
error(loc("Could not load plugin '$p': $@")), next if $@;
### register each plugin
while( my($name, $func) = each %map ) {
if( not length $name or not length $func ) {
error(loc("Empty plugin name or dispatch function detected"));
next;
}
if( exists( $Dispatch{$name} ) ) {
error(loc("'%1' is already registered by '%2'",
$name, $Dispatch{$name}->[0]));
next;
}
### register name, package and function
$Dispatch{$name} = [ $p, $func ];
}
}
}
### dispatch a plugin command to its function
sub _meta {
my $self = shift;
my %hash = @_;
my $cb = $self->backend;
my $term = $self->term;
my $conf = $cb->configure_object;
my $opts; my $input;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
options => { default => { }, store => \$opts },
input => { default => '', store => \$input },
};
check( $tmpl, \%hash ) or return;
}
$input =~ s/\s*(\S+)\s*//;
my $cmd = $1;
### look up the command, or go to the default
my $aref = $Dispatch{ $cmd } || [ __PACKAGE__, '_plugin_default' ];
my($pkg,$func) = @$aref;
my $rv = eval { $pkg->$func( $self, $cb, $cmd, $input, $opts ) };
error( $@ ) if $@;
### return $rv instead, so input loop can be terminated?
return 1;
}
sub _plugin_default { error(loc("No such plugin command")) }
}
### plugin commands
{ my $help_format = " /%-21s # %s\n";
sub _list_plugins {
my $self = shift;
$self->__print( loc("Available plugins:\n") );
$self->__print( loc(" List usage by using: /? PLUGIN_NAME\n" ) );
$self->__print( $/ );
my %table = __PACKAGE__->plugin_table;
for my $name( sort keys %table ) {
my $pkg = $table{$name}->[0];
my $this = __PACKAGE__;
my $who = $pkg eq $this
? "Standard Plugin"
: do { my $v = $self->_format_version($pkg->VERSION) || '';
$pkg =~ s/^$this/../;
sprintf "Provided by: %-30s %-10s", $pkg, $v;
};
$self->__printf( $help_format, $name, $who );
}
$self->__print( $/.$/ );
$self->__print(
" Write your own plugins? Read the documentation of:\n" .
" CPANPLUS::Shell::Default::Plugins::HOWTO\n" );
$self->__print( $/ );
}
sub _list_plugins_help {
return sprintf $help_format, 'plugins', loc("lists available plugins");
}
### registered as a plugin too
sub _show_random_tip_help {
return sprintf $help_format, 'showtip', loc("show usage tips" );
}
sub _plugins_usage {
my $self = shift;
my $shell = shift;
my $cb = shift;
my $cmd = shift;
my $input = shift;
my %table = $self->plugin_table;
my @list = length $input ? split /\s+/, $input : sort keys %table;
for my $name( @list ) {
### no such plugin? skip
error(loc("No such plugin '$name'")), next unless $table{$name};
my $pkg = $table{$name}->[0];
my $func = $table{$name}->[1] . '_help';
if ( my $sub = $pkg->can( $func ) ) {
eval { $self->__print( $sub->() ) };
error( $@ ) if $@;
} else {
$self->__print(" No usage for '$name' -- try perldoc $pkg");
}
$self->__print( $/ );
}
$self->__print( $/.$/ );
}
sub _plugins_usage_help {
return sprintf $help_format, '? [NAME ...]',
loc("show usage for plugins");
}
}
### send a command to a remote host, retrieve the answer;
sub __send_remote_command {
my $self = shift;
my $cmd = shift;
my $remote = $self->remote or return;
my $user = $remote->{'username'};
my $pass = $remote->{'password'};
my $conn = $remote->{'connection'};
my $end = "\015\012";
my $answer;
my $send = join "\0", $user, $pass, $cmd;
print $conn $send . $end;
### XXX why doesn't something like this just work?
#1 while recv($conn, $answer, 1024, 0);
while(1) {
my $buff;
$conn->recv( $buff, 1024, 0 );
$answer .= $buff;
last if $buff =~ /$end$/;
}
my($status,$buffer) = split "\0", $answer;
return ($status, $buffer);
}
sub _read_configuration_from_rc {
my $self = shift;
my $rc_file = shift;
my $href;
if( can_load( modules => { 'Config::Auto' => '0.0' } ) ) {
$Config::Auto::DisablePerl = 1;
eval { $href = Config::Auto::parse( $rc_file, format => 'space' ) };
$self->__print(
loc( "Unable to read in config file '%1': %2", $rc_file, $@ )
) if $@;
}
return $href || {};
}
{ my @tips = (
loc( "You can update CPANPLUS by running: '%1'", 's selfupdate' ),
loc( "You can install modules by URL using '%1'", 'i URL' ),
loc( "You can turn off these tips using '%1'",
's conf show_startup_tip 0' ),
loc( "You can use wildcards like '%1' and '%2' on search results",
'*', '2..5' ) ,
loc( "You can use plugins. Type '%1' to list available plugins",
'/plugins' ),
loc( "You can show all your out of date modules using '%1'", 'o' ),
loc( "Many operations take options, like '%1', '%2' or '%3'",
'--verbose', '--force', '--skiptest' ),
loc( "The documentation in %1 and %2 is very useful",
"CPANPLUS::Module", "CPANPLUS::Backend" ),
loc( "You can type '%1' for help and '%2' to exit", 'h', 'q' ),
loc( "You can run an interactive setup using '%1'", 's reconfigure' ),
loc( "You can add custom sources to your index. See '%1' for details",
'/cs --help' ),
loc( "CPANPLUS now has an experimental SQLite backend. You can enable ".
"it via: '%1'. Update dependencies via '%2'",
's conf source_engine CPANPLUS::Internals::Source::SQLite; s save',
's selfupdate enabled_features ' ),
);
sub _show_random_tip {
my $self = shift;
$self->__print( $/, "Did you know...\n ",
$tips[ int rand scalar @tips ], $/ );
return 1;
}
}
sub _reload_shell {
{ exec ($^X, '-MCPANPLUS', '-e', 'shell') }; print STDERR "couldn't exec foo: $!";
}
1;
__END__
=pod
=head1 BUG REPORTS
Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.
=head1 AUTHOR
This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
=head1 COPYRIGHT
The CPAN++ interface (of which this module is a part of) is copyright (c)
2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.
This library is free software; you may redistribute and/or modify it
under the same terms as Perl itself.
=head1 SEE ALSO
L<CPANPLUS::Shell::Classic>, L<CPANPLUS::Shell>, L<cpanp>
=cut
# Local variables:
# c-indentation-style: bsd
# c-basic-offset: 4
# indent-tabs-mode: nil
# End:
# vim: expandtab shiftwidth=4:
__END__
TODO:
e => "_expand_inc", # scratch it, imho -- not used enough
### free letters: g j k n y ###
|