| 1 | package Bolts::Meta::Class::Trait::Bag; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | $Bolts::Meta::Class::Trait::Bag::VERSION = '0.143171'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Metaclass role for Bolts-built bags | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Safe::Isa; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Scalar::Util qw( reftype ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | has artifacts => ( | ||||||||||||||||||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 13 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 44 | ▶ | default => sub { +{} }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | traits => [ 'Hash' ], | |||||||||||||||||||||||||||||||||||||||||
| 16 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 17 | '_add_artifact' => 'set', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 'list_artifacts' => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | has such_that_isa => ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | isa => 'Moose::Meta::TypeConstraint', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | predicate => 'has_such_that_isa', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 11 | has such_that_does => ( | |||||||||||||||||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | isa => 'Moose::Meta::TypeConstraint', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | predicate => 'has_such_that_does', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 53 | ▶ | sub is_finished_bag { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_finished_bag: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 53 | my $meta = shift; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 53 | return $meta->is_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 216 | ▶ | sub add_artifact { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_artifact: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 216 | my ($meta, $name, $value, $such_that) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 216 | ▶ | if (!defined $such_that and ($meta->has_such_that_isa | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not defined $such_that and $meta->has_such_that_isa || $meta->has_such_that_does
$meta->has_such_that_isa or $meta->has_such_that_does
MC/DC66%2/3
not defined $such_that and $meta->has_such_that_isa || $meta->has_such_that_does
not defined $such_that
$meta->has_such_that_isa
$meta->has_such_that_does
Truth table75%3/4
not(A) and B or C
A= not defined $such_thatB= $meta->has_such_that_isaC= $meta->has_such_that_does
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | or $meta->has_such_that_does)) { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 167 | $such_that = {}; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 167 | ▶ | $such_that->{isa} = $meta->such_that_isa | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | if $meta->has_such_that_isa; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 167 | ▶ | $such_that->{does} = $meta->such_that_does | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | if $meta->has_such_that_does; | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 216 | ▶ | if ($value->$_does('Bolts::Role::Artifact')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 214 | ▶ | $value->such_that($such_that) if $such_that; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 214 | $meta->_add_artifact($name => $value); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 214 | ▶ | $meta->add_method($name => sub { $value }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent_bag: called CC=1 SCAR=0.0
Subroutine
prototype: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | ▶ | elsif (defined reftype($value) and reftype($value) eq 'CODE') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined builtin::reftype($value) and builtin::reftype($value) eq "CODE"
MC/DC50%1/2
defined builtin::reftype($value) and builtin::reftype($value) eq "CODE"
defined builtin::reftype($value)
builtin::reftype($value) eq "CODE"
Truth table66%2/3
A and B
A= defined builtin::reftype($value)B= builtin::reftype($value) eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | my $thunk = Bolts::Artifact::Thunk->new( | |||||||||||||||||||||||||||||||||||||||||
| 63 | %$such_that, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | thunk => $value, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | $meta->_add_artifact($name => $thunk); | |||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | $meta->add_method($name => sub { $thunk }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # TODO It would be better to assert the validity of the checks on | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # the value immediately. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | my $thunk = Bolts::Artifact::Thunk->new( | ||||||||||||||||||||||||||||||||||||||||||
| 76 | %$such_that, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | ▶ | thunk => sub { $value }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | $meta->_add_artifact($name => $thunk); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | $meta->add_method($name => sub { $thunk }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 24 | ▶ | sub finish_bag { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finish_bag: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 24 | my ($meta) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 24 | $meta->make_immutable( | |||||||||||||||||||||||||||||||||||||||||
| 91 | replace_constructor => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | replace_destructor => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 24 | return $meta; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub _wrap_method_in_such_that_check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap_method_in_such_that_check: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my ($meta, $code, $such_that) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $wrapped; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (defined $such_that->{isa} or defined $such_that->{does}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $such_that->{"isa"} or defined $such_that->{"does"}
MC/DC0%0/2
defined $such_that->{"isa"} or defined $such_that->{"does"}
defined $such_that->{"isa"}
defined $such_that->{"does"}
Truth table0%0/3
A or B
A= defined $such_that->{"isa"}B= defined $such_that->{"does"}
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $wrapped = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $result = $code->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | $such_that->{isa}->assert_valid($result) | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if defined $such_that->{isa}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | $such_that->{does}->assert_valid($result) | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if defined $such_that->{does}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $wrapped = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | return scalar $code->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return $wrapped; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||||||||||||||||