| 1 | package Bolts::Bag; | ||||||||||||
| 2 | 11 | $Bolts::Bag::VERSION = '0.143171'; | |||||||||||
| 3 | # ABSTRACT: Helper for creating bags containing artifacts | ||||||||||||
| 4 | |||||||||||||
| 5 | 11 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 11 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 11 | ▶ | use Moose::Util::MetaRole; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 11 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 11 | ▶ | use Safe::Isa; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 11 | ▶ | use Scalar::Util qw( blessed reftype ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | |||||||||||||
| 14 | 55 | ▶ | sub start_bag { | ||||||||||
|
Subroutine
start_bag: called CC=8 SCAR=21.1
Pod
documented
| |||||||||||||
| 15 | 55 | my ($class, %params) = @_; | |||||||||||
| 16 | |||||||||||||
| 17 | 55 | my $package = $params{package}; | |||||||||||
| 18 | 55 | my $meta_locator = $params{meta_locator}; | |||||||||||
| 19 | 55 | my $such_that_each = $params{such_that_each}; | |||||||||||
| 20 | |||||||||||||
| 21 | 55 | my $meta; | |||||||||||
| 22 | 55 | my %options = (superclasses => [ 'Moose::Object' ]); | |||||||||||
| 23 | 55 | ▶ | if (defined $package) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | 55 | $meta = Moose::Util::find_meta($package); | |||||||||||
| 25 | 55 | ▶ | if (defined $meta) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 23 | return $meta; | |||||||||||
| 27 | } | ||||||||||||
| 28 | |||||||||||||
| 29 | 32 | $meta = Moose::Meta::Class->create($package, %options); | |||||||||||
| 30 | } | ||||||||||||
| 31 | else { | ||||||||||||
| 32 | 0 | $meta = Moose::Meta::Class->create_anon_class(%options); | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | 32 | Moose::Util::MetaRole::apply_base_class_roles( | |||||||||||
| 36 | for => $meta, | ||||||||||||
| 37 | roles => [ 'Bolts::Role::SelfLocator' ], | ||||||||||||
| 38 | ); | ||||||||||||
| 39 | |||||||||||||
| 40 | 32 | $meta = Moose::Util::MetaRole::apply_metaroles( | |||||||||||
| 41 | for => $meta, | ||||||||||||
| 42 | class_metaroles => { | ||||||||||||
| 43 | class => [ | ||||||||||||
| 44 | 'Bolts::Meta::Class::Trait::Locator', | ||||||||||||
| 45 | 'Bolts::Meta::Class::Trait::Bag', | ||||||||||||
| 46 | ], | ||||||||||||
| 47 | }, | ||||||||||||
| 48 | ); | ||||||||||||
| 49 | |||||||||||||
| 50 | 32 | ▶ | if ($such_that_each) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | 29 | my $such_that = $class->_expand_such_that($such_that_each); | |||||||||||
| 52 | 29 | ▶ | if (defined $such_that->{does}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | 28 | $meta->such_that_does($such_that->{does}); | |||||||||||
| 54 | } | ||||||||||||
| 55 | 29 | ▶ | if (defined $such_that->{isa}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | 1 | $meta->such_that_isa($such_that->{isa}); | |||||||||||
| 57 | } | ||||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | 32 | ▶ | if ($meta_locator) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | 0 | $meta->locator($meta_locator); | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | 0 | ▶ | Carp::cluck("bad meta @{[$meta->name]}") unless $meta->can('locator'); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | |||||||||||||
| 66 | 32 | return $meta; | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | 29 | ▶ | sub _expand_such_that { | ||||||||||
|
Subroutine
_expand_such_that: called CC=4 SCAR=13.9
| |||||||||||||
| 70 | 29 | my ($class, $such_that) = @_; | |||||||||||
| 71 | |||||||||||||
| 72 | 29 | ▶ | $such_that //= {}; | ||||||||||
|
Condition50%1/2
$such_that //= {}
MC/DC0%0/1
$such_that //= {}
$such_that
Truth table50%1/2
A
A= $such_that
| |||||||||||||
| 73 | 29 | my %expanded_such_that; | |||||||||||
| 74 | |||||||||||||
| 75 | 29 | ▶ | if (defined $such_that->{isa}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | 1 | $expanded_such_that{isa} = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($such_that->{isa}); | |||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | 29 | ▶ | if (defined $such_that->{does}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | 28 | $expanded_such_that{does} = Moose::Util::TypeConstraints::find_or_create_does_type_constraint($such_that->{does}); | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 29 | return \%expanded_such_that; | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | |||||||||||||
| 87 | 11 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 88 | |||||||||||||
| 89 | __END__ | ||||||||||||