I need one liner module import help

Hi All,

I need one liner help importing a module sub

This works:

perl6 -e 'use lib "/home/linuxutil/p6lib"; use PrintColors :PrintBlue; 
PrintBlue( "Blue\n" );'

Blue



This does not:

perl6 -I /home/linuxutil/p6lib -M "PrintColors :PrintBlue" -e 
'PrintBlue( "Blue\n" );'

Could not find PrintColors :PrintBlue at line 1 in:



What did I do wrong, this time?

Many thanks,
-T
0
perl6
6/11/2019 10:39:55 PM
perl.perl6.users 1188 articles. 0 followers. Follow

9 Replies
25 Views

Similar Articles

[PageSpeed] 18


> On Jun 11, 2019, at 5:39 PM, ToddAndMargo via perl6-users =
<perl6-users@perl.org> wrote:
>=20
> Hi All,
>=20
> I need one liner help importing a module sub
>=20
> This works:
>=20
> perl6 -e 'use lib "/home/linuxutil/p6lib"; use PrintColors :PrintBlue; =
PrintBlue( "Blue\n" );'
>=20
> Blue
>=20
>=20
>=20
> This does not:
>=20
> perl6 -I /home/linuxutil/p6lib -M "PrintColors :PrintBlue" -e =
'PrintBlue( "Blue\n" );'
>=20
> Could not find PrintColors :PrintBlue at line 1 in:
>=20
>=20
>=20
> What did I do wrong, this time?
>=20
> Many thanks,
> -T


Results of my research:

In Perl 5, the code to use a module *and* select its imports,
    use This::Module qw<foo bar>;
can rephrased in a one-liner as:
    -MThis::Module=3Dfoo,bar

The Perl 6 docs show a one-liner option for `use`:
    -M This::Module
, but shows no version that lets you select the import.

In src/Perl6/World.nqp, method do_pragma_or_load_module has code to =
start 'Performing imports' right after loading the module.
(you can see the progress by setting RAKUDO_MODULE_DEBUG, as in =
`RAKUDO_MODULE_DEBUG=3D1 perl6 -MTest -e 'say 42'`)
I see no tests exercising this part of the code, and when I experiment, =
any deviation I can think to try from `-M FooModule` results in failure =
in self.load_module, as whatever should recognize some divider between =
ModuleName and ModuleImportList fails to do so, so `-MFoo=3DBar` tries =
to load a module with the 7-char name "Foo=3DBar".

Based on the call to `self.do_import`, I think that Rakudo is intended =
to support something like `-MThis::Module=3Dfoo,bar`, but I cannot tell =
what exact form the import separator should take, so cannot tell if we =
are just missing the correct syntax, or if there is a bug in Rakudo.

Either way, there are docs and tests that need to be added.

EOUTOFTIME, this email stands alone, no bugs filed.

=E2=80=94=20
Bruce Gray (Util of PerlMonks)
0
robertbrucegray3
6/12/2019 4:11:06 AM
On 6/11/19 9:11 PM, Bruce Gray wrote:
>=20
>=20
>> On Jun 11, 2019, at 5:39 PM, ToddAndMargo via perl6-users <perl6-users=
@perl.org> wrote:
>>
>> Hi All,
>>
>> I need one liner help importing a module sub
>>
>> This works:
>>
>> perl6 -e 'use lib "/home/linuxutil/p6lib"; use PrintColors :PrintBlue;=
 PrintBlue( "Blue\n" );'
>>
>> Blue
>>
>>
>>
>> This does not:
>>
>> perl6 -I /home/linuxutil/p6lib -M "PrintColors :PrintBlue" -e 'PrintBl=
ue( "Blue\n" );'
>>
>> Could not find PrintColors :PrintBlue at line 1 in:
>>
>>
>>
>> What did I do wrong, this time?
>>
>> Many thanks,
>> -T
>=20
>=20
> Results of my research:
>=20
> In Perl 5, the code to use a module *and* select its imports,
>      use This::Module qw<foo bar>;
> can rephrased in a one-liner as:
>      -MThis::Module=3Dfoo,bar
>=20
> The Perl 6 docs show a one-liner option for `use`:
>      -M This::Module
> , but shows no version that lets you select the import.
>=20
> In src/Perl6/World.nqp, method do_pragma_or_load_module has code to sta=
rt 'Performing imports' right after loading the module.
> (you can see the progress by setting RAKUDO_MODULE_DEBUG, as in `RAKUDO=
_MODULE_DEBUG=3D1 perl6 -MTest -e 'say 42'`)
> I see no tests exercising this part of the code, and when I experiment,=
 any deviation I can think to try from `-M FooModule` results in failure =
