#!/usr/bin/perl -w
#
#	Author:		Fred Blaise <chapeaurouge_at_madpenguin_dot_org>
#	Date:		21 Nov 2005
#	Purpose:	Make it easy to paste a file to pastebin.ca
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#  
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
use strict;
use WWW::Mechanize;
use Getopt::Long;

# Types of text, and their option number
# 
# [22/ASP|18/Action Script|19/Ada Source|20/Apache Configuration|21/Assembly (NASM)|2/Asterisk Configuration|23/BASH Script|3/C Source|9/C# Source|4/C++ Source|24/CSS|25/Delphi Source|26/HTML 4.0 Strict|7/Java Source|27/JavaScript|28/LISP Source|29/Lua Source|30/Microprocessor ASM|31/Objective C|5/PHP Source|14/PL/I Source|12/Pascal Source|6/Perl Source|11/Python Source|*1/Raw|10/Ruby Source|16/SQL Statement|17/Scheme Source|32/Visual Basic .NET|8/Visual Basic Source|15/XML Document|13/mIRC Script]

# Expiry options
#  [*/Never|5 minutes|10 minutes|15 minutes|30 minutes|45 minutes|1 hour|2 hours|4 hours|8 hours|12 hours|1 day|2 days|3 days|1 week|2 weeks|3 weeks|1 month|2 months|3 months|4 months|5 months|6 months|1 year]

my $pastebin_url="http://pastebin.ca";

my %f = (
	content		=>	'',
	description	=>	'',
	type		=>	'1',
	expiry		=>	'Never',
	name		=>	'clueless',
);

GetOptions ( \%f,
		"content=s",
		"description=s",
		"type=i",
		"expiry=s",
		"name=s"
) || die $!;

my $boy = WWW::Mechanize->new();

$boy->get($pastebin_url);

die $! unless ($boy->success());

unless ($f{content}) {
	$f{description} = $ARGV[0];
	$f{description} .= " -- automated paste by paste2pastebin.pl - chapeaurouge_AT_madpenguin_DOT_org";
	$f{content} = join "", <>;
}

$boy->form_number(2);
$boy->set_fields(%f);
$boy->submit_form( button => 's');

die unless ($boy->success);

# dirty hack for now...
my $paste_num = $boy->find_link( url_regex => qr/\d{5}/ )->url();
print "Your paste URL is: " . $pastebin_url . "/" . $paste_num . "\n";

