Web::Paste::Simple - simple PSGI-based pastebin-like website
#!/usr/bin/plackup use Web::Paste::Simple; Web::Paste::Simple->new( storage => Path::Class::Dir->new(...), codemirror => "...", template => Text::Template->new(...), )->app;
Web::Paste::Simple is a lightweight PSGI app for operating a pastebin-like website. It provides syntax highlighting via the CodeMirror Javascript library. It should be fast enough for deployment via CGI.
It does not provide any authentication facilities or similar, instead relying on you to use subclassing/roles or Plack middleware to accomplish such things.
new(%attrs)
Standard Moose-style constructor.
This class is not based on Moose though; instead it uses Moo.
The following attributes are defined:
storage
A Path::Class::Dir indicating the directory where pastes should be stored. Pastes are kept indefinitely. Each is a single file.
codemirror
Path to the CodeMirror syntax highlighter as a string. For example, if CodeMirror is available at http://example.com/js/lib/codemirror.js then this string should be http://example.com/js with no trailing slash.
http://example.com/js/lib/codemirror.js
http://example.com/js
This defaults to an address on my server, but for production sites, please set up your own copy: it only takes a couple of minutes; just a matter of unzipping a single archive. I offer no guarantees about the continued availability of my copy of CodeMirror.
Nothing is actually done with this variable, but it's passed to the template.
template
A Text::Template template which will be used for all HTML output. The following variables are available to the template...
$DATA - the text pasted on the curent page (if any), already HTML escaped
$DATA
$MODE - the currently selected syntax highlighting mode (if any), already HTML escaped
$MODE
@MODES - all configured highlighting modes
@MODES
$CODEMIRROR - the path to codemirror
$CODEMIRROR
$APP - the blessed Web::Paste::Simple object
$APP
$REQUEST - a blessed Plack::Request for the current request
$REQUEST
$PACKAGE - the string "Web::Paste::Simple"
$PACKAGE
$VERSION - the Web::Paste::Simple version number
$VERSION
The default template is minimal, but works.
modes
The list of CodeMirror highlighting modes to offer to the user.
default_mode
The default highlighting mode.
uuid_gen
A Data::UUID object used to generate URIs. The default should be fine.
The following methods may be of interest to people subclassing Web::Paste::Simple.
app
Technically this is another attribute, but one that should not be set in the constructor. Call this method to retrieve the PSGI coderef.
This coderef is built by _build_app (a Moo lazy builder).
_build_app
dispatch
Basic request router/dispatcher. Given a Plack::Request, returns a Plack::Response.
create_paste
Given a Plack::Request corresponding to an HTTP POST request, saves the paste and returns a Plack::Reponse. The response may be an arror message, success message, or (as per the current implementation) a redirect to the paste's URI.
POST
retrieve_paste
Given a Plack::Request and a paste ID, returns a Plack::Response with a representation of the paste, or an error message.
show_error
Given an error string and optionally an HTTP status code, returns a Plack::Response.
show_template
Given a Plack::Request and a hashref of data (possibly including paste and mode keys) returns a Plack::Response with the rendered template, and the pasted data plugged into it.
paste
mode
make_paste_id
Returns a unique ID string for a paste. The current implementation is a base64-encoded UUID.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Web-Paste-Simple.
Plack, Moo, CodeMirror.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2012 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install Web::Paste::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Web::Paste::Simple
CPAN shell
perl -MCPAN -e shell install Web::Paste::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.