Skip to content

Instantly share code, notes, and snippets.

@djanatyn
Created August 12, 2011 06:52
Show Gist options
  • Save djanatyn/1141598 to your computer and use it in GitHub Desktop.
Save djanatyn/1141598 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>perlpaste</title>
<style>
body {
font-family:sans-serif; }
pre {
width:80em; }
#header {
width:100%;
background-color:#000;
color:#fff; }
#box {
border:1px solid black;
width:80em;
padding:5px;
background-color:#eee; }
</style>
</head>
<body>
<div id="header">
<h1>perlpaste - a pastebin in perl</h1>
</div>
<h1><% title %></h1>
<h3>paste id: #<% key %></h3>
<h3><a href="<% link %>"><% link %></a></h3>
<div id="box"><pre><% paste %></pre></div>
</body>
</html>
<html>
<head>
<title>perlpaste</title>
<style>
body {
font-family:sans-serif; }
p {
padding:10px; }
#header {
width:100%;
background-color:#000;
color:#fff; }
#wrapper {
width:100%; }
#input {
float:right;
width:80%; }
#sidebar {
float:left;
width:20%; }
</style>
</head>
<body>
<div id="header">
<h1>perlpaste - a pastebin in perl</h1>
</div>
<div id="wrapper">
<div id="input">
<form action="paste" method="post">
<table cellpadding=5>
<tr>
<td>title</td>
<td><input type="text" name="title" />&nbsp;<input type="submit" value="paste" /></td>
</tr>
<tr>
<td>text</td>
<td><textarea name="paste" cols="80" rows="24"></textarea></td>
</tr>
</table>
</div>
<div id="sidebar">
<p><b>perlpaste</b> is a no-nonsense pastebin, devoid of many features that you might expect to find in other pastebins. you might call this site lazy, but the author prefers the term "minimalistic".</p>
<p>you can paste things into the textbox, and you will be provided a link that you can distribute freely.</p>
</div>
</div>
</body>
</html>
#!/usr/bin/env perl
use Dancer;
use strict;
use DBI;
my $db = DBI->connect("dbi:SQLite:paste.db") || die "couldn't open";
get '/' => sub
{
template 'request.tt', {
'header' => 'perlpaste - a pastebin in perl',
'text' => 'the text',
};
};
post '/paste' => sub
{
my $title = param('title');
my $paste = param('paste');
$db->do("insert into pastes (title,paste) values ('$title','$paste')");
my $key = $db->selectall_arrayref("select pastekey from pastes where paste = '$paste'");
my $link = "http://perlpaste.com/pastes/@$key[0]";
template 'paste.tt', {
'title' => $title,
'paste' => $paste,
'key' => @$key[0],
'link' => $link,
};
};
get '/pastes/:id' => sub {
my $id = params->{id};
my $title = $db->selectall_arrayref("select title from pastes where pastekey = $id");
my $paste = $db->selectall_arrayref("select paste from pastes where pastekey = $id");
template 'paste.tt', {
'title' => @$title[0],
'paste' => @$paste[0],
'key' => $id,
'link' => '',
};
};
dance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment