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
A Way to Export Only Specific Symbols At Compile Time #5304
Comments
From @zoffixznetCurrently, there seems to be no easy way to import only specific symbols from a module *at compile time*. For example, if I want to use a module that exports a whole ton of functions but I only one just one, I have to write something complicated like this: need Test; This difficulty will result in many programmers trashing their namespaces out of convenience, resulting in hard-to-find bugs, especially when newer version of `use`d module introduces new subs. I propose we create another reserved import tag :SYM that will take a list of SYMbols we want to import, eg: use Test :SYM<&is &ok>; Although I'm ignorant of the implementation of the :ALL tag, I'd think implementing :SYM would be similar (you'd just grep for wanted symbols). Relevant IRC conversation: http://irclog.perlgeek.de/perl6/2016-05-07#i_12446098 |
From @zoffixznetTo add: pmichaud pointed out on IRC that S11 already defines a way to export symbols: https://rt-archive.perl.org/perl6//Public/Bug/Display.html?id=128090 However, that doesn't seem to work unless the module *author* defines extra EXPORT sub, which puts the feature out of the module user's control: <ZoffixWin> m: use Test <&is>; say is 2, 2 So now, I don't know if a proposed :SYM is needed or something needs to be improved with the `is export` trait. |
From @LLFournSomething like this has also passed through my head. What about use Test :ALL<&is &ok> or use Test :SOME-TAG<&foo &bar>. so you can filter out what you want with arguments to the tag. This seems Zoffix++ for bringing this up. also, I think that require could be adapted to work like this. Right now require Test <&is &ok>, :SOME-TAG<&foo &bar>; I think it's a good feature and importing would be much more consistent. LL On Sat, May 7, 2016 at 11:12 AM Zoffix Znet <perl6-bugs-followup@perl.org>
|
The RT System itself - Status changed from 'new' to 'open' |
From @zoffixznetThere was a comment on IRC from someone who doesn't have an account (http://irclog.perlgeek.de/perl6/2016-06-30#i_12762654 ): use Module :ONLY<foo bar baz>; I do like :ONLY more than my original :SYM |
From @zoffixznetOn Thu, 30 Jun 2016 05:12:09 -0700, cpan@zoffix.com wrote:
Just got bitten by this in real-life code: zostay/raku-DOM-Tiny#5 A module was overly lavish with its exports, exporting symbol `Text` (something I've no use for), which conflicted with `Text` namespace from another module I was trying to load. Not having a way to prevent those exports, I had to wrap the module into another module of my own making. |
Migrated from rt.perl.org#128090 (status was 'open')
Searchable as RT128090$
The text was updated successfully, but these errors were encountered: