| 1 | package Inline::CLIPS; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use File::Temp qw(tempfile); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use IPC::Open3 qw(open3); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Symbol qw(gensym); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | sub new { | ||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 16 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||
| 17 | executable => $args{executable}, | ||||||||||||||||||||||||||||||||||||||
| 18 | library => $args{library}, | ||||||||||||||||||||||||||||||||||||||
| 19 | 3 | }, $class; | |||||||||||||||||||||||||||||||||||||
| 20 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | sub executable { | ||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
executable: called CC=5 SCAR=19.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | return $self->{executable} if defined $self->{executable}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||
| 27 | $self->{executable} = $ENV{INLINE_CLIPS_EXECUTABLE} | ||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | || _path_executable('clips') | ||||||||||||||||||||||||||||||||||||
|
Condition37%3/8
$ENV{'INLINE_CLIPS_EXECUTABLE'} || _path_executable('clips') || _alien_executable() || ''
$ENV{"INLINE_CLIPS_EXECUTABLE"} or _path_executable("clips") or _alien_executable()
$ENV{"INLINE_CLIPS_EXECUTABLE"} or _path_executable("clips")
MC/DC0%0/3
$ENV{'INLINE_CLIPS_EXECUTABLE'} || _path_executable('clips') || _alien_executable() || ''
$ENV{"INLINE_CLIPS_EXECUTABLE"}
_path_executable("clips")
_alien_executable()
Truth table25%1/4
A or B or C
A= $ENV{"INLINE_CLIPS_EXECUTABLE"}B= _path_executable("clips")C= _alien_executable()
| |||||||||||||||||||||||||||||||||||||||
| 29 | || _alien_executable() | ||||||||||||||||||||||||||||||||||||||
| 30 | || q{}; | ||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 1 | return $self->{executable}; | |||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | sub library { | ||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
library: called CC=4 SCAR=15.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | return $self->{library} if defined $self->{library}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||
| 39 | $self->{library} = $ENV{INLINE_CLIPS_LIB} | ||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | || _alien_library() | ||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$ENV{'INLINE_CLIPS_LIB'} || _alien_library() || ''
$ENV{"INLINE_CLIPS_LIB"} or _alien_library()
MC/DC0%0/2
$ENV{'INLINE_CLIPS_LIB'} || _alien_library() || ''
$ENV{"INLINE_CLIPS_LIB"}
_alien_library()
Truth table33%1/3
A or B
A= $ENV{"INLINE_CLIPS_LIB"}B= _alien_library()
| |||||||||||||||||||||||||||||||||||||||
| 41 | || q{}; | ||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||
| 43 | 1 | return $self->{library}; | |||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | sub run_program { | ||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my ($self, $program, @commands) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
run_program: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | croak 'program text is required' if !defined $program; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my ($fh, $tmp) = tempfile('inline-clips-XXXX', SUFFIX => '.clp', UNLINK => 1); | |||||||||||||||||||||||||||||||||||||
| 51 | 0 | print {$fh} "(clear)\n"; | |||||||||||||||||||||||||||||||||||||
| 52 | 0 | print {$fh} $program; | |||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | print {$fh} "\n" if $program !~ /\n\z/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 54 | 0 | print {$fh} "(reset)\n"; | |||||||||||||||||||||||||||||||||||||
| 55 | 0 | print {$fh} "$_\n" for @commands; | |||||||||||||||||||||||||||||||||||||
| 56 | 0 | print {$fh} "(exit)\n"; | |||||||||||||||||||||||||||||||||||||
| 57 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return $self->run_file($tmp); | |||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||
| 62 | sub run_file { | ||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | my ($self, $file) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
run_file: called CC=7 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | croak 'file path is required' if !defined $file || $file eq q{}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $file or $file eq ""
MC/DC0%0/2
not defined $file or $file eq ""
not defined $file
$file eq ""
Truth table33%1/3
not(A) or B
A= not defined $fileB= $file eq ""
| |||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | croak "CLIPS file not found: $file" if !-f $file; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $exe = $self->executable; | |||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | croak 'CLIPS executable is not available; set INLINE_CLIPS_EXECUTABLE or install CLIPS/Alien::CLIPS' | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 69 | if !$exe; | ||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $err = gensym; | |||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $pid = open3(my $in, my $out, $err, $exe, '-f2', $file); | |||||||||||||||||||||||||||||||||||||
| 73 | 0 | close $in; | |||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||
| 75 | 0 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | my $stdout = <$out> // q{}; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
readline $out // ""
MC/DC0%0/1
readline $out // ""
readline $out
Truth table0%0/2
A
A= readline $out
| |||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $stderr = <$err> // q{}; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
readline $err // ""
MC/DC0%0/1
readline $err // ""
readline $err
Truth table0%0/2
A
A= readline $err
| |||||||||||||||||||||||||||||||||||||||
| 78 | 0 | waitpid($pid, 0); | |||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $status = $? >> 8; | |||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||
| 81 | return { | ||||||||||||||||||||||||||||||||||||||
| 82 | 0 | status => $status, | |||||||||||||||||||||||||||||||||||||
| 83 | stdout => $stdout, | ||||||||||||||||||||||||||||||||||||||
| 84 | stderr => $stderr, | ||||||||||||||||||||||||||||||||||||||
| 85 | }; | ||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | sub _path_executable { | ||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my ($name) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_path_executable: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 90 | 0 | for my $dir (File::Spec->path) { | |||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $candidate = File::Spec->catfile($dir, $name); | |||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return $candidate if -x $candidate; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | sub _alien_executable { | ||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $alien = _load_alien() or return; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_alien_executable: not called CC=5 SCAR=34.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my @bins = $alien->can('bin_dir') ? $alien->bin_dir : (); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 100 | 0 | for my $dir (@bins) { | |||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $candidate = File::Spec->catfile($dir, 'clips'); | |||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return $candidate if -x $candidate; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||
| 104 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | sub _alien_library { | ||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | my $alien = _load_alien() or return; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_alien_library: called CC=4 SCAR=25.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | my @libs = $alien->can('dynamic_libs') ? $alien->dynamic_libs : (); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | return $libs[0] if @libs; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 111 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | sub _load_alien { | ||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | my $ok = eval { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_alien: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||||||||||||
| 116 | 1 | require Alien::CLIPS; | |||||||||||||||||||||||||||||||||||||
| 117 | 1 | Alien::CLIPS->import(); | |||||||||||||||||||||||||||||||||||||
| 118 | 0 | 1; | |||||||||||||||||||||||||||||||||||||
| 119 | }; | ||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | return if !$ok; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return 'Alien::CLIPS'; | |||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | 2 | 1; | |||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||||||||||||||||||||