| 1 | # | ||||||||||||
| 2 | # This file is part of Reindeer | ||||||||||||
| 3 | # | ||||||||||||
| 4 | # This software is Copyright (c) 2017, 2015, 2014, 2012, 2011 by Chris Weyl. | ||||||||||||
| 5 | # | ||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||
| 7 | # | ||||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||
| 9 | # | ||||||||||||
| 10 | package Reindeer::Builder; | ||||||||||||
| 11 | 2 | our $AUTHORITY = 'cpan:RSRCHBOY'; | |||||||||||
| 12 | 2 | $Reindeer::Builder::VERSION = '0.020'; | |||||||||||
| 13 | # ABSTRACT: Easily build a new 'Reindeer' style class | ||||||||||||
| 14 | |||||||||||||
| 15 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 2 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 2 | ▶ | use Moose::Exporter; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 2 | ▶ | use Moose::Autobox; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 2 | ▶ | use Sub::Install; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | |||||||||||||
| 23 | 2 | ▶ | use Reindeer (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 2 | ▶ | use Reindeer::Util; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | |||||||||||||
| 26 | # Look at our args, figure out what needs to be added/filtered | ||||||||||||
| 27 | |||||||||||||
| 28 | 1 | ▶ | sub import { | ||||||||||
|
Subroutine
import: called CC=9 SCAR=22.5
| |||||||||||||
| 29 | 1 | my ($class, %config) = @_; | |||||||||||
| 30 | |||||||||||||
| 31 | # figure out if we're supposed to be for a role | ||||||||||||
| 32 | 1 | my $target = caller(0); # let's start out simple | |||||||||||
| 33 | 1 | ▶ | my $for_role = ($target =~ /::Role$/) ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | |||||||||||||
| 35 | 1 | my $also = []; | |||||||||||
| 36 | 1 | ▶ | if (exists $config{also}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | |||||||||||||
| 38 | 1 | my $also_config = $config{also}; | |||||||||||
| 39 | |||||||||||||
| 40 | 1 | $also = [ Reindeer::Util::also_list() ]; | |||||||||||
| 41 | 1 | ▶ | my $exclude = $config{also}->{exclude} || []; | ||||||||||
|
Condition50%1/2
$config{'also'}{'exclude'} || []
MC/DC0%0/1
$config{'also'}{'exclude'} || []
$config{'also'}{'exclude'}
Truth table50%1/2
A
A= $config{'also'}{'exclude'}
| |||||||||||||
| 42 | 1 | ▶ | my $add = $config{also}->{add} || []; | ||||||||||
|
Condition50%1/2
$config{'also'}{'add'} || []
MC/DC0%0/1
$config{'also'}{'add'} || []
$config{'also'}{'add'}
Truth table50%1/2
A
A= $config{'also'}{'add'}
| |||||||||||||
| 43 | |||||||||||||
| 44 | 8 | ▶ | $also = $also->grep(sub { !$exclude->any($_) }) | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 45 | 1 | ▶ | if @$exclude > 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | |||||||||||||
| 47 | 1 | $also->push(@$add); | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | 1 | ▶ | $also->unshift($for_role ? 'Moose::Role' : 'Moose'); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | |||||||||||||
| 52 | # create our methods... | ||||||||||||
| 53 | #my ($import, $unimport, $init_meta) = Moose::Exporter->build_import_methods( | ||||||||||||
| 54 | 1 | my %methods; | |||||||||||
| 55 | 1 | @methods{qw/ import unimport init_meta /} = | |||||||||||
| 56 | Moose::Exporter->build_import_methods( | ||||||||||||
| 57 | also => $also, | ||||||||||||
| 58 | ); | ||||||||||||
| 59 | |||||||||||||
| 60 | 2 | ▶ | my $_install = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 61 | Sub::Install::reinstall_sub({ | ||||||||||||
| 62 | 2 | code => $methods{$_[0]}, | |||||||||||
| 63 | into => $target, | ||||||||||||
| 64 | as => $_[0], | ||||||||||||
| 65 | }); | ||||||||||||
| 66 | 1 | }; | |||||||||||
| 67 | |||||||||||||
| 68 | 3 | ▶ | do { $_install->($_) if defined $methods{$_} } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | 1 | for keys %methods; | |||||||||||
| 70 | |||||||||||||
| 71 | 1 | return; | |||||||||||
| 72 | } | ||||||||||||
| 73 | |||||||||||||
| 74 | 2 | !!42; | |||||||||||
| 75 | |||||||||||||
| 76 | __END__ | ||||||||||||