| 1 | package Constructor::Sugar; | ||||||||||||
| 2 | |||||||||||||
| 3 | 8 | ▶ | use strictures 2; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 8 | ▶ | use String::CamelCase 'decamelize'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 8 | ▶ | use Throwable::SugarFactory::Utils '_getglob'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 8 | our $VERSION = '0.213360'; # VERSION | |||||||||||
| 9 | |||||||||||||
| 10 | # ABSTRACT: export 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 | 23 | ▶ | sub _export { | ||||||||||
|
Subroutine
_export: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 23 | my ( $pkg, $func, $code ) = @_; | |||||||||||
| 28 | 23 | *{ _getglob $pkg, $func } = $code; | |||||||||||
| 29 | 22 | return $func; | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | 13 | ▶ | sub import { | ||||||||||
|
Subroutine
import: called CC=4 SCAR=13.9
| |||||||||||||
| 33 | 13 | my ( undef, @specs ) = @_; | |||||||||||
| 34 | 13 | my $target = caller; | |||||||||||
| 35 | 13 | my ( @constructors, @iders ); | |||||||||||
| 36 | |||||||||||||
| 37 | 13 | for my $spec ( @specs ) { | |||||||||||
| 38 | 13 | my ( $class, $method ) = split /->/, $spec; | |||||||||||
| 39 | 13 | ▶ | $method ||= "new"; | ||||||||||
|
Condition100%2/2
$method ||= "new"
MC/DC100%1/1
$method ||= "new"
$method
Truth table100%2/2
A
A= $method
| |||||||||||||
| 40 | 13 | my $id = ( reverse split /::/, $class )[0]; | |||||||||||
| 41 | 13 | my $ct = decamelize $id; | |||||||||||
| 42 | 13 | ▶ | die "Converting '$id' into a snake_case constructor did not result in" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | . " a different string." | ||||||||||||
| 44 | if $ct eq $id; | ||||||||||||
| 45 | |||||||||||||
| 46 | 12 | ▶ | push @constructors, _export $target, $ct, sub { $class->$method( @_ ) }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 47 | 11 | ▶ | push @iders, _export $target, $id, sub { $class }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | 11 | return ( \@constructors, \@iders ); | |||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | 8 | 1; | |||||||||||
| 54 | |||||||||||||
| 55 | __END__ | ||||||||||||