From: dams <dams@gentoo.org>
To: gentoo-perl@lists.gentoo.org
Subject: [gentoo-perl] g-cpan patch
Date: Sun, 10 Sep 2006 01:19:01 +0200 [thread overview]
Message-ID: <20060910011901.1e8c0077@localhost> (raw)
[-- Attachment #1: Type: text/plain, Size: 374 bytes --]
Hi
While looking at the g-cpan code, I have coded some stuff, here is the patch. Remarks welcome. If you are pleased with it, I'll commit it.
Features/changes :
- recoded the small options verification
- implemented a Fake CPAN::Frontend, to catch the output of the CPAN search
- added a small spin animation to the cpan search
- wrote the cpan search result output
dams
[-- Attachment #2: g-cpan_patch.diff --]
[-- Type: application/octet-stream, Size: 3990 bytes --]
Index: bin/g-cpan
===================================================================
--- bin/g-cpan (revision 98)
+++ bin/g-cpan (working copy)
@@ -44,9 +44,13 @@
use Getopt::Long;
Getopt::Long::Configure("bundling");
-# Init all options (has to be done to perform the 'sum test' later)
-my ($debug, $verbose, $search, $install, $upgrade, $generate, $list, $pretend, $ask, $cpan_reload, $buildpkg, $buildpkgonly, $log) =
- (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+# Declare options
+# First, the main switches
+my @main_switches = \my ($search, $list, $install, $generate, $ask, $buildpkg, $buildpkgonly);
+# Then, additional switches
+my @additional_switches = \my ($upgrade, $pretend);
+# Then, the normal options
+my ($debug, $verbose, $cpan_reload, $log);
# Set colors here so we can use them at will anywhere :)
my $green = color("bold green");
@@ -118,20 +122,20 @@
# Array that will contain the portage friendly version of the values passed to install
my %really_install;
-# Output error if more than one switch is activated
+# Output error if more than one main switch is activated
#
-if ($search + $list + $install + $generate + $ask + $buildpkg + $buildpkgonly > 1)
+
+if ( (grep { defined $$_ } @main_switches) > 1)
{
print_err($prog, "You can't combine actions with each other.\n");
print_out("${white}Please consult ${cyan}$prog ${green}--help${reset} or ${cyan}man $prog${reset} for more information\n\n");
exit();
}
-if ($search + $list + $install + $generate + $upgrade + $pretend + $ask + $buildpkg + $buildpkgonly == 0)
+if ( ! grep { defined $$_ } @main_switches, @additional_switches )
{
print_err($prog, "You haven't told $prog what to do.\n");
print_out("${white}Please consult ${cyan}$prog ${green}--help${reset} or ${cyan}man $prog${reset} for more information\n\n");
-
exit();
}
@@ -306,8 +310,7 @@
# Set portage_categories to our defined list of perl_dirs
$gcpan_run->{portage_categories} = \@perl_dirs;
-# Taking care of Searches. This has to be improved a lot, since it uses a call to
-# CPAN Shell to do the job, thus making it impossible to have a clean output..
+# Taking care of Searches.
if ($search)
{
foreach my $expr (@ARGV)
@@ -324,17 +327,51 @@
{
print_info($prog, "No ebuild exists, pulling up CPAN listings for $expr");
- }
-
# Assume they gave us module-name instead of module::name
# which is bad, because CPAN can't convert it ;p
- print_ok($prog, "Searching for $expr on CPAN") if ($verbose);
- unless (CPAN::Shell->i("/$expr/"))
- {
- $expr =~ s/-/::/g;
+ print_ok($prog, "Searching for $expr on CPAN") if ($verbose);
+
+ my @search_results;
+
+ # Let's define a CPAN::Frontend to use our printing methods
+ {
+ package Gentoo::CPAN::FakeFrontend;
+ my $spin = 0;
+ sub myprint {
+ my ($self, $text) = @_;
+ print "\r".('/', '-', '\\', '|')[$spin++%4];
+ # if there is only one result, the string is different
+ $text =~ /Module id = (.*)/ and push(@search_results, $1), return;
+ # in the case of multiple result
+ if ($text =~ /Module\s+(\S+)/) {
+ foreach (split(/\n/, $text)) {
+ $_ =~ /Module\s+(\S+)/ or next;
+ push @search_results, $1;
+ }
+ }
+ }
+ }
+
+ $CPAN::Frontend = "Gentoo::CPAN::FakeFrontend";
+
CPAN::Shell->i("/$expr/");
- }
+ if (!@search_results) {
+ $expr =~ s/-/::/g;
+ CPAN::Shell->i("/$expr/");
+ }
+
+ # remove the spin
+ print "\r \r";
+
+ # now, @search_results should contain the matching modules strings, if any
+ if (@search_results) {
+ print_info('g-cpan', @search_results . " results found : @search_results");
+ } else {
+ print_warn('no result found.');
+ }
+
+ }
}
exit;
next reply other threads:[~2006-09-09 23:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-09 23:19 dams [this message]
2006-09-11 9:34 ` [gentoo-perl] g-cpan patch Christian Hartmann
2006-09-12 19:10 ` dams
2006-09-11 16:47 ` Chris White
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060910011901.1e8c0077@localhost \
--to=dams@gentoo.org \
--cc=gentoo-perl@gentoo.org \
--cc=gentoo-perl@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox