| 1 | package App::RecordStream::DomainLanguage::Snippet; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 29 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 29 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 29 | ▶ | use App::RecordStream::DomainLanguage::Executor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 29 | ▶ | use App::RecordStream::DomainLanguage::Value; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 29 | ▶ | use App::RecordStream::Executor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 11 | { | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 432 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 432 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 432 | my $vars = shift; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 432 | $code = App::RecordStream::Executor->transform_code($code); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 432 | $code = _transform_angles($code); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 432 | my $this = | |||||||||||||||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 'CODE' => $code, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 'VARS' => $vars, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 432 | bless $this, $class; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 432 | return $this; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | sub evaluate_as | ||||||||||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 378 | ▶ | my $this = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate_as: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 378 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 378 | ▶ | my $vars = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 378 | my $executor = App::RecordStream::DomainLanguage::Executor->new(); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 378 | $executor->import_registry(); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 378 | for my $var (%{$this->{'VARS'}}) | |||||||||||||||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 42 | for my $ref (@{$this->{'VARS'}->{$var}}) | |||||||||||||||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 36 | $executor->set_ref($var, $ref); | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 378 | for my $var (keys(%$vars)) | |||||||||||||||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 287 | ▶ | if(0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | elsif($var =~ /^\$(.*)$/) | ||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 287 | $executor->set_scalar($1, $vars->{$var}); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | else | ||||||||||||||||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | die "Bad var for snippet: '$var'"; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 378 | my $result = $executor->exec($this->{'CODE'}); | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 378 | return App::RecordStream::DomainLanguage::Value::cast_or_die($type, $result); | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | sub _transform_angles | ||||||||||||||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 432 | ▶ | my $code = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_transform_angles: called CC=9 SCAR=23.8
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 432 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 432 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 432 | while(1) | |||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 478 | my $top_level_entrance = index($code, '<<', $pos); | |||||||||||||||||||||||||||||||||||||||||
| 75 | 478 | ▶ | if($top_level_entrance == -1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 432 | $out .= substr($code, $pos); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 432 | last; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 46 | my $level = 1; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 46 | my $pos2 = $top_level_entrance + 2; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 46 | my $top_level_exit; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 46 | while(1) | |||||||||||||||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 46 | my $next_enter = index($code, '<<', $pos2); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 46 | my $next_exit = index($code, '>>', $pos2); | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 46 | ▶ | if($next_enter != -1 && ($next_exit == -1 || $next_enter < $next_exit)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$next_enter != -1 and $next_exit == -1 || $next_enter < $next_exit
$next_exit == -1 or $next_enter < $next_exit
MC/DC0%0/3
$next_enter != -1 and $next_exit == -1 || $next_enter < $next_exit
$next_enter != -1
$next_exit == -1
$next_enter < $next_exit
Truth table50%2/4
A and B or C
A= $next_enter != -1B= $next_exit == -1C= $next_enter < $next_exit
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ++$level; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $pos2 = $next_enter + 2; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 46 | ▶ | if($next_exit != -1 && ($next_enter == -1 || $next_exit < $next_enter)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$next_exit != -1 and $next_enter == -1 || $next_exit < $next_enter
$next_enter == -1 or $next_exit < $next_enter
MC/DC0%0/3
$next_exit != -1 and $next_enter == -1 || $next_exit < $next_enter
$next_exit != -1
$next_enter == -1
$next_exit < $next_enter
Truth table25%1/4
A and B or C
A= $next_exit != -1B= $next_enter == -1C= $next_exit < $next_enter
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 46 | --$level; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 46 | ▶ | if($level == 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 46 | $top_level_exit = $next_exit; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 46 | last; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $pos2 = $next_enter + 2; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | die "Unbalanced << and >> in snippet: $code"; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 46 | $out .= substr($code, $pos, $top_level_entrance - $pos); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 46 | $out .= _quote_snippet(substr($code, $top_level_entrance + 2, $top_level_exit - $top_level_entrance - 2)); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 46 | $pos = $top_level_exit + 2; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 432 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | sub _quote_snippet | ||||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 46 | ▶ | my $code = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quote_snippet: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 46 | my @vars; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 46 | ▶ | if($code =~ s/^([a-zA-Z_][a-zA-Z_0-9]*(,[a-zA-Z_][a-zA-Z_0-9]*)*)\|//) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 4 | @vars = split(/,/, $1); | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | # Could not get typeglobs to work. References go in, references come out, | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # you can't explain that... | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 46 | return "snip(App::RecordStream::DomainLanguage::Snippet->new('$code', {" . join(", ", map { "'$_' => [\\\$$_, \\\@$_, \\\%$_]" } @vars) . "}))"; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 29 | 1; | |||||||||||||||||||||||||||||||||||||||||