| 1 | package Constructor::SugarLibrary; | ||
| 2 | |||
| 3 | 6 | ▶ | use strictures 2; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 6 | ▶ | use Import::Into; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 6 | ▶ | use Constructor::Sugar (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 6 | ▶ | use Throwable::SugarFactory::Utils '_getglob'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 6 | our $VERSION = '0.213360'; # 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 | 6 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 29 | 9 | ▶ | sub _getexport { \@{"$_[0]::EXPORT"} } |
|
Subroutine
_getexport: called CC=1 SCAR=0.0
| |||
| 30 | 9 | ▶ | sub _getexport_tags { \%{"$_[0]::EXPORT_TAGS"} } |
|
Subroutine
_getexport_tags: called CC=1 SCAR=0.0
| |||
| 31 | ## use critic | ||
| 32 | } | ||
| 33 | |||
| 34 | 6 | ▶ | sub import { |
|
Subroutine
import: called CC=1 SCAR=0.0
| |||
| 35 | 3 | base->import::into( scalar caller, "Exporter" ); # I::I 1.001000 syntax | |
| 36 | 3 | my $library = caller; | |
| 37 | 10 | ▶ | my $sweeten_func = sub { |
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||
| 38 | 10 | for my $spec ( @_ ) { | |
| 39 | 10 | my ( $class ) = split /->/, $spec; | |
| 40 | 10 | my ( $id ) = ( reverse split /::/, $class )[0]; | |
| 41 | 10 | my ( $ctors, $ids ) = | |
| 42 | Constructor::Sugar->import::into( $library, $spec ); | ||
| 43 | 9 | push @{ _getexport $library}, @{$ctors}, @{$ids}; | |
| 44 | 9 | my $tags = _getexport_tags $library; | |
| 45 | 9 | push @{ $tags->{$id} }, @{$ctors}, @{$ids}; | |
| 46 | 9 | push @{ $tags->{ctors} }, @{$ctors}; | |
| 47 | 9 | push @{ $tags->{ids} }, @{$ids}; | |
| 48 | } | ||
| 49 | 3 | }; | |
| 50 | 7 | ▶ | my $sweeten_meth = sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 51 | 7 | shift; | |
| 52 | 7 | $sweeten_func->( @_ ); | |
| 53 | 3 | }; | |
| 54 | 3 | *{ _getglob $library, "sweeten" } = $sweeten_func; | |
| 55 | 3 | *{ _getglob $library, "sweeten_meth" } = $sweeten_meth; | |
| 56 | 3 | return; | |
| 57 | } | ||
| 58 | |||
| 59 | 6 | 1; | |
| 60 | |||
| 61 | __END__ | ||