blib/lib/WWW/Pastebin/PastebinCom/API.pm

filter: Statementstmt 68.5% 124 / 181 Branchbran 34.9% 37 / 106 Conditioncond 25.4% 16 / 63 MC/DCmcdc 2.4% 1 / 41 Subroutinesub 87.5% 21 / 24 Podpod 100% 8 / 8 totaltotal 48.9% 207 / 423 CC 81 SCAR 34.2
CC
81
Cov
51%
list_user_pastes
110.0
delete_paste
72.0
_prepare_optional_api_options
53.7
CRAP 30.7
↑ Summary
1 package WWW::Pastebin::PastebinCom::API;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '1.001003'; # VERSION
7  
8 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use HTTP::Cookies;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use base qw/Class::Data::Accessor/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 __PACKAGE__->mk_classaccessors(qw/
14 error
15 api_key
16 user_key
17 paste_url
18 _ua
19 /);
20  
21 use overload q|""| => sub {
22 4 ▶ my $obj = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
23 4 ▶ defined $obj->error ? 'Error: ' . $obj->error : $obj->paste_url
Branch: 1 branch
BranchTrueFalseTotal
defined $obj->error ? : 2 2 4
24 3 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 sub new {
27 1 ▶ my $class = shift;
Subroutine new: called CC=5 SCAR=16.6
Pod documented
28 1 ▶ croak 'Must have even number of arguments to the constructor'
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 1 1
29 if @_ & 1;
30  
31 1 my %args = @_;
32 1 $args{ +lc } = delete $args{ $_ } for keys %args;
33  
34 1 ▶ unless ( $args{timeout} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"timeout"}) 0 1 1
35 0 $args{timeout} = 30;
36 }
37 1 ▶ unless ( $args{ua} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"ua"}) 1 0 1
38 $args{ua} = LWP::UserAgent->new(
39 timeout => $args{timeout},
40 1 agent => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:21.0)'
41 . ' Gecko/20100101 Firefox/21.0',
42 );
43 }
44  
45 1 my $self = bless {}, $class;
46 1 $self->_ua( $args{ua} );
47 1 $self->api_key( $args{api_key} );
48 1 $self->user_key( $args{user_key} );
49  
50 1 return $self;
51 }
52  
53 sub get_user_info {
54 1 ▶ my $self = shift;
Subroutine get_user_info: called CC=6 SCAR=20.8
Pod documented
55 1 $self->error( undef );
56  
57 1 ▶ my $api_key = $self->_get_api_key
Branch: 1 branch
BranchTrueFalseTotal
my $api_key = $self->_get_api_key or return $self->_set_error("Missing API key") 0 1 1
58 or return $self->_set_error(q|Missing API key|);
59  
60 1 ▶ my $user_key = $self->_get_user_key
Branch: 1 branch
BranchTrueFalseTotal
my $user_key = $self->_get_user_key or return $self->_set_error("Missing USER key. See ->get_user_key() method") 0 1 1
61 or return $self->_set_error(
62 q|Missing USER key. See ->get_user_key() method|
63 );
64  
65 1 my $response = $self->_ua->post(
66 'http://pastebin.com/api/api_post.php',
67 {
68 api_dev_key => $api_key,
69 api_user_key => $user_key,
70 api_option => 'userdetails',
71 },
72 );
73  
74 1 ▶ if ( $response->is_success or $response->is_redirect ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success or $response->is_redirect) { } 1 0 1
Condition33%1/3
$response->is_success or $response->is_redirect
l!l&&r!l&&!r
010
MC/DC0%0/2
$response->is_success or $response->is_redirect
$response->is_success $response->is_redirect
Truth table33%1/3
A or B
A= $response->is_successB= $response->is_redirect
ABresult
1X1
011
000
75 1 ▶ return $self->_set_error( $response->content )
Branch: 1 branch
BranchTrueFalseTotal
if $response->content =~ /^Bad API request/ 0 1 1
76 if $response->content =~ /^Bad API request/;
77  
78 1 return $self->_parse_user_xml( $response->content );
79 }
80 else {
81 0 $self->error( $response->status_line );
82 0 return;
83 }
84 }
85  
86 sub list_user_pastes {
87 0 ▶ my $self = shift;
Subroutine list_user_pastes: not called CC=10 SCAR=47.0
Pod documented
88 0 ▶ my $limit = shift || 50;
Condition0%0/2
shift() || 50
l!l
00
MC/DC0%0/1
shift() || 50
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
89 0 ▶ $limit = 1 if $limit < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $limit < 1 0 0 0
90 0 ▶ $limit = 1000 if $limit > 1000;
Branch: 1 branch
BranchTrueFalseTotal
if $limit > 1000 0 0 0
91  
92 0 $self->error( undef );
93  
94 0 ▶ my $api_key = $self->_get_api_key
Branch: 1 branch
BranchTrueFalseTotal
my $api_key = $self->_get_api_key or return $self->_set_error("Missing API key") 0 0 0
95 or return $self->_set_error(q|Missing API key|);
96  
97 0 ▶ my $user_key = $self->_get_user_key
Branch: 1 branch
BranchTrueFalseTotal
my $user_key = $self->_get_user_key or return $self->_set_error("Missing USER key. See ->get_user_key() method") 0 0 0
98 or return $self->_set_error(
99 q|Missing USER key. See ->get_user_key() method|
100 );
101  
102 0 my $response = $self->_ua->post(
103 'http://pastebin.com/api/api_post.php',
104 {
105 api_dev_key => $api_key,
106 api_user_key => $user_key,
107 api_results_limit => $limit,
108 api_option => 'list',
109 },
110 );
111  
112 0 ▶ if ( $response->is_success or $response->is_redirect ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success or $response->is_redirect) { } 0 0 0
Condition0%0/3
$response->is_success or $response->is_redirect
l!l&&r!l&&!r
000
MC/DC0%0/2
$response->is_success or $response->is_redirect
$response->is_success $response->is_redirect
Truth table0%0/3
A or B
A= $response->is_successB= $response->is_redirect
ABresult
1X1
011
000
113 0 ▶ return $self->_set_error( $response->content )
Branch: 1 branch
BranchTrueFalseTotal
if $response->content =~ /^Bad API request/ 0 0 0
114 if $response->content =~ /^Bad API request/;
115  
116 0 ▶ return []
Branch: 1 branch
BranchTrueFalseTotal
if $response->content =~ /^No pastes found/ 0 0 0
117 if $response->content =~ /^No pastes found/;
118  
119 0 return $self->_parse_xml( $response->content );
120 }
121 else {
122 0 $self->error( $response->status_line );
123 0 return;
124 }
125 }
126  
127 sub list_trends {
128 1 ▶ my $self = shift;
Subroutine list_trends: called CC=5 SCAR=18.7
Pod documented
129  
130 1 $self->error( undef );
131  
132 1 ▶ my $api_key = $self->_get_api_key
Branch: 1 branch
BranchTrueFalseTotal
my $api_key = $self->_get_api_key or return $self->_set_error("Missing API key") 0 1 1
133 or return $self->_set_error(q|Missing API key|);
134  
135 1 my $response = $self->_ua->post(
136 'http://pastebin.com/api/api_post.php',
137 {
138 api_dev_key => $api_key,
139 api_option => 'trends',
140 },
141 );
142  
143 1 ▶ if ( $response->is_success or $response->is_redirect ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success or $response->is_redirect) { } 1 0 1
Condition33%1/3
$response->is_success or $response->is_redirect
l!l&&r!l&&!r
010
MC/DC0%0/2
$response->is_success or $response->is_redirect
$response->is_success $response->is_redirect
Truth table33%1/3
A or B
A= $response->is_successB= $response->is_redirect
ABresult
1X1
011
000
144 1 ▶ return $self->_set_error( $response->content )
Branch: 1 branch
BranchTrueFalseTotal
if $response->content =~ /^Bad API request/ 0 1 1
145 if $response->content =~ /^Bad API request/;
146  
147 1 return $self->_parse_xml( $response->content );
148 }
149 else {
150 0 $self->error( $response->status_line );
151 0 return;
152 }
153 }
154  
155 sub delete_paste {
156 0 ▶ my $self = shift;
Subroutine delete_paste: not called CC=8 SCAR=42.8
Pod documented
157 0 my $paste_key = shift;
158  
159 0 $paste_key =~ s{(?:https?://)?(?:www\.)?pastebin\.com/}{}i;
160  
161 0 ▶ return $self->_set_error('Missing paste key')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $paste_key and length $paste_key 0 0 0
Condition0%0/3
defined $paste_key and length $paste_key
!ll&&!rl&&r
000
MC/DC0%0/2
defined $paste_key and length $paste_key
defined $paste_key length $paste_key
Truth table0%0/3
A and B
A= defined $paste_keyB= length $paste_key
ABresult
0X0
100
111
162 unless defined $paste_key and length $paste_key;
163  
164 0 $self->error( undef );
165  
166 0 ▶ my $api_key = $self->_get_api_key
Branch: 1 branch
BranchTrueFalseTotal
my $api_key = $self->_get_api_key or return $self->_set_error("Missing API key") 0 0 0
167 or return $self->_set_error(q|Missing API key|);
168  
169 0 ▶ my $user_key = $self->_get_user_key
Branch: 1 branch
BranchTrueFalseTotal
my $user_key = $self->_get_user_key or return $self->_set_error("Missing USER key. See ->get_user_key() method") 0 0 0
170 or return $self->_set_error(
171 q|Missing USER key. See ->get_user_key() method|
172 );
173  
174 0 my $response = $self->_ua->post(
175 'http://pastebin.com/api/api_post.php',
176 {
177 # mandatory API keys
178 api_dev_key => $api_key,
179 api_user_key => $user_key,
180 api_paste_key => $paste_key,
181 api_option => 'delete',
182 },
183 );
184  
185 0 ▶ if ( $response->is_success or $response->is_redirect ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success or $response->is_redirect) { } 0 0 0
Condition0%0/3
$response->is_success or $response->is_redirect
l!l&&r!l&&!r
000
MC/DC0%0/2
$response->is_success or $response->is_redirect
$response->is_success $response->is_redirect
Truth table0%0/3
A or B
A= $response->is_successB= $response->is_redirect
ABresult
1X1
011
000
186 0 ▶ return $self->_set_error( $response->content )
Branch: 1 branch
BranchTrueFalseTotal
if $response->content =~ /^Bad API request/ 0 0 0
187 if $response->content =~ /^Bad API request/;
188  
189 0 return 1;
190 }
191 else {
192 0 $self->error( $response->status_line );
193 0 return;
194 }
195 0 return 1;
196 }
197  
198 sub get_paste {
199 2 ▶ my $self = shift;
Subroutine get_paste: called CC=11 SCAR=30.7
Pod documented
200 2 my $paste_key = shift;
201 2 my ( $login, $pass ) = @_;
202  
203 2 $self->error( undef );
204  
205 2 $paste_key =~ s{(?:https?://)?(?:www\.)?pastebin\.com/}{}i;
206  
207 2 ▶ defined $paste_key and length $paste_key
Branch: 1 branch
BranchTrueFalseTotal
defined $paste_key and length $paste_key or return $self->_set_error("Missing paste ID or URL") 0 2 2
Condition33%1/3
defined $paste_key and length $paste_key
!ll&&!rl&&r
002
MC/DC0%0/2
defined $paste_key and length $paste_key
defined $paste_key length $paste_key
Truth table33%1/3
A and B
A= defined $paste_keyB= length $paste_key
ABresult
0X0
100
111
208 or return $self->_set_error('Missing paste ID or URL');
209  
210 2 ▶ if ( defined $login and defined $pass ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $login and defined $pass) 1 1 2
Condition66%2/3
defined $login and defined $pass
!ll&&!rl&&r
101
MC/DC50%1/2
defined $login and defined $pass
defined $login defined $pass
Truth table66%2/3
A and B
A= defined $loginB= defined $pass
ABresult
0X0
100
111
211 1 $self->_ua->cookie_jar( HTTP::Cookies->new );
212 1 $self->_ua->post(
213 'http://pastebin.com/login.php', {
214 submit_hidden => 'submit_hidden',
215 user_name => $login,
216 user_password => $pass,
217 submit => 'Login',
218 }
219 );
220 }
221  
222 2 my $response = $self->_ua->get(
223 "http://pastebin.com/raw.php?i=$paste_key",
224 );
225  
226 2 $self->_ua->cookie_jar( undef );
227  
228 2 ▶ if ( $response->is_success or $response->is_redirect ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success or $response->is_redirect) { } 0 2 2
Condition33%1/3
$response->is_success or $response->is_redirect
l!l&&r!l&&!r
002
MC/DC0%0/2
$response->is_success or $response->is_redirect
$response->is_success $response->is_redirect
Truth table33%1/3
A or B
A= $response->is_successB= $response->is_redirect
ABresult
1X1
011
000
229 0 ▶ return $self->_set_error(q|This paste doesn't exist|)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response->content and length $response->content 0 0 0
Condition0%0/3
defined $response->content and length $response->content
!ll&&!rl&&r
000
MC/DC0%0/2
defined $response->content and length $response->content
defined $response->content length $response->content
Truth table0%0/3
A and B
A= defined $response->contentB= length $response->content
ABresult
0X0
100
111
230 unless defined $response->content
231 and length $response->content;
232  
233 0 ▶ return $self->_set_error( $response->content )
Branch: 1 branch
BranchTrueFalseTotal
if $response->content eq "Error, this is a private paste. If this is your private paste, please login to Pastebin first." 0 0 0
234 if $response->content
235 eq 'Error, this is a private paste. If this is your '
236 . 'private paste, please login to Pastebin first.';
237  
238 0 return $response->content;
239 }
240 else {
241 2 ▶ if ( $response->status_line eq '404 Not Found' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->status_line eq '404 Not Found') { } 2 0 2
242 2 $self->error(q|This paste doesn't exist|);
243 }
244 else {
245 0 $self->error( 'Network error: ' . $response->status_line );
246 }
247 2 return;
248 }
249 }
250  
251 sub paste {
252 1 ▶ my $self = shift;
Subroutine paste: called CC=9 SCAR=25.4
Pod documented
253 1 my $paste_text = shift;
254  
255 1 $self->error( undef );
256 1 $self->paste_url( undef );
257  
258 1 ▶ defined $paste_text and length $paste_text
Branch: 1 branch
BranchTrueFalseTotal
defined $paste_text and length $paste_text or return $self->_set_error("Paste text is empty") 0 1 1
Condition33%1/3
defined $paste_text and length $paste_text
!ll&&!rl&&r
001
MC/DC0%0/2
defined $paste_text and length $paste_text
defined $paste_text length $paste_text
Truth table33%1/3
A and B
A= defined $paste_textB= length $paste_text
ABresult
0X0
100
111
259 or return $self->_set_error('Paste text is empty');
260  
261 1 my %args = @_;
262 1 $args{ +lc } = delete $args{ $_ } for keys %args;
263  
264 1 ▶ my @args = $self->_prepare_optional_api_options( \%args )
Branch: 1 branch
BranchTrueFalseTotal
my(@args) = $self->_prepare_optional_api_options(\%args) or return 0 1 1
265 or return;
266  
267 1 ▶ my $api_key = $self->_get_api_key
Branch: 1 branch
BranchTrueFalseTotal
my $api_key = $self->_get_api_key or return $self->_set_error("Missing API key") 0 1 1
268 or return $self->_set_error(q|Missing API key|);
269  
270 1 my $response = $self->_ua->post(
271 'http://pastebin.com/api/api_post.php',
272 {
273 # mandatory API keys
274 api_dev_key => $api_key,
275 api_option => 'paste',
276 api_paste_code => $paste_text,
277  
278 @args,
279 },
280 );
281  
282 1 ▶ if ( $response->is_success or $response->is_redirect ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success or $response->is_redirect) { } 1 0 1
Condition33%1/3
$response->is_success or $response->is_redirect
l!l&&r!l&&!r
010
MC/DC0%0/2
$response->is_success or $response->is_redirect
$response->is_success $response->is_redirect
Truth table33%1/3
A or B
A= $response->is_successB= $response->is_redirect
ABresult
1X1
011
000
283 1 ▶ return $self->_set_error( $response->content )
Branch: 1 branch
BranchTrueFalseTotal
if $response->content =~ /^Bad API request|^Post limit, maximum pastes/ 0 1 1
284 if $response->content =~ /^Bad API request|^Post limit, maximum pastes/;
285  
286 1 return $self->paste_url( $response->content );
287 }
288 else {
289 0 $self->error( $response->status_line );
290 0 return;
291 }
292 }
293  
294 sub get_user_key {
295 1 ▶ my ( $self, $login, $pass ) = @_;
Subroutine get_user_key: called CC=5 SCAR=18.3
Pod documented
296  
297 1 $self->error( undef );
298 1 $self->user_key( undef );
299  
300 1 ▶ my $api_key = $self->_get_api_key
Branch: 1 branch
BranchTrueFalseTotal
my $api_key = $self->_get_api_key or return $self->_set_error("Missing API key") 0 1 1
301 or return $self->_set_error(q|Missing API key|);
302  
303 1 my $response = $self->_ua->post(
304 'http://pastebin.com/api/api_login.php',
305 {
306 api_dev_key => $api_key,
307 api_user_name => $login,
308 api_user_password => $pass,
309 },
310 );
311  
312 1 ▶ if ( $response->is_success or $response->is_redirect ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success or $response->is_redirect) { } 1 0 1
Condition33%1/3
$response->is_success or $response->is_redirect
l!l&&r!l&&!r
010
MC/DC0%0/2
$response->is_success or $response->is_redirect
$response->is_success $response->is_redirect
Truth table33%1/3
A or B
A= $response->is_successB= $response->is_redirect
ABresult
1X1
011
000
313 1 ▶ return $self->_set_error( $response->content )
Branch: 1 branch
BranchTrueFalseTotal
if $response->content =~ /^Bad API request/ 0 1 1
314 if $response->content =~ /^Bad API request/;
315  
316 1 return $self->user_key( $response->content );
317 }
318 else {
319 0 $self->error( $response->status_line );
320 0 return;
321 }
322 }
323  
324 sub _parse_user_xml {
325 1 ▶ my ( $self, $content ) = @_;
Subroutine _parse_user_xml: called CC=5 SCAR=17.8
326  
327 1 $content =~ s{<user>\s*(.+)\s*</user>}{$1}gs;
328  
329 1 my %user = $content =~ ( m{<([^>]+)>(.*?)</\1>}sg );
330 1 $user{ substr $_, 5 } = delete $user{ $_ } for keys %user;
331 1 ▶ if ( $user{private} == 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($user{'private'} == 2) { } 0 1 1
elsif ($user{'private'} == 1) { } 0 1 1
332 0 $user{private} = 1
333 }
334 elsif ( $user{private} == 1 ) {
335 0 $user{unlisted} = 1;
336 }
337 else {
338 1 delete $user{private};
339 }
340  
341 1 ▶ return wantarray ? %user : \%user;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
342 }
343  
344 sub _parse_xml {
345 1 ▶ my ( $self, $content ) = @_;
Subroutine _parse_xml: called CC=6 SCAR=29.3
346  
347 1 my @out;
348 1 for ( $content =~ m{<paste>(.+?)</paste>}gs ) {
349 0 my %paste = ( m{<([^>]+)>(.*?)</\1>}sg );
350 0 $paste{ substr $_, 6 } = delete $paste{ $_ } for keys %paste;
351  
352 0 my $private_flag = delete $paste{private};
353 0 ▶ if ( $private_flag == 2 ) { $paste{private} = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if ($private_flag == 2) { } 0 0 0
elsif ($private_flag == 1) { } 0 0 0
354 0 elsif ( $private_flag == 1 ) { $paste{unlisted} = 1; }
355  
356 0 push @out, \%paste;
357 }
358  
359 1 ▶ return wantarray ? @out : \@out;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
360 }
361  
362 sub _get_user_key {
363 1 ▶ my $self = shift;
Subroutine _get_user_key: called CC=2 SCAR=7.2
364  
365 1 ▶ return $self->user_key
Condition50%1/2
$self->user_key || (return $self->_set_error('API user key must be provided to create private pastes. See ->user_key() or ->get_user_key() in the documentation.'))
l!l
10
MC/DC0%0/1
$self->user_key || (return $self->_set_error('API user key must be provided to create private pastes. See ->user_key() or ->get_user_key() in the documentation.'))
$self->user_key
Truth table50%1/2
A
A= $self->user_key
Aresult
11
00
366 || return $self->_set_error('API user key must be provided'
367 . ' to create private pastes. See ->user_key() or'
368 . ' ->get_user_key() in the documentation.');
369 }
370  
371 sub _get_api_key {
372 4 ▶ my $self = shift;
Subroutine _get_api_key: called CC=2 SCAR=7.2
373  
374 4 ▶ return $self->api_key
Condition50%1/2
$self->api_key || (return $self->_set_error(q[Can't operate without an API key. Sign up / Log in to pastebin.com, then go to http://pastebin.com/api to see your API key (it's in the section "Your Unique Developer API Key")]))
l!l
40
MC/DC0%0/1
$self->api_key || (return $self->_set_error(q[Can't operate without an API key. Sign up / Log in to pastebin.com, then go to http://pastebin.com/api to see your API key (it's in the section "Your Unique Developer API Key")]))
$self->api_key
Truth table50%1/2
A
A= $self->api_key
Aresult
11
00
375 || return $self->_set_error(q|Can't operate without an API key.|
376 . q| Sign up / Log in to pastebin.com, then go|
377 . q| to http://pastebin.com/api to see your API key|
378 . q| (it's in the section "Your Unique Developer API Key")|);
379 }
380  
381 sub _prepare_optional_api_options {
382 1 ▶ my ( $self, $args ) = @_;
Subroutine _prepare_optional_api_options: called CC=16 SCAR=39.8
383 1 my @out_args;
384  
385 push @out_args, api_paste_name => $args->{title}
386 1 ▶ if defined $args->{title}; # title of the paste
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"title"} 0 1 1
387  
388 1 ▶ if ( defined $args->{format} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"format"}) 1 0 1
389 $self->_is_valid_format( $args->{format} )
390 1 ▶ or return $self->_set_error(
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_valid_format($args->{"format"}) or return $self->_set_error("Invalid syntax highlighting code. See ->valid_formats() method in the documentation") 0 1 1
391 'Invalid syntax highlighting code. See ->valid_formats()'
392 . ' method in the documentation'
393 );
394 1 push @out_args, api_paste_format => $args->{format};
395 }
396  
397 1 ▶ if( $args->{owned} and not $args->{private} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"owned"} and not $args->{"private"}) 0 1 1
Condition33%1/3
$args->{"owned"} and not $args->{"private"}
!ll&&!rl&&r
100
MC/DC0%0/2
$args->{"owned"} and not $args->{"private"}
$args->{"owned"} not $args->{"private"}
Truth table33%1/3
A and not(B)
A= $args->{"owned"}B= not $args->{"private"}
ABresult
0X0
100
111
398 0 ▶ defined ( $args->{user_key} || $self->user_key )
Branch: 1 branch
BranchTrueFalseTotal
defined($args->{"user_key"} || $self->user_key) or return $self->set_error("API user key must be provided to create owned pastes. See ->user_key() or ->get_user_key() in the documentation.") 0 0 0
Condition0%0/3
$args->{'user_key'} || $self->user_key
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'user_key'} || $self->user_key
$args->{'user_key'} $self->user_key
Truth table0%0/3
A || B
A= $args->{'user_key'}B= $self->user_key
ABresult
1X1
011
000
399 or return $self->set_error(
400 'API user key must be provided to create owned pastes.'
401 . ' See ->user_key() or ->get_user_key() in the'
402 . ' documentation.'
403 );
404  
405 push @out_args,
406 0 ▶ api_user_key => ( $args->{user_key} || $self->user_key );
Condition0%0/3
$args->{'user_key'} || $self->user_key
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'user_key'} || $self->user_key
$args->{'user_key'} $self->user_key
Truth table0%0/3
A || B
A= $args->{'user_key'}B= $self->user_key
ABresult
1X1
011
000
407 }
408  
409 1 ▶ if ( $args->{private} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args->{'private'}) { } 1 0 1
elsif ($args->{'unlisted'}) { } 0 0 0
410 1 ▶ defined ( $args->{user_key} || $self->user_key )
Branch: 1 branch
BranchTrueFalseTotal
defined($args->{"user_key"} || $self->user_key) or return $self->_set_error("API user key must be provided to create private pastes. See ->user_key() or ->get_user_key() in the documentation.") 0 1 1
Condition33%1/3
$args->{'user_key'} || $self->user_key
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{'user_key'} || $self->user_key
$args->{'user_key'} $self->user_key
Truth table33%1/3
A || B
A= $args->{'user_key'}B= $self->user_key
ABresult
1X1
011
000
411 or return $self->_set_error(
412 'API user key must be provided to create private pastes.'
413 . ' See ->user_key() or ->get_user_key() in the'
414 . ' documentation.'
415 );
416  
417 push @out_args,
418 api_paste_private => 2,
419 1 ▶ api_user_key => ( $args->{user_key} || $self->user_key );
Condition33%1/3
$args->{'user_key'} || $self->user_key
l!l&&r!l&&!r
010
MC/DC0%0/2
$args->{'user_key'} || $self->user_key
$args->{'user_key'} $self->user_key
Truth table33%1/3
A || B
A= $args->{'user_key'}B= $self->user_key
ABresult
1X1
011
000
420 }
421 elsif ( $args->{unlisted} ) {
422 0 push @out_args, api_paste_private => 1;
423 }
424 else {
425 ### DEBUGGING NOTE:
426 ### Pastebin will automatically list duplicate content
427 ### or content with "some" keywords as unlisted
428 ### even if we tell it to go public
429 0 push @out_args, api_paste_private => 0;
430 }
431  
432 1 ▶ if ( $args->{expiry} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"expiry"}) 1 0 1
433 my $expiry = $self->_translate_expiry( $args->{expiry} )
434 1 ▶ or return $self->_set_error('Invalid `expiry` argument');
Branch: 1 branch
BranchTrueFalseTotal
my $expiry = $self->_translate_expiry($args->{"expiry"}) or return $self->_set_error("Invalid `expiry` argument") 0 1 1
435  
436 1 push @out_args, api_paste_expire_date => $expiry;
437 }
438  
439 1 return @out_args;
440 }
441  
442 sub _translate_expiry {
443 1 ▶ my ( $self, $expiry ) = @_;
Subroutine _translate_expiry: called CC=2 SCAR=7.6
444  
445 1 my %expiries = (
446 # 10 Minutes
447 '10m' => '10M',
448 m10 => '10M',
449 asap => '10M',
450  
451 # 1 Hour
452 h => '1H',
453 '1h' => '1H',
454  
455 # 1 Day
456 d => '1D',
457 '1d' => '1D',
458 soon => '1D',
459  
460 # 1 Week
461 w => '1W',
462 '1w' => '1W',
463 awhile => '1W',
464  
465 '2w' => '2W',
466 w2 => '2W',
467  
468 # 1 Month
469 '1m' => '1M',
470 m1 => '1M',
471 eventually => '1M',
472  
473 # Never
474 n => 'N',
475 never => 'N',
476 );
477  
478 1 ▶ return $expiries{ lc $expiry }
Condition33%1/3
$expiries{lc $expiry} || $self->_set_error('Invalid expiry value')
l!l&&r!l&&!r
100
MC/DC0%0/2
$expiries{lc $expiry} || $self->_set_error('Invalid expiry value')
$expiries{lc $expiry} $self->_set_error('Invalid expiry value')
Truth table33%1/3
A || B
A= $expiries{lc $expiry}B= $self->_set_error('Invalid expiry value')
ABresult
1X1
011
000
479 || $self->_set_error('Invalid expiry value');
480 }
481  
482 sub _set_error {
483 0 ▶ my ( $self, $error ) = @_;
Subroutine _set_error: not called CC=1 SCAR=6.9
484 0 $self->error( $error );
485 0 return;
486 }
487  
488 sub _is_valid_format {
489 1 ▶ my ( $self, $format ) = @_;
Subroutine _is_valid_format: called CC=2 SCAR=7.6
490  
491 1 my %formats = (
492 '4cs' => '4CS',
493 '6502acme' => '6502 ACME Cross Assembler',
494 '6502kickass' => '6502 Kick Assembler',
495 '6502tasm' => '6502 TASM/64TASS',
496 'abap' => 'ABAP',
497 'actionscript' => 'ActionScript',
498 'actionscript3' => 'ActionScript 3',
499 'ada' => 'Ada',
500 'algol68' => 'ALGOL 68',
501 'apache' => 'Apache Log',
502 'applescript' => 'AppleScript',
503 'apt_sources' => 'APT Sources',
504 'arm' => 'ARM',
505 'asm' => 'ASM (NASM)',
506 'asp' => 'ASP',
507 'asymptote' => 'Asymptote',
508 'autoconf' => 'autoconf',
509 'autohotkey' => 'Autohotkey',
510 'autoit' => 'AutoIt',
511 'avisynth' => 'Avisynth',
512 'awk' => 'Awk',
513 'bascomavr' => 'BASCOM AVR',
514 'bash' => 'Bash',
515 'basic4gl' => 'Basic4GL',
516 'bibtex' => 'BibTeX',
517 'blitzbasic' => 'Blitz Basic',
518 'bnf' => 'BNF',
519 'boo' => 'BOO',
520 'bf' => 'BrainFuck',
521 'c' => 'C',
522 'c_mac' => 'C for Macs',
523 'cil' => 'C Intermediate Language',
524 'csharp' => 'C#',
525 'cpp' => 'C++',
526 'cpp-qt' => 'C++ (with QT extensions)',
527 'c_loadrunner' => 'C: Loadrunner',
528 'caddcl' => 'CAD DCL',
529 'cadlisp' => 'CAD Lisp',
530 'cfdg' => 'CFDG',
531 'chaiscript' => 'ChaiScript',
532 'clojure' => 'Clojure',
533 'klonec' => 'Clone C',
534 'klonecpp' => 'Clone C++',
535 'cmake' => 'CMake',
536 'cobol' => 'COBOL',
537 'coffeescript' => 'CoffeeScript',
538 'cfm' => 'ColdFusion',
539 'css' => 'CSS',
540 'cuesheet' => 'Cuesheet',
541 'd' => 'D',
542 'dcl' => 'DCL',
543 'dcpu16' => 'DCPU-16',
544 'dcs' => 'DCS',
545 'delphi' => 'Delphi',
546 'oxygene' => 'Delphi Prism (Oxygene)',
547 'diff' => 'Diff',
548 'div' => 'DIV',
549 'dos' => 'DOS',
550 'dot' => 'DOT',
551 'e' => 'E',
552 'ecmascript' => 'ECMAScript',
553 'eiffel' => 'Eiffel',
554 'email' => 'Email',
555 'epc' => 'EPC',
556 'erlang' => 'Erlang',
557 'fsharp' => 'F#',
558 'falcon' => 'Falcon',
559 'fo' => 'FO Language',
560 'f1' => 'Formula One',
561 'fortran' => 'Fortran',
562 'freebasic' => 'FreeBasic',
563 'freeswitch' => 'FreeSWITCH',
564 'gambas' => 'GAMBAS',
565 'gml' => 'Game Maker',
566 'gdb' => 'GDB',
567 'genero' => 'Genero',
568 'genie' => 'Genie',
569 'gettext' => 'GetText',
570 'go' => 'Go',
571 'groovy' => 'Groovy',
572 'gwbasic' => 'GwBasic',
573 'haskell' => 'Haskell',
574 'haxe' => 'Haxe',
575 'hicest' => 'HicEst',
576 'hq9plus' => 'HQ9 Plus',
577 'html4strict' => 'HTML',
578 'html5' => 'HTML 5',
579 'icon' => 'Icon',
580 'idl' => 'IDL',
581 'ini' => 'INI file',
582 'inno' => 'Inno Script',
583 'intercal' => 'INTERCAL',
584 'io' => 'IO',
585 'j' => 'J',
586 'java' => 'Java',
587 'java5' => 'Java 5',
588 'javascript' => 'JavaScript',
589 'jquery' => 'jQuery',
590 'kixtart' => 'KiXtart',
591 'latex' => 'Latex',
592 'ldif' => 'LDIF',
593 'lb' => 'Liberty BASIC',
594 'lsl2' => 'Linden Scripting',
595 'lisp' => 'Lisp',
596 'llvm' => 'LLVM',
597 'locobasic' => 'Loco Basic',
598 'logtalk' => 'Logtalk',
599 'lolcode' => 'LOL Code',
600 'lotusformulas' => 'Lotus Formulas',
601 'lotusscript' => 'Lotus Script',
602 'lscript' => 'LScript',
603 'lua' => 'Lua',
604 'm68k' => 'M68000 Assembler',
605 'magiksf' => 'MagikSF',
606 'make' => 'Make',
607 'mapbasic' => 'MapBasic',
608 'matlab' => 'MatLab',
609 'mirc' => 'mIRC',
610 'mmix' => 'MIX Assembler',
611 'modula2' => 'Modula 2',
612 'modula3' => 'Modula 3',
613 '68000devpac' => 'Motorola 68000 HiSoft Dev',
614 'mpasm' => 'MPASM',
615 'mxml' => 'MXML',
616 'mysql' => 'MySQL',
617 'nagios' => 'Nagios',
618 'newlisp' => 'newLISP',
619 'text' => 'None',
620 'nsis' => 'NullSoft Installer',
621 'oberon2' => 'Oberon 2',
622 'objeck' => 'Objeck Programming Langua',
623 'objc' => 'Objective C',
624 'ocaml-brief' => 'OCalm Brief',
625 'ocaml' => 'OCaml',
626 'octave' => 'Octave',
627 'pf' => 'OpenBSD PACKET FILTER',
628 'glsl' => 'OpenGL Shading',
629 'oobas' => 'Openoffice BASIC',
630 'oracle11' => 'Oracle 11',
631 'oracle8' => 'Oracle 8',
632 'oz' => 'Oz',
633 'parasail' => 'ParaSail',
634 'parigp' => 'PARI/GP',
635 'pascal' => 'Pascal',
636 'pawn' => 'PAWN',
637 'pcre' => 'PCRE',
638 'per' => 'Per',
639 'perl' => 'Perl',
640 'perl6' => 'Perl 6',
641 'php' => 'PHP',
642 'php-brief' => 'PHP Brief',
643 'pic16' => 'Pic 16',
644 'pike' => 'Pike',
645 'pixelbender' => 'Pixel Bender',
646 'plsql' => 'PL/SQL',
647 'postgresql' => 'PostgreSQL',
648 'povray' => 'POV-Ray',
649 'powershell' => 'Power Shell',
650 'powerbuilder' => 'PowerBuilder',
651 'proftpd' => 'ProFTPd',
652 'progress' => 'Progress',
653 'prolog' => 'Prolog',
654 'properties' => 'Properties',
655 'providex' => 'ProvideX',
656 'purebasic' => 'PureBasic',
657 'pycon' => 'PyCon',
658 'python' => 'Python',
659 'pys60' => 'Python for S60',
660 'q' => 'q/kdb+',
661 'qbasic' => 'QBasic',
662 'rsplus' => 'R',
663 'rails' => 'Rails',
664 'rebol' => 'REBOL',
665 'reg' => 'REG',
666 'rexx' => 'Rexx',
667 'robots' => 'Robots',
668 'rpmspec' => 'RPM Spec',
669 'ruby' => 'Ruby',
670 'gnuplot' => 'Ruby Gnuplot',
671 'sas' => 'SAS',
672 'scala' => 'Scala',
673 'scheme' => 'Scheme',
674 'scilab' => 'Scilab',
675 'sdlbasic' => 'SdlBasic',
676 'smalltalk' => 'Smalltalk',
677 'smarty' => 'Smarty',
678 'spark' => 'SPARK',
679 'sparql' => 'SPARQL',
680 'sql' => 'SQL',
681 'stonescript' => 'StoneScript',
682 'systemverilog' => 'SystemVerilog',
683 'tsql' => 'T-SQL',
684 'tcl' => 'TCL',
685 'teraterm' => 'Tera Term',
686 'thinbasic' => 'thinBasic',
687 'typoscript' => 'TypoScript',
688 'unicon' => 'Unicon',
689 'uscript' => 'UnrealScript',
690 'ups' => 'UPC',
691 'urbi' => 'Urbi',
692 'vala' => 'Vala',
693 'vbnet' => 'VB.NET',
694 'vedit' => 'Vedit',
695 'verilog' => 'VeriLog',
696 'vhdl' => 'VHDL',
697 'vim' => 'VIM',
698 'visualprolog' => 'Visual Pro Log',
699 'vb' => 'VisualBasic',
700 'visualfoxpro' => 'VisualFoxPro',
701 'whitespace' => 'WhiteSpace',
702 'whois' => 'WHOIS',
703 'winbatch' => 'Winbatch',
704 'xbasic' => 'XBasic',
705 'xml' => 'XML',
706 'xorg_conf' => 'Xorg Config',
707 'xpp' => 'XPP',
708 'yaml' => 'YAML',
709 'z80' => 'Z80 Assembler',
710 'zxbasic' => 'ZXBasic',
711 );
712  
713 1 ▶ return $formats{ $format }
Condition33%1/3
$formats{$format} || $self->_set_error('Invalid syntax highlighting code')
l!l&&r!l&&!r
100
MC/DC0%0/2
$formats{$format} || $self->_set_error('Invalid syntax highlighting code')
$formats{$format} $self->_set_error('Invalid syntax highlighting code')
Truth table33%1/3
A || B
A= $formats{$format}B= $self->_set_error('Invalid syntax highlighting code')
ABresult
1X1
011
000
714 || $self->_set_error('Invalid syntax highlighting code');
715 }
716  
717 3 1;
718  
719 __END__
↑ Summary