Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Well to start with, please please please make sure it's based on Sub::Exporter and not Exporter.pm. And as for basing it on attributes, I don't think that is a plus. Attributes are poorly implemented with a poor API to use them. They give you just enough power to think you can do something cool with them, and then fall short (IMO at least).

    Okay, that said, here is a modified version of a proof of concept [0beta.co.uk] module I did recently that mixed Moose roles and Sub::Exporter. It should do the trick for exporting all ^sim_* functions without having to repeat yourself in @EXPORT or in attributes.

    package Export::Only::What::I::Want;

    use strict;
    use warnings;

    use Class::MOP;
    use Sub::Exporter;

    sub import {
        shift;
        my ($regexp) = @_;

        my $pkg = caller();

        my $pkg_meta = Class::MOP::Class->initialize($pkg);

        $pkg_meta->alias_method(import => Sub::Exporter::build_exporter(
                {
                    exports => {
                        map {
                            $_ => $pkg_meta->get_method($_)->body
                        } grep {
                            /$regexp/
                        } $pkg_meta->get_method_list
                    },
                    groups  => { default => [':all'] }
                }
            )
        );
    }
    You would then use it in your module like so ...

    package Foo;

    use Export::Only::What::I::Want qr/^foo_/;

    sub foo_bar { 'Foo::foo_bar' }
    sub bar_foo { 'Foo::bar_foo' }
    And whalla...

    package Bar;
    use Foo;
    # Bar::foo_bar exists, but no Bar::bar_foo ..

    - Stevan