Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

BooK (2612)

BooK
  {book} {at} {cpan.org}
http://paris.mongueurs.net/
Yahoo! ID: philippe_bruhat (Add User, Send Message)

Obfuscation [plover.com]. Pink [axis-of-aevil.net]. HTTP::Proxy [cpan.org]. YEF [yapceurope.org]. Fishnet [perl.org]. Kapow [cpan.org]. Cog's [perl.org] bitch [cpan.org]. Invitation [perl.org]. White [perl.org] Camel [perl.org]. Nuff' said.

Journal of BooK (2612)

Sunday November 08, 2009
11:34 AM

nopaste

[ #39862 ]

Just a quick post to show off a small and useful script I use whenever I need to "nopaste" some text or code:

    #!/usr/bin/perl -w
    use strict;
    use WWW::Mechanize;
    use Getopt::Long;

    my %SITE = (
        snit  => 'http://nopaste.snit.ch/',
        scsys => 'http://paste.scsys.co.uk/',
    );

    my %CONF = (
        channel => '',
        nick    => '',       # use your own
        summary => '',
        paste   => '',
        site    => 'snit',
        list    => '',
    );

    GetOptions( \%CONF, 'lang=s', 'nick=s', 'summary|desc=s', 'paste|text=s',
        'list!', 'site=s' )
        or die "Bad options";

    die "No such paste site: $CONF{site}\nValid choices: @{[keys %SITE]}\n"
        if !exists $SITE{ $CONF{site} };

    my $m = WWW::Mechanize->new;
    $m->get( $SITE{ $CONF{site} } );
    die $m->res->status_line unless $m->success;

    if ( $CONF{list} ) {
        print "Possible channels for $CONF{site}:\n",
            map {"- $_\n"} grep $_,
            $m->current_form()->find_input('channel')->possible_values;
        exit;
    }

    unless ( $CONF{paste} ) {
        $CONF{summary} ||= $ARGV[0] || '-';
        $CONF{paste} = join "", <>;
    }

    delete @CONF{qw( site list )};
    $m->set_fields(%CONF);
    $m->submit;
    die $m->res->status_line unless $m->success;

    print +( $m->links )[0]->url, "\n";

Since it works has a filter, I can call it from vim or pipe to it. It also works with a file parameter, which is used to set the paste title.

Just before posting this, I looked again on CPAN, and found the follwing:

  • App::NoPaste: Seems really complete. But does much more than I need, and I like depending only on WWW::Mechanize for such tools.

  • WWW::Rafb: Well, in an earlier version my script worked with rafb.net, but the site itself is down.

  • WWW::PasteBin: Such a huge collection of distributions, I wouldn't which to install first.

  • WebService::NoPaste: Found it years ago when looking for a nopaste utility, but I preferred to write my own.

Clearly, there is no lack of modules to nopaste stuff, so I'm not going to add my own to the list. :-)

I tried publishing scripts on CPAN, but I feel the toolchain is not really targetting scripts, anyway. Anyway, I have a few utility scripts like the above lying around, and I'm thinking maybe the best way to go with them nowadays is to just publish them on GitHub. Might happen someday.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.