Welcome, Guest :: Blog Home | Login | Register

Article
Template::Plugin::HighlightPerl

2008-04-16 21:09:57 Tags: perl template toolkit cpan

CPAN Link:

http://search.cpan.org/perldoc?Template::Plugin::HighlightPerl

I just uploaded my new module to CPAN. The module is a TT2 (Template Toolkit) filter which can be used for blog posts where Perl code is to be shown. It is a sort of wrapper for the Syntax::Highlight::Perl module and is used within the template file (.tt2) as a filter. I say "sort of" because it is really much more than that. It will "dynamically" highlight all perl code based on syntax and includes a css div classes for custom formatting. It also can be used to format non-perl code by using a different set of tags.

Here's a sample of the dynamically generated syntax highlighting.

Perl Code:
package Template::Plugin::HighlightPerl;

use Syntax::Highlight::Perl;
use Template::Plugin::Filter;
use base qw( Template::Plugin::Filter );
use strict;

our $VERSION = '0.01';

sub init {
    my $self = shift;
    my $name = $self->{ _CONFIG }->{ name } || 'highlight_perl';
    $self->install_filter($name);
    return $self;
}

Comments:

There are no comments.

Please login or register to post comment.