| 1 | package Langertha::RunContext; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Structured, dependency-free execution context for runnable nodes | ||||||||||||||||||||||||||||
| 3 | 2 | our $VERSION = '0.505'; | |||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Storable qw( dclone ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | has input => ( | |||||||||||||||||||||||||||
| 11 | is => 'rw', | ||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | has state => ( | ||||||||||||||||||||||||||||
| 16 | is => 'rw', | ||||||||||||||||||||||||||||
| 17 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 19 | 2 | ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | has artifacts => ( | ||||||||||||||||||||||||||||
| 23 | is => 'rw', | ||||||||||||||||||||||||||||
| 24 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 25 | 1 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 2 | ); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | has metadata => ( | ||||||||||||||||||||||||||||
| 30 | is => 'rw', | ||||||||||||||||||||||||||||
| 31 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 32 | 1 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 2 | ); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | has trace => ( | ||||||||||||||||||||||||||||
| 37 | is => 'rw', | ||||||||||||||||||||||||||||
| 38 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 39 | 1 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 2 | ); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | has history => ( | |||||||||||||||||||||||||||
| 44 | is => 'rw', | ||||||||||||||||||||||||||||
| 45 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 46 | predicate => 'has_history', | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub add_trace { | ||||||||||||||||||||||||||
|
Subroutine
add_trace: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 1 | my ( $self, $entry ) = @_; | |||||||||||||||||||||||||||
| 52 | 1 | ▶ | croak "trace entry must be a hashref" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | unless ref($entry) eq 'HASH'; | ||||||||||||||||||||||||||||
| 54 | 1 | push @{$self->trace}, $entry; | |||||||||||||||||||||||||||
| 55 | 1 | return $self; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | ▶ | sub branch { | ||||||||||||||||||||||||||
|
Subroutine
branch: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 1 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||
| 61 | 1 | my $metadata = _clone_data($self->metadata); | |||||||||||||||||||||||||||
| 62 | 1 | ▶ | if ($opts{metadata}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | croak "branch metadata must be a hashref" | ||||||||||||||||||||||||||||
| 64 | 1 | ▶ | unless ref($opts{metadata}) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 1 | $metadata = { %{$metadata}, %{$opts{metadata}} }; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | my $branch = __PACKAGE__->new( | ||||||||||||||||||||||||||||
| 69 | 1 | ▶ | input => _clone_data(exists $opts{input} ? $opts{input} : $self->input), | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 70 | state => _clone_data($self->state), | ||||||||||||||||||||||||||||
| 71 | artifacts => _clone_data($self->artifacts), | ||||||||||||||||||||||||||||
| 72 | metadata => $metadata, | ||||||||||||||||||||||||||||
| 73 | trace => _clone_data($self->trace), | ||||||||||||||||||||||||||||
| 74 | ($self->has_history ? (history => _clone_data($self->history)) : ()), | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | return $branch; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | ▶ | sub merge_branch { | ||||||||||||||||||||||||||
|
Subroutine
merge_branch: called CC=8 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 1 | my ( $self, $branch, %opts ) = @_; | |||||||||||||||||||||||||||
| 83 | 1 | ▶ | croak "merge_branch expects a Langertha::RunContext" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($branch) and $branch->isa(__PACKAGE__)
MC/DC0%0/2
builtin::blessed($branch) and $branch->isa(__PACKAGE__)
builtin::blessed($branch)
$branch->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($branch)B= $branch->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||
| 84 | unless blessed($branch) && $branch->isa(__PACKAGE__); | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | ▶ | my $slot = $opts{slot} // 'branches'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"slot"} // "branches"
MC/DC0%0/1
$opts{"slot"} // "branches"
$opts{"slot"}
Truth table50%1/2
A
A= $opts{"slot"}
| |||||||||||||||||||||||||||||
| 87 | my $name = defined $opts{name} | ||||||||||||||||||||||||||||
| 88 | ? $opts{name} | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | : scalar(keys %{$self->artifacts->{$slot} // {}}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->artifacts->{$slot} // {}
MC/DC0%0/1
$self->artifacts->{$slot} // {}
$self->artifacts->{$slot}
Truth table0%0/2
A
A= $self->artifacts->{$slot}
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | $self->artifacts->{$slot} = {} | ||||||||||||||||||||||||||||
| 92 | 1 | ▶ | unless exists $self->artifacts->{$slot}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | croak "artifact slot '$slot' must be a hashref" | ||||||||||||||||||||||||||||
| 94 | 1 | ▶ | unless ref($self->artifacts->{$slot}) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 1 | $self->artifacts->{$slot}{$name} = { | |||||||||||||||||||||||||||
| 97 | input => _clone_data($branch->input), | ||||||||||||||||||||||||||||
| 98 | state => _clone_data($branch->state), | ||||||||||||||||||||||||||||
| 99 | artifacts => _clone_data($branch->artifacts), | ||||||||||||||||||||||||||||
| 100 | metadata => _clone_data($branch->metadata), | ||||||||||||||||||||||||||||
| 101 | trace => _clone_data($branch->trace), | ||||||||||||||||||||||||||||
| 102 | }; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | return $self; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 10 | ▶ | sub _clone_data { | ||||||||||||||||||||||||||
|
Subroutine
_clone_data: called CC=5 SCAR=23.4
| |||||||||||||||||||||||||||||
| 109 | 10 | my ( $data ) = @_; | |||||||||||||||||||||||||||
| 110 | 10 | ▶ | return $data unless ref($data); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 8 | my $copy = eval { dclone($data) }; | |||||||||||||||||||||||||||
| 113 | 8 | ▶ | return $copy if !$@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if (ref($data) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | return { %{$data} }; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if (ref($data) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | return [ @{$data} ]; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 0 | return $data; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 2 | 1; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||