Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-perl
Navigation:
Lists: gentoo-perl: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-perl@g.o
From: antoine.raillon@...
Subject: r25 - in trunk: bin extra-docs
Date: Sun, 15 May 2005 12:14:54 +0200 (CEST)
Author: cab
Date: 2005-05-15 12:02:54 +0200 (Sun, 15 May 2005)
New Revision: 25

Modified:
   trunk/bin/g-cpan.pl
   trunk/extra-docs/Changes
Log:
- corrected indentation and typos in exit_usage()
- colorized exit_usage (feel like portage)
- rearranged code (categorizing sub - easier to find what we're looking for)
- added some comments here and there (again ;p)


Modified: trunk/bin/g-cpan.pl
===================================================================
--- trunk/bin/g-cpan.pl	2005-05-12 18:05:56 UTC (rev 24)
+++ trunk/bin/g-cpan.pl	2005-05-15 10:02:54 UTC (rev 25)
@@ -11,6 +11,7 @@
 use File::Spec;
 use File::Path;
 use File::Basename;
+use Term::ANSIColor;
 
 use constant MAKE_CONF         => '/etc/make.conf';
 use constant PATH_PKG_DEV_PERL => '/var/db/pkg/dev-perl';
@@ -45,6 +46,9 @@
 my $prog = basename($0);
 
 # Do we need to generate a config ?
+# FIXME cab
+# When calling g-cpan, if the user has no conf, g-cpan will generate one as first step.
+# This is not necessary if we're asking for --help and generate way too much output.
 eval 'use CPAN::Config;';
 my $needs_cpan_stub = $@ ? 1 : 0;
 
@@ -198,7 +202,6 @@
 # Now we export our overlay directory into the session's env vars
 $ENV{PORTDIR_OVERLAY} = $tmp_overlay_dir;
 
-# sub main.. well, sort of ;p
 # Take care of List requests. This should return all the ebuilds managed by g-cpan
 if ($list) {
     printbig "Generating list of modules managed by g-cpan";
@@ -231,23 +234,10 @@
 
 exit;
 
-##########
-# subs ! #
-##########
+##############
+# Big subs ! #
+##############
 
-# jrray printing functions
-sub printbig {
-# FIXME Sniper
-# 72 hard coded is bad
-    print '*' x 72, "\n";
-    print '*',   "\n";
-    print '*',   "\n";
-    print '*  ', @_;
-    print '*',   "\n";
-    print '*',   "\n";
-    print '*' x 72, "\n";
-}
-
 sub ebuild_exists {
     my ($dir) = $_[0];
 
@@ -355,15 +345,6 @@
     # if we are here, $found if undef, what to do ?
 }
 
-sub module_check {
-
-# module_check evaluates whether a module can be loaded from @INC.
-# This allows us to assure that if a module has been manually installed, we know about it.
-    my $check = shift;
-    eval "use $check;";
-    return $@ ? 0 : 1;
-}
-
 sub portage_dir {
     my $obj  = shift;
     my $file = $obj->cpan_file;
@@ -667,19 +648,6 @@
 
 }
 
-# TODO Sniper
-# maybee put this in END {} block
-sub clean_up {
-
-    #Probably don't need to do this, but for sanity's sake, we reset this var
-    #     $ENV{'PORTDIR_OVERLAY'} = $OVERLAYS[0];
-
-    if ($needs_cpan_stub) { unlink "$ENV{HOME}/.cpan/CPAN/MyConfig.pm" }
-
-    #Clean out the /tmp tree we were using
-    rmtree( ["$tmp_overlay_dir"] ) if ( !$OVERLAYS[0] );
-}
-
 sub emerge_module {
 	my @flags;
 	push @flags, "-p" if $pretend > 0;
@@ -758,17 +726,6 @@
     return ( $conf{DISTDIR}, $conf{PORTDIR}, @OVERLAYS );
 }
 
-sub clean_vars {
-
-    # In order to parse strange but allowed constructions,
-    # (i.e. DISTDIR=${PORTDIR}/disfiles), we are cycling some times
-    # (3 should be enough) on DISTDIR and PORTDIR_OVERLAY settings,
-    # using a nice regexp (thx Sniper - sniper@...)
-    my ( $toclean, %conf ) = @_;
-    foreach my $i ( 1 .. 3 ) { $toclean =~ s/\$\{ ( [^}]+ ) \}/$conf{$1}/egx }
-    return ($toclean);
-}
-
 sub cpan_stub {
     my $cpan_cfg_dir  = File::Spec->catfile($ENV{HOME},    CPAN_CFG_DIR);
     my $cpan_cfg_file = File::Spec->catfile($cpan_cfg_dir, CPAN_CFG_NAME);
@@ -844,8 +801,43 @@
     close CPANCONF;
 }
 
-# Simple useful sub. returns md5 hexdigest of the given argument
+################
+# Display subs #
+################
+
+# jrray printing functions
+sub printbig {
+# FIXME cab
+# Rewrite using colors !
+# FIXME Sniper
+# 72 hard coded is bad
+    print '*' x 72, "\n";
+    print '*',   "\n";
+    print '*',   "\n";
+    print '*  ', @_;
+    print '*',   "\n";
+    print '*',   "\n";
+    print '*' x 72, "\n";
+}
+
+#################################################
+# NAME  : fatal
+# AUTHOR: David "Sniper" Rigaudiere
+# OBJECT: die like with pattern format
+#
+# IN: 0 scalar pattern sprintf format
+#     x LIST   variables filling blank in pattern
+#################################################
+sub fatal { die sprintf(shift, @_) }
+
+
+##############
+# Tools subs #
+##############
+
+# cab - Simple useful sub. returns md5 hexdigest of the given argument.
 # awaits a file name.
+# FIXME cab : add a test (if -f $file) ?
 sub file_md5sum {
     my ($file) = @_;;
     print "Computing MD5 Sum of $file\n" if $verbose;
@@ -859,7 +851,29 @@
     return $md5digest;
 }
 
-# Takes care of system's sanity
+# In order to parse strange but allowed constructions,
+# (i.e. DISTDIR=${PORTDIR}/disfiles), we are cycling some times
+# (3 should be enough) on DISTDIR and PORTDIR_OVERLAY settings,
+# using a nice regexp (thx Sniper - sniper@...)
+sub clean_vars {
+    my ( $toclean, %conf ) = @_;
+    foreach my $i ( 1 .. 3 ) { $toclean =~ s/\$\{ ( [^}]+ ) \}/$conf{$1}/egx }
+    return ($toclean);
+}
+
+# mcummings - module_check evaluates whether a module can be loaded from @INC.
+# This allows us to assure that if a module has been manually installed, we know about it.
+sub module_check {
+    my $check = shift;
+    eval "use $check;";
+    return $@ ? 0 : 1;
+}
+
+###############
+# Ending subs #
+###############
+
+# cab - Takes care of system's sanity
 # should try to see if it can be merged with clean_up()
 sub clean_the_mess {
     if ($verbose) {
@@ -872,43 +886,59 @@
     }
 }
 
