File Coverage

blib/lib/Constructor/SugarLibrary.pm
Criterion Covered Total %
statement 49 49 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod n/a
total 59 59 100.0


line stmt bran cond sub pod time code
1             package Constructor::SugarLibrary;
2              
3 3     3   76199 use strictures 2;
  3         23  
  3         131  
4 3     3   1661 use Import::Into;
  3         549  
  3         83  
5 3     3   1552 use Constructor::Sugar ();
  3         8  
  3         83  
6 3     3   18 use Throwable::SugarFactory::Utils '_getglob';
  3         5  
  3         208  
7              
8             our $VERSION = '0.152700'; # VERSION
9              
10             # ABSTRACT: build a library of generic constructor syntax sugar
11              
12             #
13             # This file is part of Throwable-SugarFactory
14             #
15             #
16             # Christian Walde has dedicated the work to the Commons by waiving all of his
17             # or her rights to the work worldwide under copyright law and all related or
18             # neighboring legal rights he or she had in the work, to the extent allowable by
19             # law.
20             #
21             # Works under CC0 do not require attribution. When citing the work, you should
22             # not imply endorsement by the author.
23             #
24              
25              
26             {
27             ## no critic (ProhibitNoStrict)
28 3     3   15 no strict 'refs';
  3         4  
  3         1431  
29 9     9   12 sub _getexport { \@{"$_[0]::EXPORT"} }
  9         38  
30 9     9   12 sub _getexport_tags { \%{"$_[0]::EXPORT_TAGS"} }
  9         35  
31             ## use critic
32             }
33              
34             sub import {
35 3     3   420 base->import::into( scalar caller, "Exporter" ); # I::I 1.001000 syntax
36 3         845 my $library = caller;
37             my $sweeten_func = sub {
38 10     10   96 for my $spec ( @_ ) {
39 10         38 my ( $class ) = split /->/, $spec;
40 10         35 my ( $id ) = ( reverse split /::/, $class )[0];
41 10         61 my ( $ctors, $ids ) =
42             Constructor::Sugar->import::into( $library, $spec );
43 9         85 push @{ _getexport $library}, @{$ctors}, @{$ids};
  9         25  
  9         17  
  9         20  
44 9         53 my $tags = _getexport_tags $library;
45 9         16 push @{ $tags->{$id} }, @{$ctors}, @{$ids};
  9         20  
  9         14  
  9         19  
46 9         13 push @{ $tags->{ctors} }, @{$ctors};
  9         17  
  9         20  
47 9         11 push @{ $tags->{ids} }, @{$ids};
  9         17  
  9         43  
48             }
49 3         17 };
50             my $sweeten_meth = sub {
51 7     7   11 shift;
52 7         21 $sweeten_func->( @_ );
53 3         12 };
54 3         6 *{ _getglob $library, "sweeten" } = $sweeten_func;
  3         13  
55 3         27 *{ _getglob $library, "sweeten_meth" } = $sweeten_meth;
  3         10  
56 3         107 return;
57             }
58              
59             1;
60              
61             __END__