1c618bd9233a02bf2f15495cf3225a9d23b06eb4
[sdlgit/SDL_perl.git] / tools / nopaste.pl
1 #!perl
2
3 # Copyright (C) 2008, Parrot Foundation.
4 # $Id: nopaste.pl 38612 2009-05-08 18:30:25Z Infinoid $
5
6 use 5.008;
7 use strict;
8 use warnings;
9
10 use WWW::Mechanize;
11 use Getopt::Std;
12 use Pod::Usage;
13
14
15 my $server  = 'scsys.co.uk';
16 my $url     = "http://$server:8001/paste";
17 my $opt     = {
18     c => '#sdl',                              # channel
19     n => getlogin || getpwuid($<) || 'someone',  # name
20     t => undef,                                  # title
21 };
22
23 getopt( 'c:n:t:', $opt );
24
25 pod2usage(2)
26     unless defined $opt->{t};
27
28
29 my $text; while(<>) { $text .= $_; }
30 my $mech  = WWW::Mechanize->new(
31     cookie_jar => undef,
32     autocheck  => 1,
33 );
34
35 $mech->get( $url );
36
37 $mech->submit_form(
38     form_name => 'pasteForm',
39     fields    => {
40         (defined $opt->{c} ?
41         (channel => $opt->{c}) :
42         (channel => '#sdl'  )
43         ),
44         nick    => $opt->{n},
45         summary => $opt->{t},
46         paste   => $text,
47     },
48     button    => 'Paste it',
49 );
50
51 my @link = $mech->links;
52 print "Your paste can be found at ", $link[0]->url, "\n";
53
54
55 =head1 NAME
56
57 tools/dev/nopaste.pl - paste the contents of a file via a pastebot server
58
59 =head1 SYNOPSIS
60
61   nopaste.pl -t "TITLE" [ -c CHANNEL ] [ -n NAME ] [ FILENAME ]
62
63     TITLE     the title of the paste
64     CHANNEL   the irc channel (defaults to #parrot)
65     NAME      the username (defaults to username or 'someone')
66     FILENAME  the name of the file to paste (defaults to STDIN)
67
68 =head1 DESCRIPTION
69
70 This program can be used to paste the contents of a file on a pastebot server
71 -- specifically, B<nopaste.snit.ch> -- for immediate linkage on an IRC channel --
72 by default, B<#sdl>.
73
74 =head1 AUTHOR
75
76 Originally written by particle, with subsequent contributions to functionality
77 by LimbicRegion, paultcochrane and cotto.
78
79 =cut
80
81 # Local Variables:
82 #   mode: cperl
83 #   cperl-indent-level: 4
84 #   fill-column: 100
85 # End:
86 # vim: expandtab shiftwidth=4: