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   64904 use strictures 2;
  3         18  
  3         111  
4 3     3   1250 use Import::Into;
  3         410  
  3         59  
5 3     3   1416 use Constructor::Sugar ();
  3         8  
  3         76  
6 3     3   15 use Throwable::SugarFactory::Utils '_getglob';
  3         6  
  3         195  
7              
8             our $VERSION = '0.152690'; # 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   16 no strict 'refs';
  3         3  
  3         1255  
29 9     9   13 sub _getexport { \@{"$_[0]::EXPORT"} }
  9         33  
30 9     9   9 sub _getexport_tags { \%{"$_[0]::EXPORT_TAGS"} }
  9         38  
31             ## use critic
32             }
33              
34             sub import {
35 3     3   279 base->import::into( scalar caller, "Exporter" ); # I::I 1.001000 syntax
36 3         625 my $library = caller;
37             my $sweeten_func = sub {
38 10     10   67 for my $spec ( @_ ) {
39 10         31 my ( $class ) = split /->/, $spec;
40 10         29 my ( $id ) = ( reverse split /::/, $class )[0];
41 10         54 my ( $ctors, $ids ) =
42             Constructor::Sugar->import::into( $library, $spec );
43 9         72 push @{ _getexport $library}, @{$ctors}, @{$ids};
  9         23  
  9         15  
  9         18  
44 9         22 my $tags = _getexport_tags $library;
45 9         12 push @{ $tags->{$id} }, @{$ctors}, @{$ids};
  9         20  
  9         14  
  9         17  
46 9         14 push @{ $tags->{ctors} }, @{$ctors};
  9         13  
  9         25  
47 9         14 push @{ $tags->{ids} }, @{$ids};
  9         14  
  9         36  
48             }
49 3         13 };
50             my $sweeten_meth = sub {
51 7     7   9 shift;
52 7         16 $sweeten_func->( @_ );
53 3         9 };
54 3         7 *{ _getglob $library, "sweeten" } = $sweeten_func;
  3         10  
55 3         3 *{ _getglob $library, "sweeten_meth" } = $sweeten_meth;
  3         12  
56 3         79 return;
57             }
58              
59             1;
60              
61             __END__