« blib/lib/Iterator/Flex/Role/Exhaustion/Throw.pm
↑ Summary
blib/lib/Iterator/Flex/Role/Reset/Method.pm »
| 1 | package Iterator::Flex::Method; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Compartmentalize Iterator::Flex::Method::Maker | ||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use v5.28; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use experimental 'signatures'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 5 | our $VERSION = '0.33'; | |||||||||
| 11 | |||||||||||
| 12 | # Package::Variant based modules generate constructor functions | ||||||||||
| 13 | # dynamically when those modules are imported. However, loading the | ||||||||||
| 14 | # module via require() then calling its import method must be done | ||||||||||
| 15 | # only once, otherwise Perl will emit multiply defined errors for the | ||||||||||
| 16 | # constructor functions. | ||||||||||
| 17 | |||||||||||
| 18 | # By layering the Package::Variant based module in an inner package | ||||||||||
| 19 | # and calling its import here, the constructor function, Maker(), is | ||||||||||
| 20 | # generated just once, as Iterator::Flex::Method::Maker, and is | ||||||||||
| 21 | # available to any caller by it's fully qualified name. | ||||||||||
| 22 | |||||||||||
| 23 | 5 | Iterator::Flex::Method::Maker->import; | |||||||||
| 24 | |||||||||||
| 25 | ## no critic( MultiplePackages ) | ||||||||||
| 26 | 5 | package Iterator::Flex::Method::Maker { | |||||||||
| 27 | |||||||||||
| 28 | 5 | ▶ | use Iterator::Flex::Utils qw( :default REG_ITERATOR REG_ITER_METHODS ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 5 | ▶ | use Package::Variant importing => qw[ Role::Tiny ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 5 | ▶ | use Module::Runtime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | |||||||||||
| 32 | ▶ | sub make_variant_package_name ( $, $package, % ) { | |||||||||
|
Subroutine
make_variant_package_name: called CC=2 SCAR=6.9
| |||||||||||
| 33 | |||||||||||
| 34 | 29 | $package = "Iterator::Flex::Role::Method::$package"; | |||||||||
| 35 | |||||||||||
| 36 | 29 | ▶ | if ( Role::Tiny->is_role( $package ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 20 | require Iterator::Flex::Failure; | |||||||||
| 38 | 20 | Iterator::Flex::Failure::RoleExists->throw( { payload => $package } ); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | ## no critic (Require LocalizedPunctuationVars ) | ||||||||||
| 42 | 9 | $INC{ Module::Runtime::module_notional_filename( $package ) } = 1; | |||||||||
| 43 | 9 | return $package; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | ▶ | sub make_variant ( $, $, $, %arg ) { | |||||||||
|
Subroutine
make_variant: called CC=1 SCAR=0.0
| |||||||||||
| 47 | 9 | my $name = $arg{name}; | |||||||||
| 48 | install $name => sub { | ||||||||||
| 49 | 123 | ▶ | return $REGISTRY{ refaddr $_[0] }[REG_ITERATOR][REG_ITER_METHODS]{$name}->( @_ ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 9 | }; | |||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 5 | 1; | |||||||||
| 55 | |||||||||||
| 56 | # | ||||||||||
| 57 | # This file is part of Iterator-Flex | ||||||||||
| 58 | # | ||||||||||
| 59 | # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory. | ||||||||||
| 60 | # | ||||||||||
| 61 | # This is free software, licensed under: | ||||||||||
| 62 | # | ||||||||||
| 63 | # The GNU General Public License, Version 3, June 2007 | ||||||||||
| 64 | # | ||||||||||
| 65 | |||||||||||
| 66 | __END__ | ||||||||||