package subroutines;

our $DATE = '2018-12-15'; # DATE
our $VERSION = '0.001'; # VERSION

#use strict 'subs', 'vars';

sub _package_exists {
    my $pkg = shift;

    if ($pkg =~ s/::(\w+)\z//) {
        return !!${$pkg . "::"}{$1 . "::"};
    } else {
        return !!$::{$pkg . "::"};

sub import {
    my $class = shift;
    my $noreq = $_[0] eq '-norequire' ? shift : 0;
    my $orig  = shift;

    my $caller = caller();

    unless ($noreq) {
        (my $orig_pm = "$") =~ s!::!/!g;
        require $orig_pm;

    die "Cannot use subroutines from '$orig': package does not exist" unless

    my $symtbl = \%{$orig . "::"};

    while (my ($k, $v) = each %$symtbl) {
        next if $k =~ /::$/; # subpackage
        if ("$v" !~ /^\*/) {
            # constant
            *{"$caller\::$k"} = \*{$orig . "::"};
        } elsif (defined *$v{CODE}) {
            # subroutine
            *{"$caller\::$k"} = *$v{CODE};

# ABSTRACT: Use subroutines from another module



=encoding UTF-8

=head1 NAME

subroutines - Use subroutines from another module

=head1 VERSION

This document describes version 0.001 of subroutines (from Perl distribution subroutines), released on 2018-12-15.


 package Your::Module;
 use subroutines 'Another::Module';

To avoid require()-ing:

 use subroutines '-norequire', 'Another::Module';


This pragma declares routines in your module that are copied from another

 package Your::Module;
 use subroutines 'Another::Module';

is equivalent to this pseudo-code:

 package Your::Module;
     require Another::Module;
     for my $name (all_subroutines_in("Another::Module")) {
         *{"Your::Module::$name"} = \&{"Another::Module::$name"};

This is a form of code reuse when you cannot do:

 package Your::Module;
 use parent 'Another::Module';

because the original subroutines do not expect to be called as methods, and/or
when your subroutines are not called as methods.

Another alternative is to declare C<Your::Module> as an alias of
C<Another::Module>, e.g. using L<alias::module>.

 package Your::Module;
 use alias::module 'Another::Module';

but this copies everythng, not just subroutines.


Please visit the project's homepage at L<>.

=head1 SOURCE

Source repository is at L<>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired

=head1 SEE ALSO


L<parent>, L<base>

=head1 AUTHOR

perlancar <>


This software is copyright (c) 2018 by

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.