Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: RFC: new.pm - a perl -e use/new shortener (default variable)

by LanX (Saint)
on Dec 24, 2016 at 13:04 UTC ( [id://1178462]=note: print w/replies, xml ) Need Help??


in reply to RFC: new.pm - a perl -e use/new shortener

I like this a lot, just one suggestion

> use new qw(My::Very::Long::Module x foo 42)

If conciseness is your goal,better try to make the variable name (here x) optional and default to something like $new or $obj or only $o.

Though I'm not sure about the best syntax for an optional var, probably something like

use new qw(My::Very::Long::Module>x foo 42)

Other options are | or * but any solution should play well with the -M option, ie shouldn't confuse the shell/CLI on various OSes.

update: untested

perl -Mnew=My::Very::Long::Module>x,foo,42

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: RFC: new.pm - a perl -e use/new shortener (default variable)
by Dallaylaen (Chaplain) on Dec 24, 2016 at 20:59 UTC
    A ">" would clash with shell metacharacters and require escaping. I'm thinking of something like
    x=My::Class:Name.method arg arg ....
    instead. Both x and method default to "new" if omitted, which is at least consistent with the module name.
      Hi

      > x=My::Class:Name.method arg arg

      I suppose you meant x=My::Class::Name.method arg arg with double colon after Class :)

      But apart of this, it looks good for me!

      I tested the call with -M and -m with a fake module which just print the args of the import() , using my oldest available perl(brew) version.

      $ perl -MNew=X=Y::Y::Y.meth,1,2,3 -e'print "$]\n"' New , X=Y::Y::Y.meth , 1 , 2 , 3 5.006002 $ perl -mNew=X=Y::Y::Y.meth,1,2,3 -e'print "$]\n"' New , X=Y::Y::Y.meth , 1 , 2 , 3 5.006002

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Log In?
Username:
Password:

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

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

    No recent polls found