-#################################################
-# NAME  : fatal
-# AUTHOR: David "Sniper" Rigaudiere
-# OBJECT: die like with pattern format
-#
-# IN: 0 scalar pattern sprintf format
-#     x LIST   variables filling blank in pattern
-#################################################
-sub fatal { die sprintf(shift, @_) }
+# TODO Sniper
+# maybee put this in END {} block
+sub clean_up {
 
+    #Probably don't need to do this, but for sanity's sake, we reset this var
+    #     $ENV{'PORTDIR_OVERLAY'} = $OVERLAYS[0];
 
+    if ($needs_cpan_stub) { unlink "$ENV{HOME}/.cpan/CPAN/MyConfig.pm" }
+
+    #Clean out the /tmp tree we were using
+    rmtree( ["$tmp_overlay_dir"] ) if ( !$OVERLAYS[0] );
+}
+
+# cab - nice help message ! ;)
 sub exit_usage {
+	my $green = color("bold green");
+	my $white = color ("bold white");
+	my $cyan = color("bold cyan");
+	my $reset = color("reset");
+	
     print <<"USAGE";
-Usage : $prog <Switch(es)> Module Name(s)
+${white}Usage : ${cyan}$prog ${green}<Switch(es)> ${cyan}Module Name(s)${reset}
 
---ask,-a       Ask before installing
+${green}--ask,-a${reset}
+    Ask before installing
 
---install,-i    Try to generate ebuild for the given module name
-                and, if successful, emerge it. Important : installation
-                requires exact CPAN Module Name.
+${green}--install,-i${reset}
+    Try to generate ebuild for the given module name
+    and, if successful, emerge it. Important : installation
+    requires exact CPAN Module Name.
 
---list,-l       This command generates a list of the Perl modules and ebuilds
-                handled by $prog.
+${green}--list,-l${reset}
+    This command generates a list of the Perl modules and ebuilds
+    handled by $prog.
 
---noclean,-n   Don't clean up temporary areas after running install or upgrade.
+${green}--noclean,-n${reset}
+    Don't clean up temporary areas after running install or upgrade.
 
---pretend,-u    Pretend (show actions, but don't emerge). This still generates
-		new ebuilds.
+${green}--pretend,-p${reset}
+    Pretend (show actions, but don't emerge). This still generates
+    new ebuilds.
 
---search,-s     Search CPAN for the given expression (similar to
-                the "m /EXPR/" from the CPAN Shell). Searches are
-                case insensitive.
+${green}--search,-s${reset}
+    Search CPAN for the given expression (similar to
+    the "m /EXPR/" from the CPAN Shell). Searches are
+    case insensitive.
 
---upgrade,-u    Try to list and upgrade all Perl modules managed by $prog.
-                It generate up-to-date ebuilds, then emerge then.
+${green}--upgrade,-u${reset}
+    Try to list and upgrade all Perl modules managed by $prog.
+    It generate up-to-date ebuilds, then emerge then.
 
---verbose,-v    Enable (some) verbose output.
+${green}--verbose,-v${reset}
+    Enable (some) verbose output.
 
 USAGE
 

Modified: trunk/extra-docs/Changes
===================================================================
--- trunk/extra-docs/Changes	2005-05-12 18:05:56 UTC (rev 24)
+++ trunk/extra-docs/Changes	2005-05-15 10:02:54 UTC (rev 25)
@@ -1,3 +1,10 @@
+15/05/2005 - Wonderful colored world, by cab ;)
+
+- corrected indentation and typos in exit_usage()
+- colorized exit_usage (feel like portage)
+- rearranged code (categorizing sub - easier to find what we're looking for)
+- added some comments here and there (again ;p)
+
 11/05/2005 - mcummings makes weird changes
 
 - cleaned up calls to merge, added -p,-a,-n,-u flags to respective portions


-- 
gentoo-perl@g.o mailing list

Navigation:
Lists: gentoo-perl: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
Sorry for the spam
Next by thread:
SVN - new things
Previous by date:
Re: Sorry for the spam
Next by date:
SVN - new things


Updated Jun 17, 2009

Summary: Archive of the gentoo-perl mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.