Apache-VimColor
view release on metacpan or search on metacpan
VimColor.pm view on Meta::CPAN
sub get_config ($)
{
my $req = shift;
my $options =
{
allow_dl => 0,
cssfile => '',
tabstop => 8
};
=item AllowDownload
Setting this option to B<true> will allow plaintext downloads of the files. A
link will be included in the output. The default is not to allow downloads.
=cut
if ($req->dir_config ('AllowDownload'))
{
my $conf = lc ($req->dir_config ('AllowDownload'));
if (($conf eq 'on') or ($conf eq 'true')
or ($conf eq 'yes'))
{
$options->{'allow_dl'} = 1;
}
}
=item CacheType
Selects the caching method to use. Depending on your choices a
L<Cache::Cache|Cache::Cache> module will be loaded and used. The default is not
to use any caching. I<CacheType> can be one of:
Memory
SharedMemory
File
Although the default is not to use caching, if I<CacheSize> is given and
I<CacheType> is not, then B<Memory> is being used. Obviously these values
correspond to the B<Cache::*Cache> modules.
The modules are loaded at runtime. If errors occur they are logged to Apache's
errorlog.
=item CacheSize
Sets the maximum size of the cache in bytes. If I<CacheSize> is non-zero the
B<Cache::SizeAware*Cache> variants will be used.
=item CacheExpire
I<CacheExpire> sets the expiration time. The value must be given in seconds.
Defaults to 3600 seconds (one hour). See L<Cache::Cache> for details.
=cut
if ($req->dir_config ('CacheType') or $req->dir_config ('CacheSize'))
{
my $cid = $req->server ()->server_hostname () . ':' . $req->location ();
my $cache;
if (defined ($Cache->{$cid}))
{
$cache = $Cache->{$cid};
}
else
{
my $type = 'File';
my $size = 0;
my $expr = 3600;
my $cmd;
if ($req->dir_config ('CacheType'))
{
my $tmp = lc ($req->dir_config ('CacheType'));
if ($tmp =~ m/((?:shared)?memory|file)/)
{
if ($1 eq 'sharedmemory') { $type = 'SharedMemory'; }
elsif ($1 eq 'memory') { $type = 'Memory'; }
}
else
{
$req->warn (qq(CacheType "$tmp" is not valid. Will use "File".));
}
}
if ($req->dir_config ('CacheSize'))
{
my $tmp = $req->dir_config ('CacheSize');
$tmp =~ s/\D//g;
$size = $tmp if ($tmp);
}
if ($req->dir_config ('CacheExpire'))
{
my $tmp = $req->dir_config ('CacheExpire');
$tmp =~ s/\D//g;
$expr = $tmp if ($tmp);
}
if ($size)
{
$type = "SizeAware$type";
}
$type .= 'Cache';
$cmd = "require Cache::$type; \$cache = Cache::$type->new ({ namespace => 'Apache::VimColor', default_expires_in => $expr";
if ($size)
{
$cmd .= ", max_size => $size";
}
$cmd .= ' });';
eval ($cmd);
if ($@)
{
$req->log ()->error (qq(Loading Cache::$type filed: $@"));
$cache = undef; # just to make sure ;)
}
$Cache->{$cid} = $cache if (defined ($cache));
}
$options->{'cache'} = $cache;
}
=item TabStop
Sets the width of one tab symbol. The default is eight spaces.
=cut
if ($req->dir_config ('TabStop'))
{
my $tmp = $req->dir_config ('TabStop');
$tmp =~ s/\D//g;
$options->{'tabstop'} = $tmp if ($tmp);
}
=item StyleSheet
If you want to include a custom stylesheet you can set this option. The string
will be included in the html-output as-is, you will have to take care of
relative filenames yourself.
All highlighted text is withing a C<span>-tag with one of the following
classes:
Comment
Constant
Error
Identifier
PreProc
Special
Statement
Todo
Type
Underlined
=cut
if ($req->dir_config ('StyleSheet'))
{
$options->{'cssfile'} = $req->dir_config ('StyleSheet');
}
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 = '';
( run in 1.008 second using v1.01-cache-2.11-cpan-39bf76dae61 )