summaryrefslogtreecommitdiff
path: root/server/src/perl/tidyWrapper.pl
blob: b47a7e8f9122f24a25830f1dd728efa95b88711f (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
use strict;
use warnings;
use Getopt::Long qw( GetOptions );
use utf8;
use open qw(:std :utf8);

if ( !eval{ require Perl::Tidy; 1} ){
    print "\nUnable to run Perl::Tidy as it is not installed\n";
    exit(0);
}

my ($file, $profile);
GetOptions ("profile=s" => \$profile);

my $source = do { local $/; <STDIN> };
die("Did not pass any source via stdin") if !defined($source);
die("PerlTidy profile not readable") if ($profile and !-f $profile); # Profie may be undef

my ($destination, $stderr, $formatErrors, $argv);

my $error_flag = Perl::Tidy::perltidy(
    argv        => $argv,
    source      => \$source,
    destination => \$destination,
    stderr      => \$stderr,
    errorfile   => \$formatErrors, # Important to make sure the user's workspace is not polluted with .ERR files
    perltidyrc  => $profile,
);

# Will remove the UUID and any data beforehand in case we get any extra output anywhere. We really don't want to inject garbage (or logs) into people's source code
print "ee4ffa34-a14f-4609-b2e4-bf23565f3262${destination}ee4ffa34-a14f-4609-b2e4-bf23565f3262";