Skip to content

Commit fd7e655

Browse files
committed
samepath: perl backend
perl backend add has_perl, perl_version
1 parent 8f26ec1 commit fd7e655

File tree

8 files changed

+65
-3
lines changed

8 files changed

+65
-3
lines changed

+stdlib/+perl/samepath.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function r = samepath(file1, file2)
2+
3+
cwd = fileparts(fullfile(mfilename('fullpath')));
4+
5+
[~, s] = perl([cwd filesep 'samepath.pl'], file1, file2);
6+
r = s == 0;
7+
8+
end

+stdlib/+perl/samepath.pl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env perl
2+
use strict;
3+
use warnings;
4+
5+
@ARGV == 2 or die "Usage: $0 <path1> <path2>\n";
6+
my $path1 = shift;
7+
my $path2 = shift;
8+
9+
my @st1 = stat($path1);
10+
@st1 ? () : die "stat($path1): $!\n";
11+
12+
my @st2 = stat($path2);
13+
@st2 ? () : die "stat($path2): $!\n";
14+
15+
if ($st1[1] != $st2[1] || $st1[0] != $st2[0]) { print "different\n"; exit 1; }

+stdlib/Backend.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
classdef Backend < matlab.mixin.SetGet
22

33
properties (Constant)
4-
optionalBackends = ["python", "dotnet", "java"]
4+
optionalBackends = ["perl", "python", "dotnet", "java"]
55
namespace = "stdlib"
66
end
77

+stdlib/has_perl.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
%% HAS_PERL checks if Perl is available in the current environment.
2+
3+
function y = has_perl()
4+
5+
y = ~isempty(stdlib.perl_version());
6+
7+
end

+stdlib/perl_version.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
%% PERL_VERSION get the Perl version used by MATLAB
2+
%
3+
%%% Output
4+
% * v: 1x3 vector of major, minor, micro version e.g. Perl 5.32.1 = [5, 32, 1]
5+
6+
function v = perl_version()
7+
8+
persistent perlv perlv_cached
9+
10+
if isempty(perlv_cached)
11+
perlv_cached = false;
12+
elseif perlv_cached
13+
v = perlv;
14+
return
15+
end
16+
17+
cwd = fileparts(fullfile(mfilename('fullpath')));
18+
19+
[r, s] = perl([cwd filesep 'version.pl']);
20+
21+
if s == 0
22+
v = sscanf(r, 'v%d.%d.%d');
23+
else
24+
v = [];
25+
end
26+
27+
% cache the result - even if empty -- because the check takes up to 1000 ms say on HPC
28+
perlv = v;
29+
perlv_cached = true;
30+
31+
end

+stdlib/samepath.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
arguments
2121
path1 string
2222
path2 string
23-
backend (1,:) string = ["python", "java", "sys", "native"]
23+
backend (1,:) string = ["python", "perl", "java", "sys", "native"]
2424
end
2525

2626
% For this function, Python is over 10x faster than Java

+stdlib/version.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print $^V;

private/publish_gen_index_html.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function publish_pkg(fid, pkg, pkg_name)
100100
fprintf(fid, newline + "<table>" + newline);
101101
fprintf(fid, "<tr><th>Function</th> <th>Description</th> <th>Backends</th></tr>" + newline);
102102

103-
Nbe = struct("dotnet", 0, "java", 0, "python", 0, "sys", 0, "native", 0, "legacy", 0, "top_level", 0);
103+
Nbe = struct(dotnet=0, java=0, perl=0, python=0, sys=0, native=0, legacy=0, top_level=0);
104104

105105
for fun = pkg.m.'
106106

0 commit comments

Comments
 (0)