App-Nopaste-Service-AnyPastebin

 view release on metacpan or  search on metacpan

lib/App/Nopaste/Service/AnyPastebin.pm  view on Meta::CPAN

package App::Nopaste::Service::AnyPastebin;

use warnings;
use strict;
use Scalar::Util 'blessed';

use base q[App::Nopaste::Service];

our $VERSION = '0.04';

sub uri { return 'http://pastebin.com/' }

sub forbid_in_default { 0 }

sub get {
    my $self = shift;
    my $mech = shift;
    my %args = @_;

    $mech->{__username} = $args{username}
        if exists($args{username}) && $args{username};
    $mech->{__password} = $args{password}
        if exists($args{password}) && $args{password};

    return $self->SUPER::get($mech => @_);
}

sub post_content {
    my ($self, %args) = @_;

    return {
        paste => 'Send',
        code2 => $args{text},
        poster => exists($args{nick})? $args{nick} : '',
        format => exists($self->FORMATS->{$args{lang}})? $args{lang} : 'text',
        expiry => 'd'
    };
}

sub fill_form {
    my ($self, $mech) = (shift, shift);
    my %args = @_;

    my $header = {
        'User-Agent' => 'Mozilla/5.0',
        'Content-Type' => 'application/x-www-form-urlencoded'
    };

    my $content = $self->post_content(%args);

    $mech->agent_alias('Linux Mozilla');
    my $form = $mech->form_name('editor') || return;

    # do not follow redirect please
    @{$mech->requests_redirectable} = ();

    my $paste = HTML::Form::Input->new(
        type => 'text',
        value => 'Send',
        name => 'paste'
    )->add_to_form($form);

    return $mech->submit_form( form_name => 'editor', fields => $content );
}

sub return {
    my ($self, $mech) = (shift, shift);

    return unless blessed($mech->res) && $mech->res->can('header');

    my $result  = $mech->res->header('Location')? 1 : 0;
    my $link_or_err = $result? $mech->res->header('Location') : 'Error!';

    return (1, $link_or_err);
}

use constant FORMATS => {
    abap => 1,
    actionscript => 1,
    ada => 1,
    apache => 1,
    applescript => 1,
    asm => 1,
    asp => 1,
    autoit => 1,



( run in 0.634 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )