diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..f147648 --- /dev/null +++ b/Build.PL @@ -0,0 +1,25 @@ +use strict; +use warnings; +use Module::Build; + +my $builder = Module::Build->new( + module_name => 'App::Nopaste::Service::Pastedance', + license => 'perl', + dist_author => q{Danijel Tasov }, + dist_version_from => 'lib/App/Nopaste/Service/Pastedance.pm', + dist_abstract => 'Add Pastedance service to App::Nopaste', + build_requires => { + 'Test::More' => 0, + }, + requires => { + 'App::Nopaste' => 0, + }, + add_to_cleanup => [ 'App-Nopaste-*' ], + meta_merge => { + resources => { + #repository => 'http://github.com/datamuc/WWW-Shorten-URLchen', + }, + }, +); + +$builder->create_build_script(); diff --git a/lib/App/Nopaste/Service/Pastedance.pm b/lib/App/Nopaste/Service/Pastedance.pm new file mode 100644 index 0000000..cb1faee --- /dev/null +++ b/lib/App/Nopaste/Service/Pastedance.pm @@ -0,0 +1,103 @@ +package App::Nopaste::Service::Pastedance; + +use warnings; +use strict; +use Scalar::Util 'blessed'; + +our $VERSION = '0.01'; + +use base q[App::Nopaste::Service]; + +sub uri { return 'http://pb.rbfh.de/' } + + +sub fill_form { + my ($self, $mech) = (shift, shift); + my %args = @_; + + my $content = { + code => $args{text}, + subject => $args{desc}, + lang => exists( $self->FORMATS->{ $args{lang} } ) + ? $self->FORMATS->{ $args{lang} } + : 'txt', + }; + + $mech->agent_alias('Linux Mozilla'); + my $form = $mech->form_number(1) || 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_number => 1, fields => $content ); +} + +sub return { + my $self = shift; + my $mech = shift; + my $response = $mech->response; + if($response->is_redirect) { + return (1,$response->header("Location")); + } else { + return (0, "Cannot find URL"); + } +} + +sub FORMATS { + { + ada => "Ada", + applescript => "Applescript", + asm => "Assembler", + bib => "Bib", + yacc => "Bison", + shell => "Bourne Shell", + c => "C", + csharp => "C#", + 'c++' => "C++", + caml => "CAML", + changelog => "changelog", + cobol => "COBOL", + conf => "conf", + css => "CSS", + d => "D", + diff => "diff", + bat => "DOS Batch", + erl => "Erlang", + flex => "Flex", + f77 => "Fortran (Fixed)", + f90 => "Fortran (Free)", + glsl => "GLSL", + haskell => "Haskell", + html => "HTML", + ini => "INI", + java => "Java", + js => "Javascript", + latex => "LaTeX", + ldif => "LDIF", + lua => "Lua", + m4 => "m4", + make => "Makefile", + pascal => "Pascal", + perl => "Perl", + php => "PHP", + ps => "Postscript", + python => "Python", + ruby => "Ruby", + scala => "Scala", + slang => "Slang", + sql => "SQL", + txt => "txt", + tcl => "tcl/tk", + vb => "VB Script", + xml => "XML", + xorg => "Xorg", + }; +} + +__END__