Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFE: enhancement of corelist script #16444

Open
p5pRT opened this issue Feb 28, 2018 · 5 comments
Open

RFE: enhancement of corelist script #16444

p5pRT opened this issue Feb 28, 2018 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 28, 2018

Migrated from rt.perl.org#132923 (status was 'open')

Searchable as RT132923$

@p5pRT
Copy link
Author

p5pRT commented Feb 28, 2018

From perl-diddler@tlinx.org

Created by perl-diddler@tlinx.org

I would like to propose an enhancement for the 'corelist'
command that comes with the CORE module 'Modules​::CoreList'

Proposal is to add switch(es) '-t|--test' that would
act like '-v $] <MODNAME>' with the difference that
instead of telling you what version of the module is
in the given version of perl ($]=current), it returns
status via the script exit value​: 0 if present, 1 if not.

This gives an easy way to test if a module is present in
CORE vs. need to be fetched from CPAN.

I threw together a sample patch against 5.26.0
for the 'corelist' program for my own use, and thought
it would be a good feature addition for the module in
CORE.

=====================

Inline Patch
--- corelist.orig	2017-09-26 10:05:01.000000000 -0700
+++ corelist	2018-02-28 13:38:09.750160500 -0800
@@ -14,6 +14,7 @@
 =head1 SYNOPSIS
 
    corelist -v
+   corelist -t [ <ModuleName ]
    corelist [-a|-d] <ModuleName> | /<ModuleRegex>/ [<ModuleVersion>] ...
    corelist [-v <PerlVersion>] [ <ModuleName> | /<ModuleRegex>/ ] ...
    corelist [-r <PerlVersion>] ...
@@ -145,7 +146,8 @@
 
 GetOptions(
     \%Opts,
-    qw[ help|?! man! r|release:s v|version:s a! d diff|D feature|f u|upstream ]
+    qw[ help|?! man! r|release:s v|version:s a! d diff|D feature|f u|upstream 
+	t|test a!]
 );
 
 pod2usage(1) if $Opts{help};
@@ -175,6 +177,8 @@
     exit 0;
 }
 
