summaryrefslogtreecommitdiff
path: root/server/src/perl/perlimportsWrapper.pl
blob: 7f34f5a0e3abd5cc741259f41ec0535f1ff58416 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!perl

use strict;
use warnings;

use Try::Tiny qw( catch try );

sub clear_stdin_and_exit {
    # Unclear if this is needed, but I've had issues on some versions of MacOS where STDIN needs to be cleared to function properly
    my $sSource = do { local $/; <STDIN> };
    exit(1);
}

if ( !eval { require App::perlimports::CLI; 1 } ) {
    print "\nUnable to run perlimports as it is not installed\n";
    clear_stdin_and_exit();
}

my $min = 0.000049;
if ( $App::perlimports::VERSION < $min ) {
    printf( "\nNeed at least version %f of perlimports\n", $min);
    clear_stdin_and_exit();
};

my @args = @ARGV;

push @args, '--read-stdin';

local @ARGV = @args;

my $exit_code = 0;
try {
    $exit_code = App::perlimports::CLI->new->run;
}
catch {
    print STDERR $_;
    $exit_code = 1;
};

exit($exit_code);