in self.load_module, as whatever should recognize some divider between Mo=
duleName and ModuleImportList fails to do so, so `-MFoo=3DBar` tries to l=
oad a module with the 7-char name "Foo=3DBar".
>=20
> Based on the call to `self.do_import`, I think that Rakudo is intended =
to support something like `-MThis::Module=3Dfoo,bar`, but I cannot tell w=
hat exact form the import separator should take, so cannot tell if we are=
 just missing the correct syntax, or if there is a bug in Rakudo.
>=20
> Either way, there are docs and tests that need to be added.
>=20
> EOUTOFTIME, this email stands alone, no bugs filed.
>=20
> =E2=80=94
> Bruce Gray (Util of PerlMonks)
>=20


$ perl6 -I /home/linuxutil/p6lib -M PrintColors::PrintBlue -e=20
'PrintBlue( "Blue\n" );'
=3D=3D=3DSORRY!=3D=3D=3D
Could not find PrintColors::PrintBlue at line 1 in:
0
perl6
6/12/2019 6:22:37 AM

> On Jun 12, 2019, at 1:22 AM, ToddAndMargo via perl6-users =
<perl6-users@perl.org> wrote:
=E2=80=94snip--
> $ perl6 -I /home/linuxutil/p6lib -M PrintColors::PrintBlue -e =
'PrintBlue( "Blue\n" );'
> =3D=3D=3DSORRY!=3D=3D=3D
> Could not find PrintColors::PrintBlue at line 1 in:

I see that I introduced a point of confusion.

