The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

SYNOPSIS

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

  # Mojolicious::Lite
  plugin 'PPI';

DESCRIPTION

Mojolicious::Plugin::PPI is a Mojolicious plugin.

METHODS

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

register

  $plugin->register;

Register plugin in Mojolicious application. A register time, several options may be supplied:

  • toggle_button => [0/1] specifies whether a "Toggle Line Numbers" button (see below) will be created by default. Default is false.

  • 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). Remeber, if this option is not specified, a full or relative path may be passed to ppi.

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:

  • line_numbers => [0/1] specifies if line numbers should be generated

In the case of a file, the contents are placed in a <div> tag, and there are several additional options

  • id => 'string' specifies the id to be given to the encompassing <div> tag

  • toggle_button => [0/1] specifies if a button should be created to toggle the line numbers. If given line_numbers will be forced and if not specified an id will be generated. The onClick handler is toggleLineNumbers from the ppi_js javascript library. toggle_button may also be specified at register time to set the default.

ppi_js

Returns a Javascript snippet useful when using Mojolicious::Plugin::PPI.

ppi_css

Returns a CSS snippet for coloring the PPI::HTML generated HTML. Also provides a background for the code blocks.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.

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 by Joel Berger

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