Skip to content

Instantly share code, notes, and snippets.

@Xliff
Last active October 16, 2016 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xliff/0f537c12b415fa0800a55f9484a25b1a to your computer and use it in GitHub Desktop.
Save Xliff/0f537c12b415fa0800a55f9484a25b1a to your computer and use it in GitHub Desktop.

So after that last bit of EXPORT weirdness, I went to apply lessons learned to the actual project, and the bloody error returned. I have now linked the cause to specific require statements:

sub EXPORT(+@a) {
        # cw: Implement SELECTIVE loading if necessary.
        @color_list = @a.elems > 0 ??
                @color_lists_found.grep(@a.any)
                !!
                @color_lists_found;

        #if $color_support {
        #       require Color;
        #}
        #for @color_list -> $cl {
        #       say "L: $cl";
        #       require ::("Color::Names::{$cl}");
        #}

        # cw: What we always export.
        #
        #     Is there any way to get EXPORT::DEFAULT from the module block?
        {
                '&lists_available'      => ::('&Color::Names::lists_available'),
                '&lists_loaded'         => ::('&Color::Names::lists_loaded'),
                '&location'                     => ::('&Color::Names::location'),
                '&color'                        => ::('&Color::Names::color'),
                '&hex'                          => ::('&Color::Names::hex'),
                '&rgb'                          => ::('&Color::Names::rgb'),
        }
}

If I run the project with the subroutine definition above, it works:

$ perl6 --stagestats -Ilib -e 'use Color::Names "Cloford"; dd color("red")'
Stage start      :   0.000
Stage parse      :   0.701
Stage syntaxcheck:   0.000
Stage ast        :   0.000
Stage optimize   :   0.001
Stage mast       :   0.006
Stage mbc        :   0.000
Stage moar       :   0.000
Nil

However, if I edit the sub to look like the following:

sub EXPORT(+@a) {
        # cw: Implement SELECTIVE loading if necessary.
        @color_list = @a.elems > 0 ??
                @color_lists_found.grep(@a.any)
                !!
                @color_lists_found;

        if $color_support {
               require Color;
        }
        for @color_list -> $cl {
               say "L: $cl";
               require ::("Color::Names::{$cl}");
        }

        # cw: What we always export.
        #
        #     Is there any way to get EXPORT::DEFAULT from the module block?
        {
                '&lists_available'      => ::('&Color::Names::lists_available'),
                '&lists_loaded'         => ::('&Color::Names::lists_loaded'),
                '&location'                     => ::('&Color::Names::location'),
                '&color'                        => ::('&Color::Names::color'),
                '&hex'                          => ::('&Color::Names::hex'),
                '&rgb'                          => ::('&Color::Names::rgb'),
        }
}

I get the following error:

$ perl6 --stagestats -Ilib -e 'use Color::Names "aa"; dd color("red")'
Stage start      :   0.000
Stage parse      : ===SORRY!===
Cannot find method 'merge-symbols': no method cache and no .^find_method

If you want to see this error in action, you can download the repository from here: https://github.com/Xliff/p6-color-names

So is this an error in Rakudo or an error in my code?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment