| 1 | package Outthentic::Story; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use base 'Exporter'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use Outthentic::DSL; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Outthentic::Story::Stat; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use File::ShareDir; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use JSON; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use Time::localtime; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | ▶ | use File::Path::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use Term::ANSIColor; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 1 | our @EXPORT = qw{ | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | new_story end_of_story set_story story_cache_dir | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | get_prop set_prop | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | debug_mod1 debug_mod2 debug_mod12 | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | set_stdout get_stdout stdout_file | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | dsl captures capture stream match_lines | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | run_story apply_story_vars story_var story_vars_pretty | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | do_perl_hook | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | do_ruby_hook | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | do_python_hook | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | do_bash_hook | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | do_ps_hook | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | ignore_story_err | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | quit | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | outthentic_die | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | project_root_dir | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | test_root_dir | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | cache_root_dir | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | host | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | dump_os | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 1 | our @stories = (); | |||||||||||||||||||
| 58 | 1 | our $OS; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | ▶ | sub new_story { | ||||||||||||||||||
|
Subroutine
new_story: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | my $self = { | |||||||||||||||||||
| 64 | ID => scalar(@stories), | ||||||||||||||||||||
| 65 | props => { | ||||||||||||||||||||
| 66 | ignore_story_err => 0 , | ||||||||||||||||||||
| 67 | dsl => Outthentic::DSL->new() , | ||||||||||||||||||||
| 68 | story_vars => {} }, | ||||||||||||||||||||
| 69 | }; | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | push @stories, $self; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 0 | 1; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | ▶ | sub end_of_story { | ||||||||||||||||||
|
Subroutine
end_of_story: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | if (debug_mod12()){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | 0 | main::note("end of story: ".(get_prop('story'))); | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | delete $stories[-1]; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | ▶ | sub set_story { | ||||||||||||||||||
|
Subroutine
set_story: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | my $dist_lib_dir = File::ShareDir::dist_dir('Outthentic'); | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | my $ruby_run_cmd; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | if (-f project_root_dir()."/Gemfile" ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 0 | $ruby_run_cmd = "cd ".project_root_dir()." && bundle exec ruby -I $dist_lib_dir -r outthentic -I ".story_cache_dir() | |||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||
| 96 | 0 | $ruby_run_cmd = "ruby -I $dist_lib_dir -r outthentic -I ".story_cache_dir(); | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | my $python_run_cmd = "PYTHONPATH=\$PYTHONPATH:".(story_cache_dir()).":$dist_lib_dir python"; | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | get_prop('dsl')->{languages}->{ruby} = $ruby_run_cmd; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 0 | get_prop('dsl')->{languages}->{python} = $python_run_cmd; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | get_prop('dsl')->{cache_dir} = story_cache_dir(); | |||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 0 | my $bash_run_opts = "source "._bash_glue_file()." && source $dist_lib_dir/outthentic.bash"; | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | get_prop('dsl')->{languages}->{ruby} = $ruby_run_cmd; | |||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 0 | get_prop('dsl')->{languages}->{bash} = $bash_run_opts; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 0 | _make_cache_dir(); | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | _mk_perl_glue_file(); | |||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | _mk_ruby_glue_file(); | |||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 0 | _mk_python_glue_file(); | |||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 0 | _mk_bash_glue_file(); | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 0 | _mk_ps_glue_file(); | |||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 0 | ▶ | sub _story { | ||||||||||||||||||
|
Subroutine
_story: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 128 | 0 | @stories[-1]; | |||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 0 | ▶ | sub _story_id { | ||||||||||||||||||
|
Subroutine
_story_id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 132 | 0 | _story()->{ID}; | |||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 0 | ▶ | sub get_prop { | ||||||||||||||||||
|
Subroutine
get_prop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 0 | my $name = shift; | |||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 0 | _story()->{props}->{$name}; | |||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | } | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 0 | ▶ | sub set_prop { | ||||||||||||||||||
|
Subroutine
set_prop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 0 | my $name = shift; | |||||||||||||||||||
| 146 | 0 | my $value = shift; | |||||||||||||||||||
| 147 | 0 | _story()->{props}->{$name} = $value; | |||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | } | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | 0 | ▶ | sub project_root_dir { | ||||||||||||||||||
|
Subroutine
project_root_dir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 153 | 0 | get_prop('project_root_dir'); | |||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 0 | ▶ | sub test_root_dir { # this one is deprected and exists for back compatibilty, use cache_root_dir instead | ||||||||||||||||||
|
Subroutine
test_root_dir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 158 | 0 | get_prop('cache_root_dir'); | |||||||||||||||||||
| 159 | } | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 0 | ▶ | sub cache_root_dir { | ||||||||||||||||||
|
Subroutine
cache_root_dir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 162 | 0 | get_prop('cache_root_dir'); | |||||||||||||||||||
| 163 | } | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | 0 | ▶ | sub host { | ||||||||||||||||||
|
Subroutine
host: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 166 | 0 | get_prop('host'); | |||||||||||||||||||
| 167 | } | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | 0 | ▶ | sub ignore_story_err { | ||||||||||||||||||
|
Subroutine
ignore_story_err: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 0 | my $val = shift; | |||||||||||||||||||
| 172 | 0 | my $rv; | |||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | 0 | ▶ | if (defined $val){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 175 | 0 | set_prop('ignore_story_err',$val); | |||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||
| 177 | 0 | $rv = get_prop('ignore_story_err'); | |||||||||||||||||||
| 178 | } | ||||||||||||||||||||
| 179 | 0 | $rv; | |||||||||||||||||||
| 180 | } | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | 0 | ▶ | sub debug_mod1 { | ||||||||||||||||||
|
Subroutine
debug_mod1: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | 0 | get_prop('debug') == 1 | |||||||||||||||||||
| 186 | } | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | 0 | ▶ | sub debug_mod2 { | ||||||||||||||||||
|
Subroutine
debug_mod2: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | 0 | get_prop('debug') == 2 | |||||||||||||||||||
| 191 | } | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | 0 | ▶ | sub debug_mod12 { | ||||||||||||||||||
|
Subroutine
debug_mod12: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | 0 | ▶ | debug_mod1() or debug_mod2() | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 196 | } | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | 0 | ▶ | sub set_stdout { | ||||||||||||||||||
|
Subroutine
set_stdout: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | 0 | my $line = shift; | |||||||||||||||||||
| 202 | 0 | ▶ | open FSTDOUT, ">>", stdout_file() or die $!; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 203 | 0 | print FSTDOUT $line, "\n"; | |||||||||||||||||||
| 204 | 0 | close FSTDOUT; | |||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | } | ||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | 0 | ▶ | sub get_stdout { | ||||||||||||||||||
|
Subroutine
get_stdout: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | 0 | ▶ | return unless -f stdout_file(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | 0 | my $data; | |||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | 0 | ▶ | open FSTDOUT, stdout_file() or die $!; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 215 | 0 | my $data = join "", <FSTDOUT>; | |||||||||||||||||||
| 216 | 0 | close FSTDOUT; | |||||||||||||||||||
| 217 | 0 | $data; | |||||||||||||||||||
| 218 | } | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | 0 | ▶ | sub stdout_file { | ||||||||||||||||||
|
Subroutine
stdout_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | 0 | story_cache_dir()."/std.out" | |||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | } | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | 0 | ▶ | sub _make_cache_dir { | ||||||||||||||||||
|
Subroutine
_make_cache_dir: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | 0 | my $cache_dir = cache_root_dir()."/story-"._story_id(); | |||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | 0 | ▶ | if (debug_mod12()){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 231 | 0 | main::note("make cache dir: $cache_dir"); | |||||||||||||||||||
| 232 | } | ||||||||||||||||||||
| 233 | 0 | ▶ | File::Path::Tiny::mk($cache_dir) or die "can't create $cache_dir, error: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 234 | 0 | ▶ | File::Path::Tiny::empty_dir($cache_dir) or die "can't empty $cache_dir, error: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 235 | } | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | 0 | ▶ | sub story_cache_dir { | ||||||||||||||||||
|
Subroutine
story_cache_dir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 238 | 0 | cache_root_dir()."/story-"._story_id(); | |||||||||||||||||||
| 239 | } | ||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | 0 | ▶ | sub _perl_glue_file { | ||||||||||||||||||
|
Subroutine
_perl_glue_file: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 242 | 0 | story_cache_dir()."/glue.pm"; | |||||||||||||||||||
| 243 | } | ||||||||||||||||||||
| 244 | |||||||||||||||||||||
| 245 | 0 | ▶ | sub _ruby_glue_file { | ||||||||||||||||||
|
Subroutine
_ruby_glue_file: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 246 | 0 | story_cache_dir()."/glue.rb"; | |||||||||||||||||||
| 247 | } | ||||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | 0 | ▶ | sub _python_glue_file { | ||||||||||||||||||
|
Subroutine
_python_glue_file: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 250 | 0 | story_cache_dir()."/glue.py"; | |||||||||||||||||||
| 251 | } | ||||||||||||||||||||
| 252 | |||||||||||||||||||||
| 253 | 0 | ▶ | sub _bash_glue_file { | ||||||||||||||||||
|
Subroutine
_bash_glue_file: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 254 | 0 | story_cache_dir()."/glue.bash"; | |||||||||||||||||||
| 255 | } | ||||||||||||||||||||
| 256 | |||||||||||||||||||||
| 257 | 0 | ▶ | sub _ps_glue_file { | ||||||||||||||||||
|
Subroutine
_ps_glue_file: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 258 | 0 | story_cache_dir()."/glue.ps1"; | |||||||||||||||||||
| 259 | } | ||||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | 0 | ▶ | sub dsl { | ||||||||||||||||||
|
Subroutine
dsl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 262 | 0 | get_prop('dsl') | |||||||||||||||||||
| 263 | } | ||||||||||||||||||||
| 264 | |||||||||||||||||||||
| 265 | 0 | ▶ | sub stream { | ||||||||||||||||||
|
Subroutine
stream: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 266 | 0 | dsl()->stream | |||||||||||||||||||
| 267 | } | ||||||||||||||||||||
| 268 | |||||||||||||||||||||
| 269 | 0 | ▶ | sub captures { | ||||||||||||||||||
|
Subroutine
captures: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 270 | |||||||||||||||||||||
| 271 | dsl()->{captures} | ||||||||||||||||||||
| 272 | 0 | } | |||||||||||||||||||
| 273 | |||||||||||||||||||||
| 274 | 0 | ▶ | sub capture { | ||||||||||||||||||
|
Subroutine
capture: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 275 | 0 | dsl()->{captures}->[0] | |||||||||||||||||||
| 276 | } | ||||||||||||||||||||
| 277 | |||||||||||||||||||||
| 278 | 0 | ▶ | sub match_lines { | ||||||||||||||||||
|
Subroutine
match_lines: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 279 | |||||||||||||||||||||
| 280 | dsl()->{match_lines} | ||||||||||||||||||||
| 281 | 0 | } | |||||||||||||||||||
| 282 | |||||||||||||||||||||
| 283 | 0 | ▶ | sub run_story { | ||||||||||||||||||
|
Subroutine
run_story: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||
| 284 | |||||||||||||||||||||
| 285 | 0 | my $path = shift; | |||||||||||||||||||
| 286 | |||||||||||||||||||||
| 287 | 0 | ▶ | my $story_vars = shift || {}; | ||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 288 | |||||||||||||||||||||
| 289 | 0 | Outthentic::Story::Stat->new_story({ | |||||||||||||||||||
| 290 | vars => $story_vars, | ||||||||||||||||||||
| 291 | path => $path | ||||||||||||||||||||
| 292 | }); | ||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | 0 | my $cache_root_dir = get_prop('cache_root_dir'); | |||||||||||||||||||
| 295 | |||||||||||||||||||||
| 296 | 0 | my $project_root_dir = get_prop('project_root_dir'); | |||||||||||||||||||
| 297 | |||||||||||||||||||||
| 298 | 0 | my $story_module = "$cache_root_dir/modules/$path/story.outth"; | |||||||||||||||||||
| 299 | |||||||||||||||||||||
| 300 | 0 | ▶ | die "story module file $story_module does not exist" unless -e $story_module; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 301 | |||||||||||||||||||||
| 302 | 0 | ▶ | if (debug_mod12()){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 303 | 0 | main::note("run downstream story: $path"); | |||||||||||||||||||
| 304 | 0 | for my $k (keys %{$story_vars}){ | |||||||||||||||||||
| 305 | 0 | my $v = $story_vars->{$k}; | |||||||||||||||||||
| 306 | 0 | main::note("downstream story var: $k => $v"); | |||||||||||||||||||
| 307 | } | ||||||||||||||||||||
| 308 | } | ||||||||||||||||||||
| 309 | |||||||||||||||||||||
| 310 | { | ||||||||||||||||||||
| 311 | 0 | package main; | |||||||||||||||||||
| 312 | 0 | ▶ | unless (do $story_module) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 313 | 0 | ▶ | die "couldn't parse story module file $story_module: $@" if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 314 | } | ||||||||||||||||||||
| 315 | } | ||||||||||||||||||||
| 316 | |||||||||||||||||||||
| 317 | # return statistic for downstream story just executed | ||||||||||||||||||||
| 318 | 0 | return Outthentic::Story::Stat->current; | |||||||||||||||||||
| 319 | } | ||||||||||||||||||||
| 320 | |||||||||||||||||||||
| 321 | 0 | ▶ | sub do_perl_hook { | ||||||||||||||||||
|
Subroutine
do_perl_hook: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 322 | |||||||||||||||||||||
| 323 | 0 | my $hook_file = shift; | |||||||||||||||||||
| 324 | |||||||||||||||||||||
| 325 | 0 | ▶ | print_hook_header() if debug_mod1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 326 | |||||||||||||||||||||
| 327 | { | ||||||||||||||||||||
| 328 | 0 | package main; | |||||||||||||||||||
| 329 | 0 | ▶ | unless (do $hook_file) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 330 | 0 | ▶ | die "couldn't parse perl hook file $hook_file: $@" if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 331 | } | ||||||||||||||||||||
| 332 | } | ||||||||||||||||||||
| 333 | |||||||||||||||||||||
| 334 | 0 | return 1; | |||||||||||||||||||
| 335 | } | ||||||||||||||||||||
| 336 | |||||||||||||||||||||
| 337 | 0 | ▶ | sub quit { | ||||||||||||||||||
|
Subroutine
quit: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 338 | 0 | my $msg = shift; | |||||||||||||||||||
| 339 | 0 | chomp($msg); | |||||||||||||||||||
| 340 | 0 | main::print_story_header(); | |||||||||||||||||||
| 341 | 0 | main::note("? forcefully exit: $msg"); | |||||||||||||||||||
| 342 | 0 | exit(0); | |||||||||||||||||||
| 343 | } | ||||||||||||||||||||
| 344 | |||||||||||||||||||||
| 345 | 0 | ▶ | sub outthentic_die { | ||||||||||||||||||
|
Subroutine
outthentic_die: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 346 | 0 | my $msg = shift; | |||||||||||||||||||
| 347 | 0 | chomp($msg); | |||||||||||||||||||
| 348 | 0 | main::print_story_header(); | |||||||||||||||||||
| 349 | 0 | main::note("!! forcefully die: $msg"); | |||||||||||||||||||
| 350 | 0 | $main::STATUS = 0; | |||||||||||||||||||
| 351 | 0 | exit(1); | |||||||||||||||||||
| 352 | } | ||||||||||||||||||||
| 353 | |||||||||||||||||||||
| 354 | 0 | ▶ | sub _mk_perl_glue_file { | ||||||||||||||||||
|
Subroutine
_mk_perl_glue_file: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 355 | |||||||||||||||||||||
| 356 | 0 | ▶ | open PERL_GLUE, ">", _perl_glue_file() or confess "can't create perl glue file ".(_perl_glue_file())." : $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 357 | |||||||||||||||||||||
| 358 | 0 | my $cache_root_dir = cache_root_dir(); | |||||||||||||||||||
| 359 | 0 | my $story_dir = get_prop('story_dir'); | |||||||||||||||||||
| 360 | 0 | my $project_root_dir = project_root_dir(); | |||||||||||||||||||
| 361 | 0 | my $debug_mod12 = debug_mod12(); | |||||||||||||||||||
| 362 | 0 | my $cache_dir = story_cache_dir; | |||||||||||||||||||
| 363 | |||||||||||||||||||||
| 364 | 0 | my $os = _resolve_os(); | |||||||||||||||||||
| 365 | |||||||||||||||||||||
| 366 | 0 | print PERL_GLUE <<"CODE"; | |||||||||||||||||||
| 367 | |||||||||||||||||||||
| 368 | package glue; | ||||||||||||||||||||
| 369 | 1; | ||||||||||||||||||||
| 370 | |||||||||||||||||||||
| 371 | package main; | ||||||||||||||||||||
| 372 | use strict; | ||||||||||||||||||||
| 373 | |||||||||||||||||||||
| 374 | sub debug_mod12 { | ||||||||||||||||||||
| 375 | $debug_mod12 | ||||||||||||||||||||
| 376 | } | ||||||||||||||||||||
| 377 | |||||||||||||||||||||
| 378 | sub cach_root_dir { | ||||||||||||||||||||
| 379 | '$cache_root_dir' | ||||||||||||||||||||
| 380 | } | ||||||||||||||||||||
| 381 | |||||||||||||||||||||
| 382 | sub test_root_dir { | ||||||||||||||||||||
| 383 | '$cache_root_dir' | ||||||||||||||||||||
| 384 | } | ||||||||||||||||||||
| 385 | |||||||||||||||||||||
| 386 | sub project_root_dir { | ||||||||||||||||||||
| 387 | '$project_root_dir' | ||||||||||||||||||||
| 388 | } | ||||||||||||||||||||
| 389 | |||||||||||||||||||||
| 390 | sub cache_dir { | ||||||||||||||||||||
| 391 | '$cache_dir' | ||||||||||||||||||||
| 392 | } | ||||||||||||||||||||
| 393 | |||||||||||||||||||||
| 394 | sub story_dir { | ||||||||||||||||||||
| 395 | '$story_dir' | ||||||||||||||||||||
| 396 | } | ||||||||||||||||||||
| 397 | |||||||||||||||||||||
| 398 | sub os { '$os' } | ||||||||||||||||||||
| 399 | |||||||||||||||||||||
| 400 | |||||||||||||||||||||
| 401 | 1; | ||||||||||||||||||||
| 402 | |||||||||||||||||||||
| 403 | CODE | ||||||||||||||||||||
| 404 | |||||||||||||||||||||
| 405 | 0 | close PERL_GLUE; | |||||||||||||||||||
| 406 | |||||||||||||||||||||
| 407 | } | ||||||||||||||||||||
| 408 | |||||||||||||||||||||
| 409 | 0 | ▶ | sub _mk_ruby_glue_file { | ||||||||||||||||||
|
Subroutine
_mk_ruby_glue_file: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 410 | |||||||||||||||||||||
| 411 | 0 | ▶ | open RUBY_GLUE, ">", _ruby_glue_file() or die $!; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 412 | |||||||||||||||||||||
| 413 | 0 | my $stdout_file = stdout_file(); | |||||||||||||||||||
| 414 | 0 | my $cache_root_dir = cache_root_dir(); | |||||||||||||||||||
| 415 | 0 | my $story_dir = get_prop('story_dir'); | |||||||||||||||||||
| 416 | 0 | my $project_root_dir = project_root_dir(); | |||||||||||||||||||
| 417 | 0 | my $debug_mod12 = debug_mod12(); | |||||||||||||||||||
| 418 | |||||||||||||||||||||
| 419 | 0 | my $cache_dir = story_cache_dir; | |||||||||||||||||||
| 420 | |||||||||||||||||||||
| 421 | 0 | print RUBY_GLUE <<"CODE"; | |||||||||||||||||||
| 422 | |||||||||||||||||||||
| 423 | def debug_mod12 | ||||||||||||||||||||
| 424 | '$debug_mod12' | ||||||||||||||||||||
| 425 | end | ||||||||||||||||||||
| 426 | |||||||||||||||||||||
| 427 | def cache_root_dir | ||||||||||||||||||||
| 428 | '$cache_root_dir' | ||||||||||||||||||||
| 429 | end | ||||||||||||||||||||
| 430 | |||||||||||||||||||||
| 431 | def test_root_dir | ||||||||||||||||||||
| 432 | '$cache_root_dir' | ||||||||||||||||||||
| 433 | end | ||||||||||||||||||||
| 434 | |||||||||||||||||||||
| 435 | def project_root_dir | ||||||||||||||||||||
| 436 | '$project_root_dir' | ||||||||||||||||||||
| 437 | end | ||||||||||||||||||||
| 438 | |||||||||||||||||||||
| 439 | def cache_dir | ||||||||||||||||||||
| 440 | '$cache_dir' | ||||||||||||||||||||
| 441 | end | ||||||||||||||||||||
| 442 | |||||||||||||||||||||
| 443 | def story_dir | ||||||||||||||||||||
| 444 | '$story_dir' | ||||||||||||||||||||
| 445 | end | ||||||||||||||||||||
| 446 | |||||||||||||||||||||
| 447 | def stdout_file | ||||||||||||||||||||
| 448 | '$stdout_file' | ||||||||||||||||||||
| 449 | end | ||||||||||||||||||||
| 450 | |||||||||||||||||||||
| 451 | CODE | ||||||||||||||||||||
| 452 | |||||||||||||||||||||
| 453 | 0 | close RUBY_GLUE; | |||||||||||||||||||
| 454 | |||||||||||||||||||||
| 455 | } | ||||||||||||||||||||
| 456 | |||||||||||||||||||||
| 457 | 0 | ▶ | sub _mk_python_glue_file { | ||||||||||||||||||
|
Subroutine
_mk_python_glue_file: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 458 | |||||||||||||||||||||
| 459 | 0 | ▶ | open PYTHON_GLUE, ">", _python_glue_file() or die $!; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 460 | |||||||||||||||||||||
| 461 | 0 | my $stdout_file = stdout_file(); | |||||||||||||||||||
| 462 | 0 | my $cache_root_dir = cache_root_dir(); | |||||||||||||||||||
| 463 | 0 | my $story_dir = get_prop('story_dir'); | |||||||||||||||||||
| 464 | 0 | my $project_root_dir = project_root_dir(); | |||||||||||||||||||
| 465 | 0 | my $debug_mod12 = debug_mod12(); | |||||||||||||||||||
| 466 | |||||||||||||||||||||
| 467 | 0 | my $cache_dir = story_cache_dir; | |||||||||||||||||||
| 468 | |||||||||||||||||||||
| 469 | 0 | print PYTHON_GLUE <<"CODE"; | |||||||||||||||||||
| 470 | |||||||||||||||||||||
| 471 | def debug_mod12(): | ||||||||||||||||||||
| 472 | return $debug_mod12 | ||||||||||||||||||||
| 473 | |||||||||||||||||||||
| 474 | def cache_root_dir(): | ||||||||||||||||||||
| 475 | return '$cache_root_dir' | ||||||||||||||||||||
| 476 | |||||||||||||||||||||
| 477 | def test_root_dir(): | ||||||||||||||||||||
| 478 | return '$cache_root_dir' | ||||||||||||||||||||
| 479 | |||||||||||||||||||||
| 480 | def project_root_dir(): | ||||||||||||||||||||
| 481 | return '$project_root_dir' | ||||||||||||||||||||
| 482 | |||||||||||||||||||||
| 483 | def cache_dir(): | ||||||||||||||||||||
| 484 | return '$cache_dir' | ||||||||||||||||||||
| 485 | |||||||||||||||||||||
| 486 | def story_dir(): | ||||||||||||||||||||
| 487 | return '$story_dir' | ||||||||||||||||||||
| 488 | |||||||||||||||||||||
| 489 | def stdout_file(): | ||||||||||||||||||||
| 490 | return '$stdout_file' | ||||||||||||||||||||
| 491 | |||||||||||||||||||||
| 492 | CODE | ||||||||||||||||||||
| 493 | |||||||||||||||||||||
| 494 | 0 | close PYTHON_GLUE; | |||||||||||||||||||
| 495 | |||||||||||||||||||||
| 496 | } | ||||||||||||||||||||
| 497 | |||||||||||||||||||||
| 498 | 0 | ▶ | sub _mk_bash_glue_file { | ||||||||||||||||||
|
Subroutine
_mk_bash_glue_file: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 499 | |||||||||||||||||||||
| 500 | |||||||||||||||||||||
| 501 | 0 | my $story_dir = get_prop('story_dir'); | |||||||||||||||||||
| 502 | |||||||||||||||||||||
| 503 | 0 | ▶ | open BASH_GLUE, ">", _bash_glue_file() or die $!; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 504 | |||||||||||||||||||||
| 505 | 0 | my $stdout_file = stdout_file(); | |||||||||||||||||||
| 506 | 0 | my $cache_root_dir = cache_root_dir(); | |||||||||||||||||||
| 507 | 0 | my $project_root_dir = project_root_dir(); | |||||||||||||||||||
| 508 | 0 | my $debug_mod12 = debug_mod12(); | |||||||||||||||||||
| 509 | |||||||||||||||||||||
| 510 | 0 | my $cache_dir = story_cache_dir; | |||||||||||||||||||
| 511 | |||||||||||||||||||||
| 512 | 0 | my $os = _resolve_os(); | |||||||||||||||||||
| 513 | |||||||||||||||||||||
| 514 | 0 | print BASH_GLUE <<"CODE"; | |||||||||||||||||||
| 515 | |||||||||||||||||||||
| 516 | debug_mod=debug_mod12 | ||||||||||||||||||||
| 517 | |||||||||||||||||||||
| 518 | test_root_dir=$cache_root_dir | ||||||||||||||||||||
| 519 | |||||||||||||||||||||
| 520 | cache_root_dir=$cache_root_dir | ||||||||||||||||||||
| 521 | |||||||||||||||||||||
| 522 | project_root_dir=$project_root_dir | ||||||||||||||||||||
| 523 | |||||||||||||||||||||
| 524 | cache_dir=$cache_dir | ||||||||||||||||||||
| 525 | |||||||||||||||||||||
| 526 | story_dir=$story_dir | ||||||||||||||||||||
| 527 | |||||||||||||||||||||
| 528 | stdout_file=$stdout_file | ||||||||||||||||||||
| 529 | |||||||||||||||||||||
| 530 | os=$os | ||||||||||||||||||||
| 531 | |||||||||||||||||||||
| 532 | CODE | ||||||||||||||||||||
| 533 | |||||||||||||||||||||
| 534 | 0 | close BASH_GLUE; | |||||||||||||||||||
| 535 | |||||||||||||||||||||
| 536 | } | ||||||||||||||||||||
| 537 | |||||||||||||||||||||
| 538 | 0 | ▶ | sub _mk_ps_glue_file { | ||||||||||||||||||
|
Subroutine
_mk_ps_glue_file: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 539 | |||||||||||||||||||||
| 540 | 0 | ▶ | open PS_GLUE, ">", _ps_glue_file() or die $!; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 541 | |||||||||||||||||||||
| 542 | 0 | my $stdout_file = stdout_file(); | |||||||||||||||||||
| 543 | 0 | my $cache_root_dir = cache_root_dir(); | |||||||||||||||||||
| 544 | 0 | my $story_dir = get_prop('story_dir'); | |||||||||||||||||||
| 545 | 0 | my $project_root_dir = project_root_dir(); | |||||||||||||||||||
| 546 | 0 | my $debug_mod12 = debug_mod12(); | |||||||||||||||||||
| 547 | |||||||||||||||||||||
| 548 | 0 | my $cache_dir = story_cache_dir; | |||||||||||||||||||
| 549 | |||||||||||||||||||||
| 550 | 0 | print PS_GLUE <<"CODE"; | |||||||||||||||||||
| 551 | |||||||||||||||||||||
| 552 | function debug_mod12 { | ||||||||||||||||||||
| 553 | '$debug_mod12' | ||||||||||||||||||||
| 554 | } | ||||||||||||||||||||
| 555 | |||||||||||||||||||||
| 556 | function cache_root_dir { | ||||||||||||||||||||
| 557 | '$cache_root_dir' | ||||||||||||||||||||
| 558 | } | ||||||||||||||||||||
| 559 | |||||||||||||||||||||
| 560 | function test_root_dir { | ||||||||||||||||||||
| 561 | '$cache_root_dir' | ||||||||||||||||||||
| 562 | } | ||||||||||||||||||||
| 563 | |||||||||||||||||||||
| 564 | function project_root_dir { | ||||||||||||||||||||
| 565 | '$project_root_dir' | ||||||||||||||||||||
| 566 | } | ||||||||||||||||||||
| 567 | |||||||||||||||||||||
| 568 | function cache_dir { | ||||||||||||||||||||
| 569 | '$cache_dir' | ||||||||||||||||||||
| 570 | } | ||||||||||||||||||||
| 571 | |||||||||||||||||||||
| 572 | function story_dir { | ||||||||||||||||||||
| 573 | '$story_dir' | ||||||||||||||||||||
| 574 | } | ||||||||||||||||||||
| 575 | |||||||||||||||||||||
| 576 | function stdout_file { | ||||||||||||||||||||
| 577 | '$stdout_file' | ||||||||||||||||||||
| 578 | } | ||||||||||||||||||||
| 579 | |||||||||||||||||||||
| 580 | CODE | ||||||||||||||||||||
| 581 | |||||||||||||||||||||
| 582 | 0 | close PS_GLUE; | |||||||||||||||||||
| 583 | |||||||||||||||||||||
| 584 | } | ||||||||||||||||||||
| 585 | |||||||||||||||||||||
| 586 | 0 | ▶ | sub do_ruby_hook { | ||||||||||||||||||
|
Subroutine
do_ruby_hook: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||
| 587 | |||||||||||||||||||||
| 588 | 0 | my $file = shift; | |||||||||||||||||||
| 589 | |||||||||||||||||||||
| 590 | 0 | my $ruby_lib_dir = File::ShareDir::dist_dir('Outthentic'); | |||||||||||||||||||
| 591 | |||||||||||||||||||||
| 592 | 0 | my $cmd; | |||||||||||||||||||
| 593 | |||||||||||||||||||||
| 594 | 0 | ▶ | print_hook_header() if debug_mod1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 595 | |||||||||||||||||||||
| 596 | 0 | ▶ | if (-f project_root_dir()."/Gemfile" ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 597 | 0 | $cmd = "cd ".project_root_dir()." && bundle exec ruby -I $ruby_lib_dir -r outthentic -I ".story_cache_dir()." $file" | |||||||||||||||||||
| 598 | } else { | ||||||||||||||||||||
| 599 | 0 | $cmd = "ruby -I $ruby_lib_dir -r outthentic -I ".story_cache_dir()." $file" | |||||||||||||||||||
| 600 | } | ||||||||||||||||||||
| 601 | |||||||||||||||||||||
| 602 | 0 | ▶ | if (debug_mod12()){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 603 | 0 | main::note("do_ruby_hook: $cmd"); | |||||||||||||||||||
| 604 | } | ||||||||||||||||||||
| 605 | |||||||||||||||||||||
| 606 | |||||||||||||||||||||
| 607 | 0 | my $rand = int(rand(1000)); | |||||||||||||||||||
| 608 | |||||||||||||||||||||
| 609 | 0 | my $st = system("$cmd 2>".story_cache_dir()."/$rand.err 1>".story_cache_dir()."/$rand.out"); | |||||||||||||||||||
| 610 | |||||||||||||||||||||
| 611 | 0 | ▶ | if($st != 0){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 612 | 0 | die "do_ruby_hook failed. \n see ".story_cache_dir()."/$rand.err for details"; | |||||||||||||||||||
| 613 | } | ||||||||||||||||||||
| 614 | |||||||||||||||||||||
| 615 | 0 | my $out_file = story_cache_dir()."/$rand.out"; | |||||||||||||||||||
| 616 | |||||||||||||||||||||
| 617 | 0 | ▶ | open RUBY_HOOK_OUT, $out_file or die "can't open RUBY_HOOK_OUT file $out_file to read!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 618 | |||||||||||||||||||||
| 619 | 0 | my @out = <RUBY_HOOK_OUT>; | |||||||||||||||||||
| 620 | |||||||||||||||||||||
| 621 | 0 | close RUBY_HOOK_OUT; | |||||||||||||||||||
| 622 | |||||||||||||||||||||
| 623 | 0 | my $story_vars_json; | |||||||||||||||||||
| 624 | |||||||||||||||||||||
| 625 | 0 | for my $l (@out) { | |||||||||||||||||||
| 626 | |||||||||||||||||||||
| 627 | 0 | ▶ | next if $l=~/#/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 628 | |||||||||||||||||||||
| 629 | 0 | ▶ | quit($1) if $l=~/quit:(.*)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 630 | |||||||||||||||||||||
| 631 | 0 | ▶ | outthentic_die($1) if $l=~/outthentic_die:(.*)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 632 | |||||||||||||||||||||
| 633 | 0 | ▶ | ignore_story_err($1) if $l=~/ignore_story_err:\s+(\d)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 634 | |||||||||||||||||||||
| 635 | 0 | ▶ | if ($l=~s/story_var_json_begin.*// .. $l=~s/story_var_json_end.*//){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 636 | 0 | $story_vars_json.=$l; | |||||||||||||||||||
| 637 | 0 | next; | |||||||||||||||||||
| 638 | } | ||||||||||||||||||||
| 639 | |||||||||||||||||||||
| 640 | |||||||||||||||||||||
| 641 | 0 | ▶ | if ($l=~/story:\s+(\S+)/){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 642 | |||||||||||||||||||||
| 643 | 0 | my $path = $1; | |||||||||||||||||||
| 644 | |||||||||||||||||||||
| 645 | 0 | ▶ | if (debug_mod12()){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 646 | 0 | main::note("run downstream story from ruby hook"); | |||||||||||||||||||
| 647 | } | ||||||||||||||||||||
| 648 | |||||||||||||||||||||
| 649 | 0 | ▶ | run_story($path, decode_json($story_vars_json||{})); | ||||||||||||||||||
|
Condition0%0/2
$story_vars_json || {}
MC/DC0%0/1
$story_vars_json || {}
$story_vars_json
Truth table0%0/2
A
A= $story_vars_json
| |||||||||||||||||||||
| 650 | 0 | $story_vars_json = undef; | |||||||||||||||||||
| 651 | |||||||||||||||||||||
| 652 | } | ||||||||||||||||||||
| 653 | } | ||||||||||||||||||||
| 654 | |||||||||||||||||||||
| 655 | 0 | return 1; | |||||||||||||||||||
| 656 | } | ||||||||||||||||||||
| 657 | |||||||||||||||||||||
| 658 | 0 | ▶ | sub do_python_hook { | ||||||||||||||||||
|
Subroutine
do_python_hook: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||
| 659 | |||||||||||||||||||||
| 660 | 0 | my $file = shift; | |||||||||||||||||||
| 661 | |||||||||||||||||||||
| 662 | 0 | my $python_lib_dir = File::ShareDir::dist_dir('Outthentic'); | |||||||||||||||||||
| 663 | |||||||||||||||||||||
| 664 | 0 | my $cmd = "PYTHONPATH=\$PYTHONPATH:".(story_cache_dir()).":$python_lib_dir python $file"; | |||||||||||||||||||
| 665 | |||||||||||||||||||||
| 666 | 0 | ▶ | print_hook_header() if debug_mod1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 667 | |||||||||||||||||||||
| 668 | 0 | ▶ | if (debug_mod12()){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 669 | 0 | main::note("do_python_hook: $cmd"); | |||||||||||||||||||
| 670 | } | ||||||||||||||||||||
| 671 | |||||||||||||||||||||
| 672 | |||||||||||||||||||||
| 673 | 0 | my $rand = int(rand(1000)); | |||||||||||||||||||
| 674 | |||||||||||||||||||||
| 675 | 0 | my $st = system("$cmd 2>".story_cache_dir()."/$rand.err 1>".story_cache_dir()."/$rand.out"); | |||||||||||||||||||
| 676 | |||||||||||||||||||||
| 677 | 0 | ▶ | if($st != 0){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 678 | 0 | die "do_python_hook failed. \n see ".story_cache_dir()."/$rand.err for details"; | |||||||||||||||||||
| 679 | } | ||||||||||||||||||||
| 680 | |||||||||||||||||||||
| 681 | 0 | my $out_file = story_cache_dir()."/$rand.out"; | |||||||||||||||||||
| 682 | |||||||||||||||||||||
| 683 | 0 | ▶ | open PYTHON_HOOK_OUT, $out_file or die "can't open PYTHON_HOOK_OUT file $out_file to read!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 684 | |||||||||||||||||||||
| 685 | 0 | my @out = <PYTHON_HOOK_OUT>; | |||||||||||||||||||
| 686 | |||||||||||||||||||||
| 687 | 0 | close PYTHON_HOOK_OUT; | |||||||||||||||||||
| 688 | |||||||||||||||||||||
| 689 | 0 | my $story_vars_json; | |||||||||||||||||||
| 690 | |||||||||||||||||||||
| 691 | 0 | for my $l (@out) { | |||||||||||||||||||
| 692 | |||||||||||||||||||||
| 693 | 0 | ▶ | next if $l=~/#/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 694 | |||||||||||||||||||||
| 695 | 0 | ▶ | quit($1) if $l=~/quit:(.*)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 696 | |||||||||||||||||||||
| 697 | 0 | ▶ | outthentic_die($1) if $l=~/outthentic_die:(.*)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 698 | |||||||||||||||||||||
| 699 | 0 | ▶ | ignore_story_err($1) if $l=~/ignore_story_err:\s+(\d)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 700 | |||||||||||||||||||||
| 701 | 0 | ▶ | if ($l=~s/story_var_json_begin.*// .. $l=~s/story_var_json_end.*//){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 702 | 0 | $story_vars_json.=$l; | |||||||||||||||||||
| 703 | 0 | next; | |||||||||||||||||||
| 704 | } | ||||||||||||||||||||
| 705 | |||||||||||||||||||||
| 706 | |||||||||||||||||||||
| 707 | 0 | ▶ | if ($l=~/story:\s+(\S+)/){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 708 | |||||||||||||||||||||
| 709 | 0 | my $path = $1; | |||||||||||||||||||
| 710 | |||||||||||||||||||||
| 711 | 0 | ▶ | if (debug_mod12()){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 712 | 0 | main::note("run downstream story from python hook"); | |||||||||||||||||||
| 713 | } | ||||||||||||||||||||
| 714 | |||||||||||||||||||||
| 715 | 0 | ▶ | run_story($path, decode_json($story_vars_json||{})); | ||||||||||||||||||
|
Condition0%0/2
$story_vars_json || {}
MC/DC0%0/1
$story_vars_json || {}
$story_vars_json
Truth table0%0/2
A
A= $story_vars_json
| |||||||||||||||||||||
| 716 | |||||||||||||||||||||
| 717 | 0 | $story_vars_json = undef; | |||||||||||||||||||
| 718 | |||||||||||||||||||||
| 719 | } | ||||||||||||||||||||
| 720 | } | ||||||||||||||||||||
| 721 | |||||||||||||||||||||
| 722 | 0 | return 1; | |||||||||||||||||||
| 723 | } | ||||||||||||||||||||
| 724 | |||||||||||||||||||||
| 725 | 0 | ▶ | sub do_bash_hook { | ||||||||||||||||||
|
Subroutine
do_bash_hook: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||
| 726 | |||||||||||||||||||||
| 727 | 0 | my $file = shift; | |||||||||||||||||||
| 728 | |||||||||||||||||||||
| 729 | 0 | my $bash_lib_dir = File::ShareDir::dist_dir('Outthentic'); | |||||||||||||||||||
| 730 | |||||||||||||||||||||
| 731 | 0 | my $cmd = "source "._bash_glue_file()." && source $bash_lib_dir/outthentic.bash"; | |||||||||||||||||||
| 732 | |||||||||||||||||||||
| 733 | 0 | $cmd.=" && source $file"; | |||||||||||||||||||
| 734 | |||||||||||||||||||||
| 735 | 0 | $cmd="bash -c '$cmd'"; | |||||||||||||||||||
| 736 | |||||||||||||||||||||
| 737 | 0 | ▶ | print_hook_header() if debug_mod1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 738 | |||||||||||||||||||||
| 739 | 0 | ▶ | if (debug_mod12()){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 740 | 0 | main::note("do_bash_hook: $cmd"); | |||||||||||||||||||
| 741 | } | ||||||||||||||||||||
| 742 | |||||||||||||||||||||
| 743 | |||||||||||||||||||||
| 744 | 0 | my $rand = int(rand(1000)); | |||||||||||||||||||
| 745 | |||||||||||||||||||||
| 746 | 0 | my $st = system("$cmd 2>".story_cache_dir()."/$rand.err 1>".story_cache_dir()."/$rand.out"); | |||||||||||||||||||
| 747 | |||||||||||||||||||||
| 748 | 0 | ▶ | if($st != 0){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 749 | 0 | die "do_bash_hook failed. \n see ".story_cache_dir()."/$rand.err for details"; | |||||||||||||||||||
| 750 | } | ||||||||||||||||||||
| 751 | |||||||||||||||||||||
| 752 | 0 | my $out_file = story_cache_dir()."/$rand.out"; | |||||||||||||||||||
| 753 | |||||||||||||||||||||
| 754 | 0 | ▶ | open HOOK_OUT, $out_file or die "can't open HOOK_OUT file $out_file to read!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 755 | |||||||||||||||||||||
| 756 | 0 | my @out = <HOOK_OUT>; | |||||||||||||||||||
| 757 | |||||||||||||||||||||
| 758 | 0 | close HOOK_OUT; | |||||||||||||||||||
| 759 | |||||||||||||||||||||
| 760 | 0 | my %story_vars_bash = (); | |||||||||||||||||||
| 761 | |||||||||||||||||||||
| 762 | 0 | for my $l (@out) { | |||||||||||||||||||
| 763 | |||||||||||||||||||||
| 764 | 0 | ▶ | next if $l=~/#/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 765 | |||||||||||||||||||||
| 766 | 0 | ▶ | quit($1) if $l=~/quit:(.*)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 767 | |||||||||||||||||||||
| 768 | 0 | ▶ | outthentic_die($1) if $l=~/outthentic_die:(.*)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 769 | |||||||||||||||||||||
| 770 | 0 | ▶ | ignore_story_err($1) if $l=~/ignore_story_err:\s+(\d)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 771 | |||||||||||||||||||||
| 772 | 0 | ▶ | if ($l=~/story_var_bash:\s+(\S+)\s+(.*)/){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 773 | 0 | $story_vars_bash{$1}=$2; | |||||||||||||||||||
| 774 | #warn %story_vars_bash; | ||||||||||||||||||||
| 775 | 0 | next; | |||||||||||||||||||
| 776 | } | ||||||||||||||||||||
| 777 | |||||||||||||||||||||
| 778 | 0 | ▶ | if ($l=~/story:\s+(\S+)/){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 779 | 0 | my $path = $1; | |||||||||||||||||||
| 780 | 0 | ▶ | if (debug_mod12()){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 781 | 0 | main::note("run downstream story from bash hook"); | |||||||||||||||||||
| 782 | } | ||||||||||||||||||||
| 783 | 0 | run_story($path, {%story_vars_bash}); | |||||||||||||||||||
| 784 | 0 | %story_vars_bash = (); | |||||||||||||||||||
| 785 | } | ||||||||||||||||||||
| 786 | } | ||||||||||||||||||||
| 787 | |||||||||||||||||||||
| 788 | 0 | return 1; | |||||||||||||||||||
| 789 | |||||||||||||||||||||
| 790 | } | ||||||||||||||||||||
| 791 | |||||||||||||||||||||
| 792 | |||||||||||||||||||||
| 793 | 0 | ▶ | sub do_ps_hook { | ||||||||||||||||||
|
Subroutine
do_ps_hook: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||
| 794 | |||||||||||||||||||||
| 795 | 0 | my $file = shift; | |||||||||||||||||||
| 796 | |||||||||||||||||||||
| 797 | 0 | my $ps_lib_dir = File::ShareDir::dist_dir('Outthentic'); | |||||||||||||||||||
| 798 | |||||||||||||||||||||
| 799 | 0 | my $cmd; | |||||||||||||||||||
| 800 | |||||||||||||||||||||
| 801 | 0 | ▶ | print_hook_header() if debug_mod1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 802 | |||||||||||||||||||||
| 803 | 0 | ▶ | if ( $^O =~ 'MSWin' ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 804 | 0 | $cmd = "powershell.exe -NoProfile -c \". ".story_cache_dir()."/glue.ps1; . $ps_lib_dir/outthentic.ps1; . $file; \""; | |||||||||||||||||||
| 805 | } else { | ||||||||||||||||||||
| 806 | 0 | $cmd = "pwsh -c \". ".story_cache_dir()."/glue.ps1; . $ps_lib_dir/outthentic.ps1; . $file; \""; | |||||||||||||||||||
| 807 | } | ||||||||||||||||||||
| 808 | |||||||||||||||||||||
| 809 | 0 | ▶ | if (debug_mod12()){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 810 | 0 | main::note("do_ps_hook: $cmd"); | |||||||||||||||||||
| 811 | } | ||||||||||||||||||||
| 812 | |||||||||||||||||||||
| 813 | |||||||||||||||||||||
| 814 | 0 | my $rand = int(rand(1000)); | |||||||||||||||||||
| 815 | |||||||||||||||||||||
| 816 | 0 | my $st = system("$cmd 2>".story_cache_dir()."/$rand.err 1>".story_cache_dir()."/$rand.out"); | |||||||||||||||||||
| 817 | |||||||||||||||||||||
| 818 | 0 | ▶ | if($st != 0){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 819 | 0 | die "do_ps_hook failed. \n see ".story_cache_dir()."/$rand.err for details"; | |||||||||||||||||||
| 820 | } | ||||||||||||||||||||
| 821 | |||||||||||||||||||||
| 822 | 0 | my $out_file = story_cache_dir()."/$rand.out"; | |||||||||||||||||||
| 823 | |||||||||||||||||||||
| 824 | 0 | ▶ | open HOOK_OUT, $out_file or die "can't open HOOK_OUT file $out_file to read!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 825 | |||||||||||||||||||||
| 826 | 0 | my @out = <HOOK_OUT>; | |||||||||||||||||||
| 827 | |||||||||||||||||||||
| 828 | 0 | close HOOK_OUT; | |||||||||||||||||||
| 829 | |||||||||||||||||||||
| 830 | 0 | my $story_vars_json; | |||||||||||||||||||
| 831 | |||||||||||||||||||||
| 832 | 0 | for my $l (@out) { | |||||||||||||||||||
| 833 | |||||||||||||||||||||
| 834 | 0 | ▶ | next if $l=~/#/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 835 | |||||||||||||||||||||
| 836 | 0 | ▶ | quit($1) if $l=~/quit:(.*)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 837 | |||||||||||||||||||||
| 838 | 0 | ▶ | outthentic_die($1) if $l=~/outthentic_die:(.*)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 839 | |||||||||||||||||||||
| 840 | 0 | ▶ | ignore_story_err($1) if $l=~/ignore_story_err:\s+(\d)/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 841 | |||||||||||||||||||||
| 842 | 0 | ▶ | if ($l=~s/story_var_json_begin.*// .. $l=~s/story_var_json_end.*//){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 843 | 0 | $story_vars_json.=$l; | |||||||||||||||||||
| 844 | 0 | next; | |||||||||||||||||||
| 845 | } | ||||||||||||||||||||
| 846 | |||||||||||||||||||||
| 847 | 0 | ▶ | if ($l=~/story:\s+(\S+)/){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 848 | |||||||||||||||||||||
| 849 | 0 | my $path = $1; | |||||||||||||||||||
| 850 | |||||||||||||||||||||
| 851 | 0 | ▶ | if (debug_mod12()){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 852 | 0 | main::note("run downstream story from powershell hook"); | |||||||||||||||||||
| 853 | } | ||||||||||||||||||||
| 854 | |||||||||||||||||||||
| 855 | 0 | ▶ | run_story($path, decode_json($story_vars_json||{})); | ||||||||||||||||||
|
Condition0%0/2
$story_vars_json || {}
MC/DC0%0/1
$story_vars_json || {}
$story_vars_json
Truth table0%0/2
A
A= $story_vars_json
| |||||||||||||||||||||
| 856 | |||||||||||||||||||||
| 857 | 0 | $story_vars_json = undef; | |||||||||||||||||||
| 858 | |||||||||||||||||||||
| 859 | } | ||||||||||||||||||||
| 860 | |||||||||||||||||||||
| 861 | } | ||||||||||||||||||||
| 862 | |||||||||||||||||||||
| 863 | 0 | return 1; | |||||||||||||||||||
| 864 | |||||||||||||||||||||
| 865 | } | ||||||||||||||||||||
| 866 | |||||||||||||||||||||
| 867 | |||||||||||||||||||||
| 868 | 0 | ▶ | sub apply_story_vars { | ||||||||||||||||||
|
Subroutine
apply_story_vars: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 869 | |||||||||||||||||||||
| 870 | 0 | my $story_vars = Outthentic::Story::Stat->current->{vars}; | |||||||||||||||||||
| 871 | |||||||||||||||||||||
| 872 | 0 | set_prop( story_vars => $story_vars ); | |||||||||||||||||||
| 873 | |||||||||||||||||||||
| 874 | 0 | ▶ | open STORY_VARS, ">", (story_cache_dir())."/variables.json" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 875 | or die "can't open ".(story_cache_dir())."/variables.json write: $!"; | ||||||||||||||||||||
| 876 | |||||||||||||||||||||
| 877 | 0 | print STORY_VARS encode_json($story_vars); | |||||||||||||||||||
| 878 | |||||||||||||||||||||
| 879 | 0 | close STORY_VARS; | |||||||||||||||||||
| 880 | |||||||||||||||||||||
| 881 | 0 | ▶ | open STORY_VARS, ">", (story_cache_dir())."/variables.bash" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 882 | or die "can't open ".(story_cache_dir())."/variables.bash write: $!"; | ||||||||||||||||||||
| 883 | |||||||||||||||||||||
| 884 | 0 | for my $name (keys %{$story_vars} ){ | |||||||||||||||||||
| 885 | 0 | print STORY_VARS "$name=".$story_vars->{$name}."\n"; | |||||||||||||||||||
| 886 | } | ||||||||||||||||||||
| 887 | |||||||||||||||||||||
| 888 | 0 | close STORY_VARS; | |||||||||||||||||||
| 889 | |||||||||||||||||||||
| 890 | } | ||||||||||||||||||||
| 891 | |||||||||||||||||||||
| 892 | 0 | ▶ | sub story_var { | ||||||||||||||||||
|
Subroutine
story_var: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 893 | |||||||||||||||||||||
| 894 | 0 | my $name = shift; | |||||||||||||||||||
| 895 | |||||||||||||||||||||
| 896 | 0 | get_prop( 'story_vars' )->{$name}; | |||||||||||||||||||
| 897 | |||||||||||||||||||||
| 898 | } | ||||||||||||||||||||
| 899 | |||||||||||||||||||||
| 900 | 0 | ▶ | sub story_vars_pretty { | ||||||||||||||||||
|
Subroutine
story_vars_pretty: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 901 | |||||||||||||||||||||
| 902 | 0 | join " ", map { "$_:".(story_var($_)) } sort keys %{get_prop( 'story_vars' ) }; | |||||||||||||||||||
| 903 | |||||||||||||||||||||
| 904 | } | ||||||||||||||||||||
| 905 | |||||||||||||||||||||
| 906 | 0 | ▶ | sub print_hook_header { | ||||||||||||||||||
|
Subroutine
print_hook_header: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||
| 907 | |||||||||||||||||||||
| 908 | 0 | my $task_name = get_prop('task_name'); | |||||||||||||||||||
| 909 | |||||||||||||||||||||
| 910 | 0 | my $format = get_prop('format'); | |||||||||||||||||||
| 911 | |||||||||||||||||||||
| 912 | 0 | my $data; | |||||||||||||||||||
| 913 | |||||||||||||||||||||
| 914 | 0 | ▶ | if ($format eq 'production') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 915 | 0 | ▶ | $data = timestamp().' : '.($task_name || '').' '.'[hook]' | ||||||||||||||||||
|
Condition0%0/2
$task_name || ''
MC/DC0%0/1
$task_name || ''
$task_name
Truth table0%0/2
A
A= $task_name
| |||||||||||||||||||||
| 916 | } elsif ($format ne 'concise') { | ||||||||||||||||||||
| 917 | 0 | ▶ | $data = timestamp().' : '.($task_name || '' ).' '.(nocolor() ? ' hook' : colored(['yellow'],'[hook]')) | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$task_name || ''
MC/DC0%0/1
$task_name || ''
$task_name
Truth table0%0/2
A
A= $task_name
| |||||||||||||||||||||
| 918 | } | ||||||||||||||||||||
| 919 | |||||||||||||||||||||
| 920 | 0 | ▶ | note($data) if $format ne 'concise'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 921 | } | ||||||||||||||||||||
| 922 | |||||||||||||||||||||
| 923 | 0 | ▶ | sub note { | ||||||||||||||||||
|
Subroutine
note: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 924 | |||||||||||||||||||||
| 925 | 0 | my $message = shift; | |||||||||||||||||||
| 926 | 0 | my $no_new_line = shift; | |||||||||||||||||||
| 927 | |||||||||||||||||||||
| 928 | 0 | binmode(STDOUT, ":utf8"); | |||||||||||||||||||
| 929 | 0 | print $message; | |||||||||||||||||||
| 930 | 0 | ▶ | print "\n" unless $no_new_line; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 931 | |||||||||||||||||||||
| 932 | } | ||||||||||||||||||||
| 933 | |||||||||||||||||||||
| 934 | 0 | ▶ | sub nocolor { | ||||||||||||||||||
|
Subroutine
nocolor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 935 | 0 | get_prop('nocolor') | |||||||||||||||||||
| 936 | } | ||||||||||||||||||||
| 937 | |||||||||||||||||||||
| 938 | 0 | ▶ | sub timestamp { | ||||||||||||||||||
|
Subroutine
timestamp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 939 | |||||||||||||||||||||
| 940 | 0 | sprintf '%02d-%02d-%02d %02d:%02d:%02d', | |||||||||||||||||||
| 941 | localtime->year()+1900, | ||||||||||||||||||||
| 942 | localtime->mon()+1, localtime->mday, | ||||||||||||||||||||
| 943 | localtime->hour, localtime->min, localtime->sec; | ||||||||||||||||||||
| 944 | |||||||||||||||||||||
| 945 | } | ||||||||||||||||||||
| 946 | |||||||||||||||||||||
| 947 | 0 | ▶ | sub dump_os { | ||||||||||||||||||
|
Subroutine
dump_os: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 948 | |||||||||||||||||||||
| 949 | 0 | ▶ | return $^O if $^O =~ 'MSWin'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 950 | |||||||||||||||||||||
| 951 | 0 | my $cmd = <<'HERE'; | |||||||||||||||||||
| 952 | #! /usr/bin/env sh | ||||||||||||||||||||
| 953 | |||||||||||||||||||||
| 954 | # Find out the target OS | ||||||||||||||||||||
| 955 | if [ -s /etc/os-release ]; then | ||||||||||||||||||||
| 956 | # freedesktop.org and systemd | ||||||||||||||||||||
| 957 | . /etc/os-release | ||||||||||||||||||||
| 958 | OS=$NAME | ||||||||||||||||||||
| 959 | VER=$VERSION_ID | ||||||||||||||||||||
| 960 | elif lsb_release -h >/dev/null 2>&1; then | ||||||||||||||||||||
| 961 | # linuxbase.org | ||||||||||||||||||||
| 962 | OS=$(lsb_release -si) | ||||||||||||||||||||
| 963 | VER=$(lsb_release -sr) | ||||||||||||||||||||
| 964 | elif [ -s /etc/lsb-release ]; then | ||||||||||||||||||||
| 965 | # For some versions of Debian/Ubuntu without lsb_release command | ||||||||||||||||||||
| 966 | . /etc/lsb-release | ||||||||||||||||||||
| 967 | OS=$DISTRIB_ID | ||||||||||||||||||||
| 968 | VER=$DISTRIB_RELEASE | ||||||||||||||||||||
| 969 | elif [ -s /etc/debian_version ]; then | ||||||||||||||||||||
| 970 | # Older Debian/Ubuntu/etc. | ||||||||||||||||||||
| 971 | OS=Debian | ||||||||||||||||||||
| 972 | VER=$(cat /etc/debian_version) | ||||||||||||||||||||
| 973 | elif [ -s /etc/SuSe-release ]; then | ||||||||||||||||||||
| 974 | # Older SuSE/etc. | ||||||||||||||||||||
| 975 | printf "TODO\n" | ||||||||||||||||||||
| 976 | elif [ -s /etc/redhat-release ]; then | ||||||||||||||||||||
| 977 | # Older Red Hat, CentOS, etc. | ||||||||||||||||||||
| 978 | OS=$(cat /etc/redhat-release| head -n 1) | ||||||||||||||||||||
| 979 | else | ||||||||||||||||||||
| 980 | RELEASE_INFO=$(cat /etc/*-release 2>/dev/null | head -n 1) | ||||||||||||||||||||
| 981 | |||||||||||||||||||||
| 982 | if [ ! -z "$RELEASE_INFO" ]; then | ||||||||||||||||||||
| 983 | OS=$(printf -- "$RELEASE_INFO" | awk '{ print $1 }') | ||||||||||||||||||||
| 984 | VER=$(printf -- "$RELEASE_INFO" | awk '{ print $NF }') | ||||||||||||||||||||
| 985 | else | ||||||||||||||||||||
| 986 | # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc. | ||||||||||||||||||||
| 987 | OS=$(uname -s) | ||||||||||||||||||||
| 988 | VER=$(uname -r) | ||||||||||||||||||||
| 989 | fi | ||||||||||||||||||||
| 990 | fi | ||||||||||||||||||||
| 991 | |||||||||||||||||||||
| 992 | echo "$OS$VER" | ||||||||||||||||||||
| 993 | |||||||||||||||||||||
| 994 | HERE | ||||||||||||||||||||
| 995 | |||||||||||||||||||||
| 996 | 0 | `$cmd` | |||||||||||||||||||
| 997 | |||||||||||||||||||||
| 998 | } | ||||||||||||||||||||
| 999 | |||||||||||||||||||||
| 1000 | 0 | ▶ | sub _resolve_os { | ||||||||||||||||||
|
Subroutine
_resolve_os: not called CC=26 SCAR=65.5
| |||||||||||||||||||||
| 1001 | |||||||||||||||||||||
| 1002 | |||||||||||||||||||||
| 1003 | 0 | ▶ | if (!$OS){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1004 | |||||||||||||||||||||
| 1005 | 0 | DONE: while (1) { | |||||||||||||||||||
| 1006 | 0 | my $data = dump_os(); | |||||||||||||||||||
| 1007 | 0 | ▶ | $data=~/alpine/i and $OS = 'alpine' and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /alpine/i and $Outthentic::Story::OS = "alpine"
MC/DC0%0/1
$data =~ /alpine/i and $Outthentic::Story::OS = "alpine"
$data =~ /alpine/i
Truth table0%0/2
A
A= $data =~ /alpine/i
| |||||||||||||||||||||
| 1008 | 0 | ▶ | $data=~/minoca/i and $OS = "minoca" and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /minoca/i and $Outthentic::Story::OS = "minoca"
MC/DC0%0/1
$data =~ /minoca/i and $Outthentic::Story::OS = "minoca"
$data =~ /minoca/i
Truth table0%0/2
A
A= $data =~ /minoca/i
| |||||||||||||||||||||
| 1009 | 0 | ▶ | $data=~/centos linux(\d+)/i and $OS = "centos$1" and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /centos linux(\d+)/i and $Outthentic::Story::OS = "centos$1"
MC/DC0%0/1
$data =~ /centos linux(\d+)/i and $Outthentic::Story::OS = "centos$1"
$data =~ /centos linux(\d+)/i
Truth table0%0/2
A
A= $data =~ /centos linux(\d+)/i
| |||||||||||||||||||||
| 1010 | 0 | ▶ | $data=~/Red Hat.*release\s+(\d)/i and $OS = "centos$1" and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /Red Hat.*release\s+(\d)/i and $Outthentic::Story::OS = "centos$1"
MC/DC0%0/1
$data =~ /Red Hat.*release\s+(\d)/i and $Outthentic::Story::OS = "centos$1"
$data =~ /Red Hat.*release\s+(\d)/i
Truth table0%0/2
A
A= $data =~ /Red Hat.*release\s+(\d)/i
| |||||||||||||||||||||
| 1011 | 0 | ▶ | $data=~/arch/i and $OS = 'archlinux' and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /arch/i and $Outthentic::Story::OS = "archlinux"
MC/DC0%0/1
$data =~ /arch/i and $Outthentic::Story::OS = "archlinux"
$data =~ /arch/i
Truth table0%0/2
A
A= $data =~ /arch/i
| |||||||||||||||||||||
| 1012 | 0 | ▶ | $data=~/funtoo/i and $OS = 'funtoo' and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /funtoo/i and $Outthentic::Story::OS = "funtoo"
MC/DC0%0/1
$data =~ /funtoo/i and $Outthentic::Story::OS = "funtoo"
$data =~ /funtoo/i
Truth table0%0/2
A
A= $data =~ /funtoo/i
| |||||||||||||||||||||
| 1013 | 0 | ▶ | $data=~/fedora/i and $OS = 'fedora' and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /fedora/i and $Outthentic::Story::OS = "fedora"
MC/DC0%0/1
$data =~ /fedora/i and $Outthentic::Story::OS = "fedora"
$data =~ /fedora/i
Truth table0%0/2
A
A= $data =~ /fedora/i
| |||||||||||||||||||||
| 1014 | 0 | ▶ | $data=~/amazon/i and $OS = 'amazon' and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /amazon/i and $Outthentic::Story::OS = "amazon"
MC/DC0%0/1
$data =~ /amazon/i and $Outthentic::Story::OS = "amazon"
$data =~ /amazon/i
Truth table0%0/2
A
A= $data =~ /amazon/i
| |||||||||||||||||||||
| 1015 | 0 | ▶ | $data=~/ubuntu/i and $OS = 'ubuntu' and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /ubuntu/i and $Outthentic::Story::OS = "ubuntu"
MC/DC0%0/1
$data =~ /ubuntu/i and $Outthentic::Story::OS = "ubuntu"
$data =~ /ubuntu/i
Truth table0%0/2
A
A= $data =~ /ubuntu/i
| |||||||||||||||||||||
| 1016 | 0 | ▶ | $data=~/debian/i and $OS = 'debian' and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /debian/i and $Outthentic::Story::OS = "debian"
MC/DC0%0/1
$data =~ /debian/i and $Outthentic::Story::OS = "debian"
$data =~ /debian/i
Truth table0%0/2
A
A= $data =~ /debian/i
| |||||||||||||||||||||
| 1017 | 0 | ▶ | $data=~/darwin/i and $OS = 'darwin' and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /darwin/i and $Outthentic::Story::OS = "darwin"
MC/DC0%0/1
$data =~ /darwin/i and $Outthentic::Story::OS = "darwin"
$data =~ /darwin/i
Truth table0%0/2
A
A= $data =~ /darwin/i
| |||||||||||||||||||||
| 1018 | 0 | ▶ | $data=~/MSWin/i and $OS = 'windows' and last DONE; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$data =~ /MSWin/i and $Outthentic::Story::OS = "windows"
MC/DC0%0/1
$data =~ /MSWin/i and $Outthentic::Story::OS = "windows"
$data =~ /MSWin/i
Truth table0%0/2
A
A= $data =~ /MSWin/i
| |||||||||||||||||||||
| 1019 | 0 | warn "unknown os: $data"; | |||||||||||||||||||
| 1020 | 0 | last DONE; | |||||||||||||||||||
| 1021 | } | ||||||||||||||||||||
| 1022 | } | ||||||||||||||||||||
| 1023 | 0 | return $OS; | |||||||||||||||||||
| 1024 | } | ||||||||||||||||||||
| 1025 | |||||||||||||||||||||
| 1026 | package main; | ||||||||||||||||||||
| 1027 | |||||||||||||||||||||
| 1028 | 0 | ▶ | sub os { Outthentic::Story::_resolve_os } | ||||||||||||||||||
|
Subroutine
os: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 1029 | |||||||||||||||||||||
| 1030 | |||||||||||||||||||||
| 1031 | |||||||||||||||||||||
| 1032 | 1 | 1; | |||||||||||||||||||
| 1033 | |||||||||||||||||||||
| 1034 | __END__ | ||||||||||||||||||||