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

Documentation patch for -M #16909

Open
p5pRT opened this issue Mar 27, 2019 · 6 comments
Open

Documentation patch for -M #16909

p5pRT opened this issue Mar 27, 2019 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 27, 2019

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

Searchable as RT133961$

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2019

From book@cpan.org

Here's a tiny documentation patch for -M.

I found this while and reading `perlrun` and exploring the possibilities
of `-M5;some-code` as a way to insert code before the loop when used in
combination with -n and -p (book/perlsecret#16).

  $ perl -MO=Deparse '-M5;insert_code_here()' -pe 1
  sub BEGIN {
  require 5;
  ()
  }
  insert_code_here();
  LINE​: while (defined($_ = readline ARGV)) {
  '???';
  }
  continue {
  die "-p destination​: $!\n" unless print $_;
  }
  -e syntax OK

Feel free to reword it as needed.

--
Philippe Bruhat (BooK)

Destroy the little and you destroy the large.
  (Moral from Groo The Wanderer #55 (Epic))

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2019

From book@cpan.org

0001-Document-a-way-to-perform-use-Module-VERSION-LIST-on.patch
From 832c0a61e398ca47fc96eed3573c061ff8ba880d Mon Sep 17 00:00:00 2001
From: "Philippe Bruhat (BooK)" <book@cpan.org>
Date: Wed, 27 Mar 2019 09:00:24 +0100
Subject: [PATCH] Document a way to perform `use Module VERSION LIST` on the
 command-line

The `split(/,/,q{foo,bar})` seems to still happen.

This is the currently documented case:

    $ perl -MO=Deparse '-MList::Util=any,all' -e1
    use List::Util (split(/,/, 'any,all', 0));
    '???';
    -e syntax OK

And these work too (and the split on comma also happens somehow):

    $ perl -MO=Deparse '-MList::Util any,all' -e1
    use List::Util ('any', 'all');
    '???';
    -e syntax OK

    $ perl -MO=Deparse '-MList::Util 1.5' -e1
    use List::Util 1.5;
    '???';
    -e syntax OK

    $ perl -MO=Deparse '-MList::Util 1.5 any,all' -e1
    use List::Util 1.5 ('any', 'all');
    '???';
    -e syntax OK
---
 pod/perlrun.pod | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/pod/perlrun.pod b/pod/perlrun.pod
index 77660ef17d..4855c29d81 100644
--- a/pod/perlrun.pod
+++ b/pod/perlrun.pod
@@ -692,6 +692,11 @@ is that B<-MI<MODULE>=number> never does a version check,
 unless C<I<MODULE>::import()> itself is set up to do a version check, which
 could happen for example if I<MODULE> inherits from L<Exporter>.
 
+However, it should be noted that since the syntax C<'-MI<MODULE foo,bar>'>
+shown above will generate C<use MODULE ('foo', 'bar')>, it's possible
+to do a version check using C<'-MI<MODULE VERSION foo,bar>'>, which will
+generate C<use MODULE VERSION ('foo', 'bar')>.
+
 =item B<-n>
 X<-n>
 
-- 
2.20.1

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2019

From @jkeenan

On Wed, 27 Mar 2019 08​:56​:54 GMT, book wrote​:

Here's a tiny documentation patch for -M.

I found this while and reading `perlrun` and exploring the possibilities
of `-M5;some-code` as a way to insert code before the loop when used in
combination with -n and -p (book/perlsecret#16).

$ perl \-MO=Deparse '\-M5;insert\_code\_here\(\)' \-pe 1
sub BEGIN \{
    require 5;
    \(\)
\}
insert\_code\_here\(\);
LINE&#8203;: while \(defined\($\_ = readline ARGV\)\) \{
    '???';
\}
continue \{
    die "\-p destination&#8203;: $\!\\n" unless print $\_;
\}
\-e syntax OK

Feel free to reword it as needed.

If we accept the patch, then this becomes a feature which we have to support going forward. Do we want to do that? Should we?

Thank you very much.
--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2019

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

@p5pRT
Copy link
Author

p5pRT commented Apr 24, 2019

From book@cpan.org

On Wed, 27 Mar 2019 05​:24​:28 -0700, jkeenan wrote​:

If we accept the patch, then this becomes a feature which we have to
support going forward. Do we want to do that? Should we?

My understanding of many of the command-line operators like -p, -n, -e
and others is that they basically construct a string that ends up being
eval'ed. This is a particularly stable part of Perl.

This powers the Eskimo Greeting secret operator `}{` and makes weird
things like `perl -pe '11..&'` (exposed back in 2001) still work today.

https://metacpan.org/pod/perlsecret#Eskimo-greeting
https://www.nntp.perl.org/group/perl.fwp/2001/12/msg813.html
http​://web.archive.org/web/20020715001632/http​://use.perl.org/~pdcawley/journal/1474

-- BooK

@jkeenan
Copy link
Contributor

jkeenan commented Jul 10, 2022

From book@cpan.org

On Wed, 27 Mar 2019 05​:24​:28 -0700, jkeenan wrote​:

If we accept the patch, then this becomes a feature which we have to
support going forward. Do we want to do that? Should we?

My understanding of many of the command-line operators like -p, -n, -e and others is that they basically construct a string that ends up being eval'ed. This is a particularly stable part of Perl.

This powers the Eskimo Greeting secret operator }{ and makes weird things like perl -pe '11..&' (exposed back in 2001) still work today.

https://metacpan.org/pod/perlsecret#Eskimo-greeting https://www.nntp.perl.org/group/perl.fwp/2001/12/msg813.html http​://web.archive.org/web/20020715001632/http​://use.perl.org/~pdcawley/journal/1474

-- BooK

@book, if you want to move this patch forward, could you file a pull request?

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

4 participants