Const-Common

 view release on metacpan or  search on metacpan

lib/Const/Common.pm  view on Meta::CPAN

our $VERSION = "0.01";

require Exporter;
use Data::Lock;

sub import {
    my $pkg   = caller;
    shift;
    my %constants = @_ == 1 ? %{ $_[0] } : @_;

    Data::Lock::dlock my $locked = \%constants;
    {
        no strict 'refs';
        ${ "$pkg\::_constants" } = $locked;
        for my $method (qw/const constants constant_names/) {
            *{ "$pkg\::$method" } = \&{ __PACKAGE__ . "::$method" };
        }
        push @{"$pkg\::ISA"}, ('Exporter');
        push @{"$pkg\::EXPORT"}, (keys %$locked);
    }

    require constant;
    @_ = ('constant', $locked);
    goto constant->can('import');
}

sub const {
    my ($pkg, $constant_name) = @_;
    $pkg->constants->{$constant_name};
}

sub constants {
    no strict 'refs';



( run in 0.501 second using v1.01-cache-2.11-cpan-49f99fa48dc )