develooper Front page | perl.perl6.users | Postings from August 2020

Re: Re-exporting modules that export operators...

Thread Previous
From:
Stuart Hungerford
Date:
August 16, 2020 03:58
Subject:
Re: Re-exporting modules that export operators...
Message ID:
CAG+kMrHg4TNnHjQx1tPz_8GU7FgNCL3Vg1_CEnSFUGA42ZvBEg@mail.gmail.com
On Sun, Aug 16, 2020 at 9:03 AM Ralph Mellor <ralphdjmellor@gmail.com> wrote:

> The SO you quote includes an operator. So that's not the problem.
>
> The SO is written by jnthn. It doesn't get more authoritative than that.

That's good to know, although for me the difference between it working
and not working (with that error) was the presence of an exported
infix operator. I can see that may be different with different
versions of Rakudo and different platforms etc.

> [...]
> Your export code is attempting to export `%?LANG`, but that already
> exists in every lexical scope. (`%?LANG`:is the language braid -- the
> dictionary of sub-languages that collectively constitute the Raku language.)
>
> So don't do that.
>
> In the SO jnthn demonstrates stripping out `$_`. You need to also strip
> out any other lexicals that you don't mean to export. So use a `say` to
> see what lexicals you're currently exporting and then grep out any that
> you don't mean to export.
>
> Perhaps share your code if you can't get it to work.

I also found I couldn't use the technique transitively (i.e.
sub-preludes) so using the approach you describe here I ended up with:

sub EXPORT() {{

  use Project::SubPrelude1;
  use Project::SubPrelude2;
  # etc

  ::.pairs.grep(*.key ∉ ('$_', '%?LANG', '$*DISPATCHER')).Map;
}}

Thanks for the feedback.

Stu

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About