In Perl 5 and Perl 6, double-colons are a namespace separator.
The module Audio::Taglib::Simple is a single module, but can be thought =
of as "the Simple module, of possibly-a-bunch-of Taglib modules, of the =
overall family of Audio modules".
In the same way, my name is "Bruce Gray" and I am an individual, but can =
be thought of as "the Bruce person, of the Gray family".
This is all less evident when browsing modules.perl6.org than Perl 5's =
CPAN, because the CPAN sheriffs pressure its module authors to use =
multi-level naming, and modules.perl6.org is more of the Wild West where =
single-level naming (Balidor, CCChart, ECMA262Regex, ScaleVec) is =
common.
( My talk on variable namespaces is "The Why of My()": =
https://www.youtube.com/watch?v=3DSA4mUs3Ro98 )

All that to say, that of all the ways Perl 6 or Rakudo might intend us =
to indicate the arguments to a `use` statement in a one-liner, I am sure =
that way cannot ever be with a double-colon.
I was using double-colon in my made-up module names just because I =
thought it would be clearer; to my Perl 5 eyes, Foo::Bar::Baz is always =
a module name.

The fact that a single leading colon designates a import tag (or =
"group") further clouds the issue.

--=20
Bruce Gray (Util of PerlMonks)
0
robertbrucegray3
6/12/2019 1:43:12 PM
Hi Bruce,

This has to do with the way I am importing subs from modules.

When importing subs, I like to declare which subs I
am importing.  Otherwise my code is a nightmare to maintain.
"Where the heck did that subs comes from? Is its a system
subs or ...."


For instance, in  Perl 5:

     use Term::ANSIColor qw ( BOLD BLUE RED GREEN RESET );

imports "BOLD BLUE RED GREEN RESET".


Perl 6 has improved on this with selective importing and exporting.
The ":" is part of the tag:

https://docs.perl6.org/language/modules#Exporting_and_selective_importing

For instance:

PrintColors.pm6 exports with:

     sub PrintBlue  ( **@args ) is export( :PrintBlue )  { print 
color('bold'), color('blue'),  |@args, color('reset'); }

The tag is `is export( :PrintBlue )`


And imports with:

      use PrintColors :PrintRed, :PrintGreen, :PrintBlue, :PrintErr, 
:PrintRedErr, :PrintGreenErr, :PrintBlueErr;

What I am after is a way to run a one liner with
this type of export using the "-M" switch".

        perl6 -I /home/linuxutil/p6lib -M "PrintColors :PrintBlue" -e 
'PrintBlue( "Blue\n" );'

        Could not find PrintColors :PrintBlue at line 1 in:

-T
0
perl6
6/12/2019 8:56:55 PM
--000000000000fe7a3d058b276b31
Content-Type: text/plain; charset="UTF-8"

On Wed, Jun 12, 2019 at 16:12 ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi Bruce,
>
> This has to do with the way I am importing subs from modules.
>
> When importing subs, I like to declare which subs I
> am importing.  Otherwise my code is a nightmare to maintain.
> "Where the heck did that subs comes from? Is its a system
> subs or ...."
>
>
> For instance, in  Perl 5:
>
>      use Term::ANSIColor qw ( BOLD BLUE RED GREEN RESET );
>
> imports "BOLD BLUE RED GREEN RESET".
>
>
> Perl 6 has improved on this with selective importing and exporting.
> The ":" is part of the tag:
>
> https://docs.perl6.org/language/modules#Exporting_and_selective_importing
>
> For instance:
>
> PrintColors.pm6 exports with:
>
>      sub PrintBlue  ( **@args ) is export( :PrintBlue )  { print
> color('bold'), color('blue'),  |@args, color('reset'); }
>
> The tag is `is export( :PrintBlue )`
>
> And imports with:
>
>       use PrintColors :PrintRed, :PrintGreen, :PrintBlue, :PrintErr,
> :PrintRedErr, :PrintGreenErr, :PrintBlueErr;
>
> What I am after is a way to run a one liner with
> this type of export using the "-M" switch".


I think you will have to file a Rakudo issue.

-Tom

--000000000000fe7a3d058b276b31
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div><br></div><div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=
=3D"gmail_attr">On Wed, Jun 12, 2019 at 16:12 ToddAndMargo via perl6-users =
&lt;<a href=3D"mailto:perl6-users@perl.org">perl6-users@perl.org</a>&gt; wr=
ote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex">Hi Bruce,<br>
<br>
This has to do with the way I am importing subs from modules.<br>
<br>
When importing subs, I like to declare which subs I<br>
am importing.=C2=A0 Otherwise my code is a nightmare to maintain.<br>
&quot;Where the heck did that subs comes from? Is its a system<br>
subs or ....&quot;<br>
<br>
<br>
For instance, in=C2=A0 Perl 5:<br>
<br>
=C2=A0 =C2=A0 =C2=A0use Term::ANSIColor qw ( BOLD BLUE RED GREEN RESET );<b=
r>
<br>
imports &quot;BOLD BLUE RED GREEN RESET&quot;.<br>
<br>
<br>
Perl 6 has improved on this with selective importing and exporting.<br>
The &quot;:&quot; is part of the tag:<br>
<br>
<a href=3D"https://docs.perl6.org/language/modules#Exporting_and_selective_=
importing" rel=3D"noreferrer" target=3D"_blank">https://docs.perl6.org/lang=
uage/modules#Exporting_and_selective_importing</a><br>
<br>
For instance:<br>
<br>
PrintColors.pm6 exports with:<br>
<br>
=C2=A0 =C2=A0 =C2=A0sub PrintBlue=C2=A0 ( **@args ) is export( :PrintBlue )=
=C2=A0 { print <br>
color(&#39;bold&#39;), color(&#39;blue&#39;),=C2=A0 |@args, color(&#39;rese=
t&#39;); }<br>
<br>
The tag is `is export( :PrintBlue )`<br>
<br>
And imports with:<br>
<br>
=C2=A0 =C2=A0 =C2=A0 use PrintColors :PrintRed, :PrintGreen, :PrintBlue, :P=
rintErr, <br>
:PrintRedErr, :PrintGreenErr, :PrintBlueErr;<br>
<br>
What I am after is a way to run a one liner with<br>
this type of export using the &quot;-M&quot; switch&quot;.</blockquote><div=
 dir=3D"auto"><br></div><div dir=3D"auto">I think you will have to file a R=
akudo issue.</div><div dir=3D"auto"><br></div><div dir=3D"auto">-Tom</div><=
/div></div>

--000000000000fe7a3d058b276b31--
0
tom
6/12/2019 9:51:43 PM
On 6/12/19 2:51 PM, Tom Browder wrote:
> I think you will have to file a Rakudo issue.
> 

Do you have a link to them?
0
perl6
6/13/2019 12:11:05 AM
On 6/11/19 3:39 PM, ToddAndMargo via perl6-users wrote:
> This=C2=A0works:
>=20
> perl6 -e 'use lib "/home/linuxutil/p6lib"; use PrintColors :PrintBlue; =

> PrintBlue(=C2=A0"Blue\n"=C2=A0);'
>=20
> Blue
>=20

Just posted:

RFE: -M switch for selective imports
https://github.com/perl6/doc/issues/2852
0
perl6
6/13/2019 7:24:03 AM
--000000000000c9c87d058b309aec
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi,

El jue., 13 jun. 2019 a las 9:39, ToddAndMargo via perl6-users (<
perl6-users@perl.org>) escribi=C3=B3:

> On 6/11/19 3:39 PM, ToddAndMargo via perl6-users wrote:
> > This works:
> >
> > perl6 -e 'use lib "/home/linuxutil/p6lib"; use PrintColors :PrintBlue;
> > PrintBlue( "Blue\n" );'
> >
> > Blue
> >
>
> Just posted:
>
> RFE: -M switch for selective imports
> https://github.com/perl6/doc/issues/2852
>

I've already answered there, but anyway, as Tom says, it's better if you
file a Rakudo issue.

--=20
JJ

--000000000000c9c87d058b309aec
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi,<br></div><br><div class=3D"gmail_quote"><div dir=
=3D"ltr" class=3D"gmail_attr">El jue., 13 jun. 2019 a las 9:39, ToddAndMarg=
o via perl6-users (&lt;<a href=3D"mailto:perl6-users@perl.org">perl6-users@=
perl.org</a>&gt;) escribi=C3=B3:<br></div><blockquote class=3D"gmail_quote"=
 style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p=
adding-left:1ex">On 6/11/19 3:39 PM, ToddAndMargo via perl6-users wrote:<br=
>
&gt; This=C2=A0works:<br>
&gt; <br>
&gt; perl6 -e &#39;use lib &quot;/home/linuxutil/p6lib&quot;; use PrintColo=
rs :PrintBlue; <br>
&gt; PrintBlue(=C2=A0&quot;Blue\n&quot;=C2=A0);&#39;<br>
&gt; <br>
&gt; Blue<br>
&gt; <br>
<br>
Just posted:<br>
<br>
RFE: -M switch for selective imports<br>
<a href=3D"https://github.com/perl6/doc/issues/2852" rel=3D"noreferrer" tar=
get=3D"_blank">https://github.com/perl6/doc/issues/2852</a><br>
</blockquote></div><div><br></div><div>I&#39;ve already answered there, but=
 anyway, as Tom says, it&#39;s better if you file a Rakudo issue.<br></div>=
<br>-- <br><div dir=3D"ltr" class=3D"gmail_signature">JJ</div></div>

--000000000000c9c87d058b309aec--
0
jjmerelo
6/13/2019 8:49:03 AM
On 6/13/19 1:49 AM, JJ Merelo wrote:
> Hi,
>=20
> El jue., 13 jun. 2019 a las 9:39, ToddAndMargo via perl6-users=20
> (<perl6-users@perl.org <mailto:perl6-users@perl.org>>) escribi=C3=B3:
>=20
>     On 6/11/19 3:39 PM, ToddAndMargo via perl6-users wrote:
>      > This=C2=A0works:
>      >
>      > perl6 -e 'use lib "/home/linuxutil/p6lib"; use PrintColors
>     :PrintBlue;
>      > PrintBlue(=C2=A0"Blue\n"=C2=A0);'
>      >
>      > Blue
>      >
>=20
>     Just posted:
>=20
>     RFE: -M switch for selective imports
>     https://github.com/perl6/doc/issues/2852
>=20
>=20
> I've already answered there, but anyway, as Tom says, it's better if yo=
u=20
> file a Rakudo issue.
>=20
> --=20
> JJ


RFE: -M switch for selective imports
https://github.com/rakudo/rakudo/issues/2981
0
perl6
6/13/2019 9:35:36 AM
Reply: