File Coverage

blib/lib/App/Nopaste/Service/PastebinComAPI.pm
Criterion Covered Total %
statement 12 27 44.4
branch 0 12 0.0
condition 0 9 0.0
subroutine 4 6 66.6
pod 1 2 50.0
total 17 56 30.3


line stmt bran cond sub pod time code
1             package App::Nopaste::Service::PastebinComAPI;
2              
3 1     1   34416 use 5.006;
  1         4  
  1         42  
4 1     1   8 use strict;
  1         2  
  1         47  
5 1     1   6 use warnings FATAL => 'all';
  1         8  
  1         57  
6 1     1   6 use base 'App::Nopaste::Service';
  1         2  
  1         974  
7              
8             our $VERSION = '1.002';
9              
10             sub available {
11 0     0 0   eval 'require WWW::Pastebin::PastebinCom::API; 1';
12             }
13             sub run {
14 0     0 1   my $self = shift;
15 0           my %args = @_;
16              
17 0           my ( $api_key, $user_key ) = @ENV{qw/
18             APP_NOPASTE_PASTEBINCOM_API_KEY
19             APP_NOPASTE_PASTEBINCOM_USER_KEY
20             /};
21              
22 0 0 0       unless ( defined $api_key and length $api_key
      0        
      0        
23             and defined $user_key and length $user_key
24             ) {
25 0           return (0,'You must specify the pastebin.com API keys'
26             . ' using the APP_NOPASTE_PASTEBINCOM_API_KEY and'
27             . ' APP_NOPASTE_PASTEBINCOM_USER_KEY environmental'
28             . ' variables! To generate your user key, run this piece of'
29             . ' code: '
30             . q{perl -MWWW::Pastebin::PastebinCom::API -wle "print }
31             . q{WWW::Pastebin::PastebinCom::API->new( api_key => }
32             . q{ q|YOUR_API_KEY_HERE|)->get_user_key(qw/ }
33             . q{YOUR_PASTEBIN_LOGIN_HERE YOUR_PASTEBIN_PASSWORD_HERE/);"}
34             );
35             }
36              
37 0           require WWW::Pastebin::PastebinCom::API;
38              
39 0           my $bin = WWW::Pastebin::PastebinCom::API->new(
40             api_key => $api_key,
41             user_key => $user_key,
42             );
43              
44 0 0         delete $args{nick} if defined $args{nick};
45 0 0         $args{title} = delete $args{desc} if defined $args{desc};
46 0 0         $args{format} = delete $args{lang} if defined $args{lang};
47 0 0         $args{unlisted} = 1 unless $args{private};
48              
49 0           my $ok = $bin->paste(
50             delete($args{text}),
51             expiry => 'm1',
52             %args,
53             );
54              
55 0 0         return (0, $bin->error) unless $ok;
56 0           return (1, $bin->paste_url);
57             }
58              
59              
60              
61             q|
62             Q: How many programmers does it take to change a light bulb?
63             A: None. It's a hardware problem.
64             |;
65              
66             __END__