Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How to get at perl's options in a program

by tobyink (Canon)
on Nov 06, 2012 at 22:49 UTC ( [id://1002593]=note: print w/replies, xml ) Need Help??


in reply to How to get at perl's options in a program

Mwahahaha!!! Insane crap...

{ package Devel::PL_origargv; use 5.008; use Inline C => q{ int _argc () { return PL_origargc; } char* _argv (int x) { return PL_origargv[x - 1]; } }; sub get { return _argc unless wantarray; map _argv($_), 1 .. _argc; } } print "ARG: $_\n" for Devel::PL_origargv->get;

Anyone think it's worth CPANning?

Update: Devel::PL_origargv is now on CPAN. I kept the ugly name with weird capitalisation and punctuation, reasoning that if you have to think carefully to remember how to type the module name, then it will make you think carefully before using it.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: How to get at perl's options in a program (submit)
by tye (Sage) on Nov 06, 2012 at 23:08 UTC

    Sure, put it on CPAN. But also turn it into a patch against Perl.

    - tye        

Re^2: How to get at perl's options in a program
by Hercynium (Hermit) on Dec 28, 2012 at 19:49 UTC

    Thanks, tobyink++!So much of your stuff has either ended up in my code and/or taught me new things I never knew about Perl, I feel I owe you a *case* of beer. Seriously, if we ever meet at a YAPC or Hackathon, I will honor that!

    While your module doesn't *quite* solve the problem I came here to research, it points me in the right direction. I've spent some time today groveling in the perl source and found a few more useful variables like that, for example PL_origenviron

    I'm working on a means of bootstrapping perl applications using a new perl installation on systems stuck with an old perl, but without needing to run or install external CPAN modules as root. In trying to make this as simple as possible, I have code that, if run with too old a version of perl, attempts to find a new-enough one, and re-execs the original command using the found perl. (Additionally, it will update a perl-version-specific local::lib using cpanm if one of {Makefile,Build}.PL are present, and add it to @INC). Unfortunately, it's a nasty combination of bash and perl, and I'd *love* to dispense with the bash all together.

    Now, I know this sort of thing can be "solved" using perlbrew, but unfortunately perlbrew has not worked out very well for the users & devs I am supporting. Also, they dislike having to keep a new installation of perl around for every project. (several are new to perl, and are giving me their time to help me deliver several projects for their groups. I feel I owe it to them to make using and hacking on on my code as comfortable as possible... so far, it's working - two have now expressed that they never knew Perl could be such a nice language to use!)

    Once I feel like I have good general solution, I will release whatever I can :)

Re^2: How to get at perl's options in a program
by Anonymous Monk on Apr 26, 2014 at 08:52 UTC

    FWIW, you should not use Inline inside a module, you end up with

    ./Devel-PL_origargv-0.003/_Inline/lib/auto/Devel/PL_origargv_a77c/PL_o +rigargv_a77c.dll
    which doesn't get installed, and and an empty
    ./Devel-PL_origargv-0.003/blib/lib/auto/Devel/PL_origargv/.exists
    and then every time someone uses the module, in the current directory, an _Inline/lib/auto/Devel/PL_origargv_a77c/PL_origargv_a77c.dll is built, every single time, instead of once during installation

      It's not built every single time. It's only rebuilt if it's missing or if there have been modifications to the .pm file since the last build. If you don't like it being built in the current working directory, then create a ~/.Inline directory.

      I'd happily accept a patch to XSify the module, but I'm not going to write that myself. It seems more effort than would be deserved by this silly little module.

      use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
        package Devel::PL_origargv; use strict; use warnings; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.004'; require DynaLoader; @Devel::PL_origargv::ISA = qw( Exporter DynaLoader); bootstrap Devel::PL_origargv; sub get { return _my_argc() unless wantarray; map _my_argv($_), 1 .. _my_argc(); } 1;

        #include "EXTERN.h" #include "perl.h" #include "XSUB.h" MODULE = Devel::PL_origargv PACKAGE = Devel::PL_origargv PROTOTYPES: DISABLE int _my_argc () CODE: RETVAL = PL_origargc; OUTPUT: RETVAL char * _my_argv (x) int x CODE: RETVAL = PL_origargv[x - 1]; OUTPUT: RETVAL

        I'd happily accept a patch to XSify the module, but I'm not going to write that myself. It seems more effort than would be deserved by this silly little module.

        Um, when you build it on your machine, copy the .xs files it generates, the end

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1002593]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-29 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found