user-pic

Yang Bo

Subscribe to feed Recent Actions from Yang Bo

  • Tim King commented on Long Import Lists (and available strategies for managing them)

    That's close, and it brings us part of the way there. But it only aliases during the compile phase. It's more akin to localized aliasing, because the aliasing disappears as soon as *A:: = $bak runs.

    For example:

    BEGIN {
        my $bak;
        *A:: = $bak;
        BEGIN {
            $bak = \%A::;
            *A:: = \%a::b::c::d::e::f::;
        }
        A::g();
        A->g();
    }
    

    This prints:

    I am a::b::c::d::e::f::g.
    I am A::g.
    

    ...because the call to A::g() is resolved at compile time, but the call to A->g() is resolved at runtime…

  • Tim King commented on Long Import Lists (and available strategies for managing them)

    However... (Thinking out loud here.) It might be possible to use this with another technique to achieve the desired effect.

    BEGIN {
        my $bak;
        *A:: = $bak;
        BEGIN {
            $bak = \%A::;
            *A:: = \%a::b::c::d::e::f::;
        }
        sub A {
            return 'a::b::c::d::e::f';
        }
    
    

    A::g();
    A->g();
    }

    That could also conceivably be done in a package.

    What am I missing?

  • Toby Inkster commented on Long Import Lists (and available strategies for managing them)

    If the module uses Exporter::Tiny, then you'll get your "Export a hash of symbols" solution for free.

    For example, List::MoreUtils uses Exporter::Tiny, so you can do this:

    use v5.10;
    use strictures;
    
    

    my %LMU;
    use List::MoreUtils { into => \%LMU }, -all;

    # calls List::MoreUtils::uniq()
    say for $LMU{uniq}->(qw/foo bar foo baz/);


  • Tim King commented on Long Import Lists (and available strategies for managing them)

    Exporter::Tiny: good tip. (Unfortunately, this depends on the implementation of the package being used. That kinda sucks.)

  • Tim King commented on Long Import Lists (and available strategies for managing them)

    Yes! That's it. (I had to run it through perltidy to make sense of it, but that's the code.)

Subscribe to feed Responses to Comments from Yang Bo

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is hosted by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.