+$Opts{v}=$] if exists($Opts{t}) ? 1 : 0;
+
 if(exists $Opts{v} ){
     if( !$Opts{v} ) {
	 print "\nModule::CoreList has info on the following perl versions:\n";
@@ -278,6 +282,8 @@
     pod2usage(0);
 }
 
+my $exit_status=0;
+
 while (@ARGV) {
	my ($mod, $ver);
	if ($ARGV[0] =~ /=/) {
@@ -288,7 +294,7 @@
	}
 
	if ($mod !~ m|^/(.*)/([imosx]*)$|) { # not a regex
-	    module_version($mod,$ver);
+	    ++$exit_status if module_version($mod,$ver);
	} else {
	    my $re;
	    eval { $re = $2 ? qr/(?$2)($1)/ : qr/$1/; }; # trap exceptions while building regex
@@ -310,7 +316,7 @@
	}
 }
 
-exit();
+exit($exit_status);
 
 sub module_version {
     my($mod,$ver) = @_;
@@ -319,8 +325,9 @@
	my $numeric_v = numify_version($Opts{v});
	my $version_hash = Module::CoreList->find_version($numeric_v);
	if ($version_hash) {
+	    return $version_hash->{$mod} ? 0 : 1 if $Opts{t};
	    print $mod, " ", $version_hash->{$mod} || 'undef', "\n";
-	    return;
+	    return 0;
	}
	else { die "Shouldn't happen" }
     }
=====================

The above is the simple case of checking for the module
in the running vesrion of perl

Thanks,
Linda Walsh

Perl Info

Flags:
    category=core
    severity=wishlist

Site configuration information for perl 5.26.0:

Configured by law at Sat Oct  7 15:42:15 PDT 2017.

Summary of my perl5 (revision 5 version 26 subversion 0) configuration:
   
  Platform:
    osname=linux
    osvers=4.13.5-isht-van
    archname=x86_64-linux-thread-multi-ld
    uname='linux ishtar 4.13.5-isht-van #2 smp preempt thu oct 5 15:26:06 pdt 2017 x86_64 gnulinux '
    config_args=''
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=define
    usemymalloc=n
    default_inc_excludes_dot=undef
    bincompat5005=undef
  Compiler:
    cc='gcc'
    ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-explicit -I/home/perl/perl-5.26.0/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    optimize='-O2'
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-explicit -I/home/perl/perl-5.26.0/include'
    ccversion=''
    gccversion='7.1.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='long double'
    nvsize=16
    Off_t='off_t'
    lseeksize=8
    alignbytes=16
    prototype=define
  Linker and Libraries:
    ld='gcc'
    ldflags ='-fstack-protector-explicit -I/home/perl/perl-5.26.0/include'
    libpth=/usr/local/lib //lib /usr/lib64/gcc/x86_64-pc-linux-gnu/7/include-fixed /usr/lib /lib/../lib64 /usr/lib/../lib64 /lib /lib64 /usr/lib64
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.19.so
    so=so
    useshrplib=true
    libperl=libperl-5.26.0.so
    gnulibc_version='2.19'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E -Wl,-rpath,/home/perl/perl-5.26.0/usr/lib/5.26.0/x86_64-linux-thread-multi-ld/CORE'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2'



@INC for perl 5.26.0:
    /home/law/bin/lib
    /home/perl/perl-5.26.0/usr/lib/site_perl/5.26.0/x86_64-linux-thread-multi-ld
    /home/perl/perl-5.26.0/usr/lib/site_perl/5.26.0
    /home/perl/perl-5.26.0/usr/lib/5.26.0/x86_64-linux-thread-multi-ld
    /home/perl/perl-5.26.0/usr/lib/5.26.0


Environment for perl 5.26.0:
    HOME=/home/law
    LANG (unset)
    LANGUAGE (unset)
    LC_COLLATE=C
    LC_CTYPE=en_US.UTF-8
    LC_MESSAGES=C
    LC_MONETARY=C
    LC_NUMERIC=C
    LC_TIME=C
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/perl/perl-5.26.0:.:/sbin:/home/law/bin/lib:/home/law/bin:/usr/local/bin:/usr/bin:/bin:/opt/kde3/bin:/usr/sbin:/etc/local/func_lib:/home/law/lib
    PERL5OPT=-Mutf8 -CSA -I/home/law/bin/lib
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

From @jkeenan

On Wed, 28 Feb 2018 22​:27​:41 GMT, LAWalsh wrote​:

This is a bug report for perl from perl-diddler@​tlinx.org,
generated with the help of perlbug 1.40 running under perl 5.26.0.

-----------------------------------------------------------------
[Please describe your issue here]

I would like to propose an enhancement for the 'corelist'
command that comes with the CORE module 'Modules​::CoreList'

Proposal is to add switch(es) '-t|--test' that would
act like '-v $] <MODNAME>' with the difference that
instead of telling you what version of the module is
in the given version of perl ($]=current), it returns
status via the script exit value​: 0 if present, 1 if not.

This gives an easy way to test if a module is present in
CORE vs. need to be fetched from CPAN.

I threw together a sample patch against 5.26.0
for the 'corelist' program for my own use, and thought
it would be a good feature addition for the module in
CORE.

=====================
--- corelist.orig 2017-09-26 10​:05​:01.000000000 -0700
+++ corelist 2018-02-28 13​:38​:09.750160500 -0800
@​@​ -14,6 +14,7 @​@​
=head1 SYNOPSIS

corelist -v
+ corelist -t [ <ModuleName ]
corelist [-a|-d] <ModuleName> | /<ModuleRegex>/ [<ModuleVersion>] ...
corelist [-v <PerlVersion>] [ <ModuleName> | /<ModuleRegex>/ ] ...
corelist [-r <PerlVersion>] ...
@​@​ -145,7 +146,8 @​@​

GetOptions(
\%Opts,
- qw[ help|?! man! r|release​:s v|version​:s a! d diff|D feature|f
u|upstream ]
+ qw[ help|?! man! r|release​:s v|version​:s a! d diff|D feature|f
u|upstream
+ t|test a!]
);

pod2usage(1) if $Opts{help};
@​@​ -175,6 +177,8 @​@​
exit 0;
}

+$Opts{v}=$] if exists($Opts{t}) ? 1 : 0;
+
if(exists $Opts{v} ){
if( !$Opts{v} ) {
print "\nModule​::CoreList has info on the following perl
versions​:\n";
@​@​ -278,6 +282,8 @​@​
pod2usage(0);
}

+my $exit_status=0;
+
while (@​ARGV) {
my ($mod, $ver);
if ($ARGV[0] =~ /=/) {
@​@​ -288,7 +294,7 @​@​
}

if ($mod !~ m|^/(.*)/([imosx]*)$|) { # not a regex
- module_version($mod,$ver);
+ ++$exit_status if module_version($mod,$ver);
} else {
my $re;
eval { $re = $2 ? qr/(?$2)($1)/ : qr/$1/; }; # trap exceptions
while building regex
@​@​ -310,7 +316,7 @​@​
}
}

-exit();
+exit($exit_status);

sub module_version {
my($mod,$ver) = @​_;
@​@​ -319,8 +325,9 @​@​
my $numeric_v = numify_version($Opts{v});
my $version_hash = Module​::CoreList->find_version($numeric_v);
if ($version_hash) {
+ return $version_hash->{$mod} ? 0 : 1 if $Opts{t};
print $mod, " ", $version_hash->{$mod} || 'undef', "\n";
- return;
+ return 0;
}
else { die "Shouldn't happen" }
}

The above is the simple case of checking for the module
in the running vesrion of perl

Thanks,
Linda Walsh

I think the maintainer of Module​::CoreList should have first crack at evaluating this request.

However, I would recommend the following​:

* Pull the patch against the version of Module​::CoreList in Perl 5 blead, i.e., in a checkout from our git repository.

* Add tests for this feature in dist/Module-CoreList/t/.

* Attach the patch to this RT (or to your email response), i.e., don't inline the patch.

These steps will make the patch easier to evaluate.

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

From @Grinnz

On Tue, Sep 4, 2018 at 11​:56 AM James E Keenan via RT <
perlbug-followup@​perl.org> wrote​:

I would like to propose an enhancement for the 'corelist'
command that comes with the CORE module 'Modules​::CoreList'

Proposal is to add switch(es) '-t|--test' that would
act like '-v $] <MODNAME>' with the difference that
instead of telling you what version of the module is
in the given version of perl ($]=current), it returns
status via the script exit value​: 0 if present, 1 if not.

This gives an easy way to test if a module is present in
CORE vs. need to be fetched from CPAN.

I'll also note that, separate from whether the maintainer decides to add
this option, there is an easy alternative​:

perl -MModule​::CoreList -E'say Module​::CoreList​::is_core(shift) ? 1 : 0'
Foo​::Bar

perl -MModule​::CoreList -E'say Module​::CoreList​::is_core(shift, undef,
shift) ? 1 : 0' Foo​::Bar 5.008001

-Dan

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2018

From perl-diddler@tlinx.org

On 9/4/2018 9​:04 AM, Dan Book via RT wrote​:

On Tue, Sep 4, 2018 at 11​:56 AM James E Keenan via RT <
perlbug-followup@​perl.org> wrote​:

I would like to propose an enhancement for the 'corelist'
command that comes with the CORE module 'Modules​::CoreList'

Proposal is to add switch(es) '-t|--test' that would
act like '-v $] <MODNAME>' with the difference that
instead of telling you what version of the module is
in the given version of perl ($]=current), it returns
status via the script exit value​: 0 if present, 1 if not.

This gives an easy way to test if a module is present in
CORE vs. need to be fetched from CPAN.

I'll also note that, separate from whether the maintainer decides to add
this option, there is an easy alternative​:

perl -MModule​::CoreList -E'say Module​::CoreList​::is_core(shift) ? 1 : 0'
Foo​::Bar

perl -MModule​::CoreList -E'say Module​::CoreList​::is_core(shift, undef,
shift) ? 1 : 0' Foo​::Bar 5.008001

Easy is in the eye of the beholder. *ahem*. I wouldn't exactly call that
a user friendly interface....*sigh*​: i.e. I might be able to use it for
myself, but it's hardly a solution i'd want to present to a non-perl expert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants