File Coverage

blib/lib/Iterator/Flex/Method.pm
Criterion Covered Total %
statement 35 35 100.0
branch 2 2 100.0
condition n/a
subroutine 10 10 100.0
pod n/a
total 47 47 100.0


line stmt bran cond sub pod time code
1             package Iterator::Flex::Method;
2              
3             # ABSTRACT: Compartmentalize Iterator::Flex::Method::Maker
4              
5 5     18   180791 use v5.28;
  5         16  
6 5     5   29 use strict;
  5         25  
  5         146  
7 5     5   21 use warnings;
  5         7  
  5         282  
8 5     5   404 use experimental 'signatures';
  5         1302  
  5         31  
9              
10             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             Iterator::Flex::Method::Maker->import;
24              
25             ## no critic( MultiplePackages )
26             package Iterator::Flex::Method::Maker {
27              
28 5     5   1601 use Iterator::Flex::Utils qw( :default REG_ITERATOR REG_ITER_METHODS );
  5         12  
  5         957  
29 5     5   3025 use Package::Variant importing => qw[ Role::Tiny ];
  5         29056  
  5         36  
30 5     5   521 use Module::Runtime;
  5         32  
  5         40  
31              
32 29     29   710 sub make_variant_package_name ( $, $package, % ) {
  29         57  
  29         41  
33              
34 29         90 $package = "Iterator::Flex::Role::Method::$package";
35              
36 29 100       112 if ( Role::Tiny->is_role( $package ) ) {
37 20         2181 require Iterator::Flex::Failure;
38 20         146 Iterator::Flex::Failure::RoleExists->throw( { payload => $package } );
39             }
40              
41             ## no critic (Require LocalizedPunctuationVars )
42 9         81 $INC{ Module::Runtime::module_notional_filename( $package ) } = 1;
43 9         254 return $package;
44             }
45              
46 9     9   5497 sub make_variant ( $, $, $, %arg ) {
  9         27  
  9         13  
47 9         15 my $name = $arg{name};
48             install $name => sub {
49 123     123   1207 return $REGISTRY{ refaddr $_[0] }[REG_ITERATOR][REG_ITER_METHODS]{$name}->( @_ );
50 9         46 };
51             }
52             }
53              
54             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__