File Coverage

blib/lib/Mojolicious/Command/nopaste/Service/pastie.pm
Criterion Covered Total %
statement 3 11 27.2
branch 0 2 0.0
condition 0 3 0.0
subroutine 1 2 50.0
pod 0 1 0.0
total 4 19 21.0


line stmt bran cond sub pod time code
1             package Mojolicious::Command::nopaste::Service::pastie;
2 1     1   715 use Mojo::Base 'Mojolicious::Command::nopaste::Service';
  1         2  
  1         5  
3              
4             has description => "Post to pastie.org\n";
5              
6             my %languages = (
7             "bash" => "13",
8             "c#" => "20",
9             "c/c++" => "7",
10             "css" => "8",
11             "diff" => "5",
12             "go" => "21",
13             "html (erb / rails)" => "12",
14             "html / xml" => "11",
15             "java" => "9",
16             "javascript" => "10",
17             "objective-c/c++" => "1",
18             "perl" => "18",
19             "php" => "15",
20             "plain text" => "6",
21             "python" => "16",
22             "ruby" => "3",
23             "ruby on rails" => "4",
24             "sql" => "14",
25             # hidden
26             "apache" => "22",
27             "clojure" => "38",
28             "d" => "26",
29             "erlang" => "27",
30             "fortran" => "28",
31             "haskell" => "29",
32             "ini" => "35",
33             "io" => "24",
34             "lisp" => "25",
35             "lua" => "23",
36             "makefile" => "31",
37             "nu" => "36",
38             "pascal" => "17",
39             "puppet" => "39",
40             "scala" => "32",
41             "scheme" => "33",
42             "smarty" => "34",
43             "tex" => "37",
44             # aliases
45             "sh" => "13",
46             "c" => "7",
47             "c++" => "7",
48             "objective-C" => "1",
49             "objective-C++" => "1",
50             "plain" => "6",
51             "raw" => "6",
52             "rails" => "4",
53             "html" => "11",
54             "xml" => "11",
55             "js" => "10",
56             "make" => "31",
57             );
58              
59             sub paste {
60 0     0 0   my $self = shift;
61 0   0       my $lang_id = $languages{lc($self->language || '')} || $languages{'plain text'};
62              
63 0           my $tx = $self->ua->post( 'http://pastie.org/pastes', form => {
64             'paste[body]' => $self->text,
65             'paste[authorization]' => 'burger', # set with JS to avoid bots
66             'paste[restricted]' => $self->private,
67             'paste[parser_id]' => $lang_id,
68             });
69              
70 0 0         unless ($tx->res->is_success) {
71 0           say $tx->res->message;
72 0           say $tx->res->body;
73 0           exit 1;
74             }
75              
76 0           return $tx->req->url;
77             }
78              
79             1;
80