Module::New::Meta - Module::New::Meta documentation


Module-New documentation Contained in the Module-New distribution.

Index


Code Index:

NAME

Top

Module::New::Meta

DESCRIPTION

Top

Used internally to install functions/methods.

AUTHOR

Top

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE

Top


Module-New documentation Contained in the Module-New distribution.

package Module::New::Meta;

use strict;
use warnings;
use Carp;
use Sub::Install 'reinstall_sub';

my $meta;

sub import {
  my $class  = shift;
  my $caller = caller;

  foreach my $type (qw( methods functions )) {
    reinstall_sub({
      as   => $type,
      into => $caller,
      code => sub ($) {
        my $href = shift;
        foreach my $name (keys %{ $href }) {
          $meta->{$caller}->{$name} = $href->{$name};
        }
      }
    });
  }

  reinstall_sub({
    as   => 'import',
    into => $caller,
    code => sub {
      my $class  = shift;
      my $caller = caller;

      return if $caller eq 'main';
      return if $caller =~ /^Test::/;

      my $my_meta = $meta->{$class};
      foreach my $name (keys %{ $my_meta }) {
        reinstall_sub({
          as   => $name,
          into => $caller,
          code => $my_meta->{$name},
        });
      }
    }
  });
}

1;

__END__