| 1 | ## no critic: TestingAndDebugging::RequireUseStrict | ||||||||||
| 2 | package alias::module; | ||||||||||
| 3 | |||||||||||
| 4 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 5 | 1 | our $DATE = '2023-09-30'; # DATE | |||||||||
| 6 | 1 | our $DIST = 'alias-module'; # DIST | |||||||||
| 7 | 1 | our $VERSION = '0.003'; # VERSION | |||||||||
| 8 | |||||||||||
| 9 | 0 | ▶ | sub import { | ||||||||
|
Subroutine
import: not called CC=5 SCAR=34.0
| |||||||||||
| 10 | 0 | my $class = shift; | |||||||||
| 11 | 0 | ▶ | my $noreq = $_[0] eq '-norequire' ? shift : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 12 | 0 | my $orig = shift; | |||||||||
| 13 | |||||||||||
| 14 | 0 | ▶ | defined $orig or die "Please specify package to alias from"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | |||||||||||
| 16 | 0 | my $caller = caller(); | |||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | if ($caller eq $orig) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | warn "Aliasing from the same package '$caller', probably a typo?"; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | unless ($noreq) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | (my $orig_pm = "$orig.pm") =~ s!::!/!g; | |||||||||
| 24 | 0 | require $orig_pm; | |||||||||
| 25 | } | ||||||||||
| 26 | 0 | *{$caller . "::"} = \*{$orig . "::"}; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 1 | 1; | |||||||||
| 30 | # ABSTRACT: Alias one module as another | ||||||||||
| 31 | |||||||||||
| 32 | __END__ | ||||||||||