The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mojolicious::Plugin::PPI - Mojolicious Plugin for Rendering Perl Code Using PPI

SYNOPSIS

 # Mojolicious
 $self->plugin('PPI');

 # Mojolicious::Lite
 plugin 'PPI';

 # In your template
 Perl is as simple as <%= ppi q{say "Hello World"} %>.

DESCRIPTION

Mojolicious::Plugin::PPI is a Mojolicious plugin which adds Perl syntax highlighting via PPI and PPI::HTML. Perl is notoriously hard to properly syntax highlight, but since PPI is made especially for parsing Perl this plugin can help you show off your Perl scripts in your Mojolicious webapp.

ATTRIBUTES

Mojolicious::Plugin::PPI inherits all methods from Mojolicious::Plugin and implements the following new ones.

  • line_numbers => [0/1] specifies if line numbers should be generated. Defaults to 1 for file-based snippets, however 0 is used for an inline snipppet unless explicitly overridden in the helper arguments.

  • no_check_file => [0/1] specifies if a file check should be performed. Default 0.

  • src_folder => 'directory' specifies a folder where input files will be found. When specified, if the directory is not found, a warning is issued, but not fatally. This functionality is not (currently) available for per-file alteration, so only use if all files will be in this folder (or subfolder). Remember, if this option is not specified, a full or relative path may be passed to "ppi".

  • style => '.ppi-code { some: style; }' a string of overall style sheet to be applied via the ppi_css helper.

  • class_style => { class => 'string color', other_class => { style => 'pairs' } } This hashref's keys are individual element style definitions. If the value is a string, it is used as the value of the color attribute. If the value is another hashref, it is converted into style definitions.

METHODS

Mojolicious::Plugin::PPI inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

  $plugin->register;

Register plugin in Mojolicious application. At register time, key-value pairs for the plugin attributes may be supplied.

HELPERS

Mojolicous::Plugin::PPI provides these helpers:

ppi

  %== ppi 'my $code = "highlighted";'
  %== ppi 'file.pl'

Returns HTML form of Perl snippet or file. The behavior may be slightly different in each case. If the argument is the name of a file that exists, it will be loaded and used. If not the string will be interpreted as an inline snippet. In either form, the call to ppi may take the additional option:

Additional key-value pairs may be passed which override the object's defaults. Most attributes are available (except: no_check_file for now) and the additional key inline lets you override the default choice of display inline vs block (by string vs file respectively).

ppi_css

Injects a generated CSS style into the page, using style properties defined in the plugin attributes.

SEE ALSO

Mojolicious, PPI, PPI::HTML

PPI, PPI::HTML

SOURCE REPOSITORY

http://github.com/jberger/Mojolicious-Plugin-PPI

AUTHOR

Joel Berger, <joel.a.berger@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2011-2013 by Joel Berger

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.