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     122   177354 use v5.28;
  5         14  
6 5     5   18 use strict;
  5         6  
  5         92  
7 5     5   14 use warnings;
  5         11  
  5         282  
8 5     5   438 use experimental 'signatures';
  5         1237  
  5         26  
9              
10             our $VERSION = '0.34';
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   1272 use Iterator::Flex::Utils qw( :default REG_ITERATOR REG_ITER_METHODS );
  5         6  
  5         774  
29 5     5   2114 use Package::Variant importing => qw[ Role::Tiny ];
  5         21443  
  5         25  
30 5     5   399 use Module::Runtime;
  5         7  
  5         15  
31              
32 29     29   616 sub make_variant_package_name ( $, $package, % ) {
  29         62  
  29         65  
33              
34 29         85 $package = "Iterator::Flex::Role::Method::$package";
35              
36 29 100       93 if ( Role::Tiny->is_role( $package ) ) {
37 20         1113 require Iterator::Flex::Failure;
38 20         95 Iterator::Flex::Failure::RoleExists->throw( { payload => $package } );
39             }
40              
41             ## no critic (Require LocalizedPunctuationVars )
42 9         62 $INC{ Module::Runtime::module_notional_filename( $package ) } = 1;
43 9         204 return $package;
44             }
45              
46 9     9   3731 sub make_variant ( $, $, $, %arg ) {
  9         22  
  9         12  
47 9         15 my $name = $arg{name};
48             install $name => sub {
49 123     123   1474 return $REGISTRY{ refaddr $_[0] }[REG_ITERATOR][REG_ITER_METHODS]{$name}->( @_ );
50 9         47 };
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__