Apache-VimColor

 view release on metacpan or  search on metacpan

VimColor.pm  view on Meta::CPAN

	}

	return ($options);
}

sub handler
{
	my $req = shift;
	my $filename = $req->filename ();
	my $filename_without_path = basename ($filename);
	my $options = get_config ($req);
	my $download = 0;
	my $mtime;
	my $vim;
	my $cache_entry;
	my $elems;
	my $output = '';

	if (!-e $filename or -z $filename)
	{
		return (NOT_FOUND);
	}

	if (!-r $filename)
	{
		return (FORBIDDEN);
	}

	$mtime = (stat ($filename))[9] or return (SERVER_ERROR);

	if ($req->args ())
	{
		my %args = $req->args ();

		if (exists ($args{'download'})
				and ($options->{'allow_dl'}))
		{
			$download = 1;
		}
	}

	# Set up header
	$req->content_type ($download ? 'text/perl-script' : 'text/html');
	$req->set_last_modified ($mtime);
	$req->set_etag ();

	if ($req->header_only ())
	{
		return (OK);
	}

	# User wished to download. This is already checked against the
	# `AllowDownload' option.
	if ($download)
	{
		return ($req->sendfile ($filename));
	}

	$req->print (<<HEADER);
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<title>$filename_without_path</title>
HEADER
	$req->print ($options->{'cssfile'} ? qq(\t\t<link rel="stylesheet" type="text/css" href=") . $options->{'cssfile'} . qq(" />\n) : <<HEADER);
		<style type="text/css">
		<!--
		a { color: inherit; background-color: transparent; }
		body { background-color: black; color: white; }
		div.fixed { border: 1px solid silver; font-family: monospace; padding: 1ex; }
		div.notice { color: silver; background-color: inherit; font-size: smaller; text-align: right; }
		h1 { font-size: medium; }
		span.linenumber { white-space: pre; color: yellow; background-color: transparent; }
		
		span.Comment { color: blue; background-color: transparent; }
		span.Constant { color: red; background-color: transparent; }
		span.Identifier { color: aqua; background-color: transparent; }
		span.Statement { color: yellow; background-color: transparent; }
		span.PreProc { color: fuchsia; background-color: transparent; }
		span.Type { color: lime; background-color: transparent; }
		span.Special { color: fuchsia; background-color: transparent; }
		span.Underlined { color: fuchsia; background-color: transparent; text-decoration: underline; }
		span.Error { background-color: red; color: white; font-weight: bold; }
		span.Todo { background-color: yellow; color: black; }
		-->
		</style>
HEADER
	$req->print (<<HEADER);
	</head>

	<body>
HEADER
	$req->print (qq(\t\t<h1>Source of <code>$filename_without_path</code>)
	. ($options->{'allow_dl'} ? ' (<a href="' . $req->uri () . '?download">download</a>)' : '') . "</h1>\n");

	$req->print (qq(\t\t<div class="fixed">\n));

	if (defined ($options->{'cache'}))
	{
		$cache_entry = $options->{'cache'}->get ($filename);

		if (defined ($cache_entry))
		{
			if ($cache_entry->[0] != $mtime)
			{
				$cache_entry->[0] = $mtime;
				$cache_entry->[1] = [];
			}

			$elems = $cache_entry->[1];
		}
		else
		{
			$cache_entry = [$mtime, []];
			$elems = $cache_entry->[1];
		}
	}
	else



( run in 0.707 second using v1.01-cache-2.11-cpan-8450f2e95f3 )