pkgsrc-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
pkg/46785: pkgdep: Eliminate use of undefined variable and deprecated getopts.pl
>Number: 46785
>Category: pkg
>Synopsis: pkgdep: Eliminate use of undefined variable and deprecated
>getopts.pl
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: pkg-manager
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Wed Aug 08 10:15:01 +0000 2012
>Originator: Moritz Wilhelmy
>Release: NetBSD 6.0_BETA2, pkgsrc-current
>Organization:
Fictional Enterprises Ltd
>Environment:
System: NetBSD fenrir.wzff.de 6.0_BETA2 NetBSD 6.0_BETA2 (GENERIC) i386
Architecture: i386
Machine: i386
/usr/pkgsrc/pkgtools/pkgdep/files/pkgdep.pl:
$NetBSD: pkgdep.pl,v 1.3 2011/05/23 08:28:42 cheusov Exp $
$indexfile: $
>Description:
This patch converts pkgdep to use Getopt::Std, which seems to be the
de-facto way of parsing options in Perl 5. Previously, the Perl 4
'getopts.pl' was used, which was deprecated by the perl developers and
scheduled for removal for the next release.
The $VERSION variable was introduced and usage_and_exit was renamed
HELP_MESSAGE, because perl uses these for --help and --version output.
Also, it spews warnings because $pkgdir{$_} in line 166 is used
unconditionally, after it is checked for being defined, which is also
fixed by the patch below.
>How-To-Repeat:
Run pkgdep.pl in Perl 5.14.2, observe it warning about deprecation of
getopts.pl and spew warnings about $pkgdir{$_} being used undefined.
>Fix:
Index: files/pkgdep.pl
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkgdep/files/pkgdep.pl,v
retrieving revision 1.3
diff -u -p -r1.3 pkgdep.pl
--- files/pkgdep.pl 23 May 2011 08:28:42 -0000 1.3
+++ files/pkgdep.pl 8 Aug 2012 09:58:59 -0000
@@ -1,14 +1,15 @@
#!/usr/bin/env perl
# $NetBSD: pkgdep.pl,v 1.3 2011/05/23 08:28:42 cheusov Exp $
-require 'getopts.pl';
+use Getopt::Std;
use strict;
$^W=1;
$|=1;
-
-use vars qw($opt_I $opt_h $opt_e $opt_r $opt_v);
+use vars qw($opt_I $opt_h $opt_e $opt_r $opt_v $VERSION);
+$VERSION = '$NetBSD$';
+$Getopt::Std::STANDARD_HELP_VERSION = 1;
my (%pkgdir, %builddeps, %rundeps, %buildreqd, %runreqd, %printed);
-my ($indexfile) = "@PKGSRCDIR@/INDEX";
+my ($indexfile) = '@PKGSRCDIR@/INDEX';
my ($package, $match_pkgs);
my (%node, %arrow, $home_level);
my(%color);
@@ -16,10 +17,10 @@ $color{"D"} = "black";
$color{"B"} = "blue";
$color{"R"} = "red";
-if (!&Getopts('I:herv') || $opt_h) {&usage_and_exit;}
+&HELP_MESSAGE if !&getopts('I:herv') || $opt_h;
if (defined($opt_I)) {$indexfile = $opt_I;}
$package = shift;
-if (!defined($package)) {&usage_and_exit;}
+&HELP_MESSAGE if !defined($package);
open(INDEX, $indexfile) || die "$indexfile: $!\n";
while (<INDEX>) {
@@ -111,7 +112,7 @@ if (!defined($opt_v)) {
print "}\n";
}
-sub usage_and_exit {
+sub HELP_MESSAGE {
print <<EOF;
Usage: pkgdep [opts] package
-I INDEX file path (default: $indexfile)
@@ -161,8 +162,12 @@ sub printdeps {
print "\t$depname depends on:\n";
if (defined($deps{$pkg}) && $deps{$pkg} ne "") {
for (sort split(/ /, $deps{$pkg})) {
- if (!defined($pkgdir{$_})) {$_ = &searchpkg($_);}
- print "\t\t$_ [$pkgdir{$_}]\n";
+ if (!defined($pkgdir{$_})) {
+ $_ = &searchpkg($_);
+ print "\t\t$_\n"
+ } else {
+ print "\t\t$_ [$pkgdir{$_}]\n";
+ }
if ($opt_r) {@rpkg = (@rpkg, $_);}
}
} else {
Home |
Main Index |
Thread Index |
Old Index