+ return $ssi;
+}
+
+sub compile
+{
+ my ($ssi, $input, $output) = @_;
+ my $input_fh;
+ my $input_abs;
+ my $output_fh;
+
+ if ($input eq $output and $input ne "-") {
+ warning("Input and output files are equal\n");
+ }
+
+ if ($input eq "-") {
+ $input_fh = *STDIN;
+ $input_abs = File::Spec->rel2abs(".");
+ } else {
+ if (not open($input_fh, "<", $input)) {
+ error(4, "%s: %s\n", $input, $!);
+ }
+ $input_abs = File::Spec->rel2abs($input);
+ }
+ if ($output eq "-") {
+ $output_fh = *STDOUT;
+ } else {
+ if (not open($output_fh, ">", $output . "~")) {
+ error(4, "%s: %s\n", $output . "~", $!);
+ }
+ }
+
+ # CGI::SSI uses SCRIPT_FILENAME to determine the value of LAST_MODIFIED.
+ $ENV{"DOCUMENT_NAME"} = $input;
+ $ENV{"DOCUMENT_URI"} = $input;
+ $ENV{"SCRIPT_FILENAME"} = $input_abs;
+
+ # Reset config tags to default values.
+ $ssi->config("errmsg",
+ "[an error occurred while processing this directive]");
+ $ssi->config("sizefmt", "abbrev");
+ $ssi->config("timefmt", undef);
+
+ $ssi->set("DOCUMENT_NAME" => $input);
+ $ssi->set("DOCUMENT_URI" => $input);
+