Skip to content

Instantly share code, notes, and snippets.

@jberger
Last active December 18, 2015 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/5701774 to your computer and use it in GitHub Desktop.
Save jberger/5701774 to your computer and use it in GitHub Desktop.
very simple mojolicious based pastie
#!/usr/bin/env perl
use Mojolicious::Lite;
use DBM::Deep;
helper db => sub { state $db = DBM::Deep->new('paste.db') };
helper add => sub { push(@{ shift->db->{items} }, shift) - 1 };
helper item => sub { shift->db->{items}[shift] };
any '/' => sub {
my $self = shift;
return $self->render('post')
unless my $code = $self->param('code');
$self->redirect_to( show => num => $self->add( $code ) );
};
any '/:num' => 'show';
app->defaults( layout => 'basic' )->start;
__DATA__
@@ layouts/basic.html.ep
<!DOCTYPE html>
<html>
<head>
<title>MojoPaste <%= stash('num') // 'Post' %></title>
</head>
<body>
%= content
</body>
</html>
@@ post.html.ep
%= form_for '/' => method => POST => begin
%= text_area 'code'
%= submit_button
% end
@@ show.html.ep
<pre class="prettyprint"><%= item $num %></pre>
%= javascript 'https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment