blib/lib/Langertha/RunContext.pm

filter: Statementstmt 85.0% 51 / 60 Branchbran 46.1% 12 / 26 Conditioncond 28.5% 2 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 91.6% 11 / 12 Podpod 100% 3 / 3 totaltotal 70.5% 79 / 112 CC 17 SCAR 19.3
CC
17
Cov
70%
merge_branch
12.6
_clone_data
10.4
branch
5.3
CRAP 6.9
« blib/lib/Langertha/Virtual/Rules.pm ↑ Summary blib/lib/Langertha/Pricing.pm »
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
BranchTrueFalseTotal
unless ref $entry eq "HASH" 0 1 1
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
BranchTrueFalseTotal
if ($opts{"metadata"}) 1 0 1
63 croak "branch metadata must be a hashref"
64 1 ▶ unless ref($opts{metadata}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opts{"metadata"} eq "HASH" 0 1 1
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
BranchTrueFalseTotal
exists $opts{'input'} ? : 0 1 1
$self->has_history ? : 0 1 1
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
BranchTrueFalseTotal
unless builtin::blessed($branch) and $branch->isa(__PACKAGE__) 0 1 1
Condition33%1/3
builtin::blessed($branch) and $branch->isa(__PACKAGE__)
!ll&&!rl&&r
001
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__)
ABresult
0X0
100
111
84 unless blessed($branch) && $branch->isa(__PACKAGE__);
85  
86 1 ▶ my $slot = $opts{slot} // 'branches';
Condition50%1/2
$opts{"slot"} // "branches"
l!l
10
MC/DC0%0/1
$opts{"slot"} // "branches"
$opts{"slot"}
Truth table50%1/2
A
A= $opts{"slot"}
Aresult
11
00
87 my $name = defined $opts{name}
88 ? $opts{name}
89 0 ▶ : scalar(keys %{$self->artifacts->{$slot} // {}});
Branch: 1 branch
BranchTrueFalseTotal
defined $opts{'name'} ? : 1 0 1
Condition0%0/2
$self->artifacts->{$slot} // {}
l!l
00
MC/DC0%0/1
$self->artifacts->{$slot} // {}
$self->artifacts->{$slot}
Truth table0%0/2
A
A= $self->artifacts->{$slot}
Aresult
11
00
90  
91 $self->artifacts->{$slot} = {}
92 1 ▶ unless exists $self->artifacts->{$slot};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->artifacts->{$slot} 1 0 1
93 croak "artifact slot '$slot' must be a hashref"
94 1 ▶ unless ref($self->artifacts->{$slot}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->artifacts->{$slot} eq "HASH" 0 1 1
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
BranchTrueFalseTotal
unless ref $data 2 8 10
111  
112 8 my $copy = eval { dclone($data) };
113 8 ▶ return $copy if !$@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 8 0 8
114  
115 0 ▶ if (ref($data) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq "HASH") 0 0 0
116 0 return { %{$data} };
117 }
118 0 ▶ if (ref($data) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq "ARRAY") 0 0 0
119 0 return [ @{$data} ];
120 }
121 0 return $data;
122 }
123  
124 2 __PACKAGE__->meta->make_immutable;
125  
126 2 1;
127  
128 __END__
« blib/lib/Langertha/Virtual/Rules.pm ↑ Summary blib/lib/Langertha/Pricing.pm »