-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscaler_stub.pl
More file actions
executable file
·71 lines (55 loc) · 2.24 KB
/
scaler_stub.pl
File metadata and controls
executable file
·71 lines (55 loc) · 2.24 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl
use strict;
use warnings;
#----------------------------------------------------------------------
# imports
#----------------------------------------------------------------------
use CGI;
use Getopt::Long;
use XML::SemanticDiff;
use Data::Dumper;
use File::Spec::Functions qw(catfile);
use File::Slurp;
use HelperMethods;
use Getopt::Long;
use Log::Log4perl qw(:easy);
#----------------------------------------------------------------------
# constants
#----------------------------------------------------------------------
use constant USAGE => <<HEREDOC;
Usage: $0 < tree.nexml
HEREDOC
use constant IS_CGI => exists $ENV{'GATEWAY_INTERFACE'};
use constant MOCK_INPUT_TREE_FILE => catfile('mock-data', 'pruner-output.nexml');
use constant MOCK_OUTPUT_TREE_FILE => catfile('mock-data', 'scaler-output.nexml');
#----------------------------------------------------------------------
# logging
#----------------------------------------------------------------------
# For debugging when owner of this script does not have read access to apache log.
#close STDERR or HelperMethods::fatal($!, IS_CGI, 500);
#open STDERR, '>>/home/ben/temp/cgi.log' or HelperMethods::fatal($!, IS_CGI, 500);
Log::Log4perl::easy_init(IS_CGI ? $WARN : $INFO);
#----------------------------------------------------------------------
# argument processing
#----------------------------------------------------------------------
my $help_opt = 0;
unless (IS_CGI) {
my $getopt_success = GetOptions('help' => \$help_opt);
die USAGE unless $getopt_success;
die USAGE if $help_opt;
}
my $query = join('',<STDIN>);
my $cgi = CGI->new();
#----------------------------------------------------------------------
# main
#----------------------------------------------------------------------
my $mock_input_tree = read_file(MOCK_INPUT_TREE_FILE);
my $mock_output_tree = read_file(MOCK_OUTPUT_TREE_FILE);
my $diff = XML::SemanticDiff->new();
if ($diff->compare($query, $mock_input_tree)) {
HelperMethods::fatal(
sprintf("%s\nError: This service only supports a mock input equivalent to the NeXML tree shown above.", $mock_input_tree),
IS_CGI, 400);
}
print $cgi->header(-status => 200, -type => 'application/xml') if IS_CGI;
print $mock_output_tree;