Last active
December 18, 2015 01:09
-
-
Save jberger/5701774 to your computer and use it in GitHub Desktop.
very simple mojolicious based pastie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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