| 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.001006'; # 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 | 3 | ▶ | use overload q|""| => sub { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 22 | 3 | my $obj = shift; | |||||||||||||||||||||||||||
| 23 | 3 | ▶ | defined $obj->error ? 'Error: ' . $obj->error : $obj->paste_url | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 3 | }; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 28 | 1 | ▶ | croak 'Must have even number of arguments to the constructor' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 35 | 0 | $args{timeout} = 30; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 1 | ▶ | unless ( $args{ua} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub get_user_info { | ||||||||||||||||||||||||||
|
Subroutine
get_user_info: called CC=6 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 1 | $self->error( undef ); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | ▶ | my $api_key = $self->_get_api_key | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | or return $self->_set_error(q|Missing API key|); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $user_key = $self->_get_user_key | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | or return $self->_set_error( | ||||||||||||||||||||||||||||
| 62 | q|Missing USER key. See ->get_user_key() method| | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | my $response = $self->_ua->post( | |||||||||||||||||||||||||||
| 66 | 'https://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 | 0 | ▶ | if ( $response->is_success or $response->is_redirect ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response->is_success or $response->is_redirect
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
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return $self->_set_error( $response->content ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | if $response->content =~ /^Bad API request/; | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | return $self->_parse_user_xml( $response->content ); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||||||||
| 81 | 0 | $self->error( $response->status_line ); | |||||||||||||||||||||||||||
| 82 | 0 | return; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub list_user_pastes { | ||||||||||||||||||||||||||
|
Subroutine
list_user_pastes: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $limit = shift || 50; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 50
MC/DC0%0/1
shift() || 50
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | $limit = 1 if $limit < 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $limit = 1000 if $limit > 1000; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | $self->error( undef ); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my $api_key = $self->_get_api_key | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | or return $self->_set_error(q|Missing API key|); | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my $user_key = $self->_get_user_key | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 'https://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
Condition0%0/3
$response->is_success or $response->is_redirect
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
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return $self->_set_error( $response->content ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | if $response->content =~ /^Bad API request/; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | return [] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub list_trends { | ||||||||||||||||||||||||||
|
Subroutine
list_trends: called CC=5 SCAR=28.2
Pod
documented
| |||||||||||||||||||||||||||||
| 128 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 1 | $self->error( undef ); | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 1 | ▶ | my $api_key = $self->_get_api_key | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | or return $self->_set_error(q|Missing API key|); | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | my $response = $self->_ua->post( | |||||||||||||||||||||||||||
| 136 | 'https://pastebin.com/api/api_post.php', | ||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||
| 138 | api_dev_key => $api_key, | ||||||||||||||||||||||||||||
| 139 | api_option => 'trends', | ||||||||||||||||||||||||||||
| 140 | }, | ||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ( $response->is_success or $response->is_redirect ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response->is_success or $response->is_redirect
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
| |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | return $self->_set_error( $response->content ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | if $response->content =~ /^Bad API request/; | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | return $self->_parse_xml( $response->content ); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | else { | ||||||||||||||||||||||||||||
| 150 | 0 | $self->error( $response->status_line ); | |||||||||||||||||||||||||||
| 151 | 0 | return; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub delete_paste { | ||||||||||||||||||||||||||
|
Subroutine
delete_paste: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 156 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $paste_key and length $paste_key
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 167 | or return $self->_set_error(q|Missing API key|); | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | my $user_key = $self->_get_user_key | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 'https://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
Condition0%0/3
$response->is_success or $response->is_redirect
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
| |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | return $self->_set_error( $response->content ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 2 | ▶ | sub get_paste { | ||||||||||||||||||||||||||
|
Subroutine
get_paste: called CC=11 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $paste_key and length $paste_key
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
| |||||||||||||||||||||||||||||
| 208 | or return $self->_set_error('Missing paste ID or URL'); | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 2 | ▶ | if ( defined $login and defined $pass ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $login and defined $pass
MC/DC0%0/2
defined $login and defined $pass
defined $login
defined $pass
Truth table33%1/3
A and B
A= defined $loginB= defined $pass
| |||||||||||||||||||||||||||||
| 211 | 0 | $self->_ua->cookie_jar( HTTP::Cookies->new ); | |||||||||||||||||||||||||||
| 212 | 0 | $self->_ua->post( | |||||||||||||||||||||||||||
| 213 | 'https://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 | "https://pastebin.com/raw/$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
Condition33%1/3
$response->is_success or $response->is_redirect
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
| |||||||||||||||||||||||||||||
| 229 | 2 | ▶ | return $self->_set_error(q|This paste doesn't exist|) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $response->content and length $response->content
MC/DC0%0/2
defined $response->content and length $response->content
defined $response->content
length $response->content
Truth table33%1/3
A and B
A= defined $response->contentB= length $response->content
| |||||||||||||||||||||||||||||
| 230 | unless defined $response->content | ||||||||||||||||||||||||||||
| 231 | and length $response->content; | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 2 | ▶ | return $self->_set_error( $response->content ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 2 | return $response->content; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | else { | ||||||||||||||||||||||||||||
| 241 | 0 | ▶ | if ( $response->status_line eq '404 Not Found' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | 0 | $self->error(q|This paste doesn't exist|); | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | else { | ||||||||||||||||||||||||||||
| 245 | 0 | $self->error( 'Network error: ' . $response->status_line ); | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | 0 | return; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub paste { | ||||||||||||||||||||||||||
|
Subroutine
paste: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 252 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 253 | 0 | my $paste_text = shift; | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 0 | $self->error( undef ); | |||||||||||||||||||||||||||
| 256 | 0 | $self->paste_url( undef ); | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 0 | ▶ | defined $paste_text and length $paste_text | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $paste_text and length $paste_text
MC/DC0%0/2
defined $paste_text and length $paste_text
defined $paste_text
length $paste_text
Truth table0%0/3
A and B
A= defined $paste_textB= length $paste_text
| |||||||||||||||||||||||||||||
| 259 | or return $self->_set_error('Paste text is empty'); | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 262 | 0 | $args{ +lc } = delete $args{ $_ } for keys %args; | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 0 | ▶ | my @args = $self->_prepare_optional_api_options( \%args ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | or return; | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 0 | ▶ | my $api_key = $self->_get_api_key | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | or return $self->_set_error(q|Missing API key|); | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | my $response = $self->_ua->post( | |||||||||||||||||||||||||||
| 271 | 'https://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 | 0 | ▶ | if ( $response->is_success or $response->is_redirect ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response->is_success or $response->is_redirect
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
| |||||||||||||||||||||||||||||
| 283 | 0 | ▶ | return $self->_set_error( $response->content ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | if $response->content =~ /^Bad API request|^Post limit, maximum pastes/; | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 0 | return $self->paste_url( $response->content ); | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | else { | ||||||||||||||||||||||||||||
| 289 | 0 | $self->error( $response->status_line ); | |||||||||||||||||||||||||||
| 290 | 0 | return; | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 1 | ▶ | sub get_user_key { | ||||||||||||||||||||||||||
|
Subroutine
get_user_key: called CC=5 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||
| 295 | 1 | my ( $self, $login, $pass ) = @_; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 301 | or return $self->_set_error(q|Missing API key|); | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 0 | my $response = $self->_ua->post( | |||||||||||||||||||||||||||
| 304 | 'https://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 | 0 | ▶ | if ( $response->is_success or $response->is_redirect ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response->is_success or $response->is_redirect
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
| |||||||||||||||||||||||||||||
| 313 | 0 | ▶ | return $self->_set_error( $response->content ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 314 | if $response->content =~ /^Bad API request/; | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 0 | return $self->user_key( $response->content ); | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | else { | ||||||||||||||||||||||||||||
| 319 | 0 | $self->error( $response->status_line ); | |||||||||||||||||||||||||||
| 320 | 0 | return; | |||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | ▶ | sub _parse_user_xml { | ||||||||||||||||||||||||||
|
Subroutine
_parse_user_xml: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 325 | 0 | my ( $self, $content ) = @_; | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | $content =~ s{<user>\s*(.+)\s*</user>}{$1}gs; | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 0 | my %user = $content =~ ( m{<([^>]+)>(.*?)</\1>}sg ); | |||||||||||||||||||||||||||
| 330 | 0 | $user{ substr $_, 5 } = delete $user{ $_ } for keys %user; | |||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ( $user{private} == 2 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 332 | 0 | $user{private} = 1 | |||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | elsif ( $user{private} == 1 ) { | ||||||||||||||||||||||||||||
| 335 | 0 | $user{unlisted} = 1; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | else { | ||||||||||||||||||||||||||||
| 338 | 0 | delete $user{private}; | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 0 | ▶ | return wantarray ? %user : \%user; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 0 | ▶ | sub _parse_xml { | ||||||||||||||||||||||||||
|
Subroutine
_parse_xml: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 345 | 0 | my ( $self, $content ) = @_; | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 0 | my @out; | |||||||||||||||||||||||||||
| 348 | 0 | 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
| |||||||||||||||||||||||||||||
| 354 | 0 | elsif ( $private_flag == 1 ) { $paste{unlisted} = 1; } | |||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 0 | push @out, \%paste; | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | ▶ | return wantarray ? @out : \@out; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 0 | ▶ | sub _get_user_key { | ||||||||||||||||||||||||||
|
Subroutine
_get_user_key: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 363 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 0 | ▶ | return $self->user_key | ||||||||||||||||||||||||||
|
Condition0%0/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.'))
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 table0%0/2
A
A= $self->user_key
| |||||||||||||||||||||||||||||
| 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 | 3 | ▶ | sub _get_api_key { | ||||||||||||||||||||||||||
|
Subroutine
_get_api_key: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 372 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 3 | ▶ | 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")]))
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
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _prepare_optional_api_options { | ||||||||||||||||||||||||||
|
Subroutine
_prepare_optional_api_options: not called CC=16 SCAR=56.1
| |||||||||||||||||||||||||||||
| 382 | 0 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 383 | 0 | my @out_args; | |||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | push @out_args, api_paste_name => $args->{title} | ||||||||||||||||||||||||||||
| 386 | 0 | ▶ | if defined $args->{title}; # title of the paste | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if ( defined $args->{format} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 389 | $self->_is_valid_format( $args->{format} ) | ||||||||||||||||||||||||||||
| 390 | 0 | ▶ | or return $self->_set_error( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 391 | 'Invalid syntax highlighting code. See ->valid_formats()' | ||||||||||||||||||||||||||||
| 392 | . ' method in the documentation' | ||||||||||||||||||||||||||||
| 393 | ); | ||||||||||||||||||||||||||||
| 394 | 0 | push @out_args, api_paste_format => $args->{format}; | |||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if( $args->{owned} and not $args->{private} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{"owned"} and not $args->{"private"}
MC/DC0%0/2
$args->{"owned"} and not $args->{"private"}
$args->{"owned"}
not $args->{"private"}
Truth table0%0/3
A and not(B)
A= $args->{"owned"}B= not $args->{"private"}
| |||||||||||||||||||||||||||||
| 398 | 0 | ▶ | defined ( $args->{user_key} || $self->user_key ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{'user_key'} || $self->user_key
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
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | 0 | ▶ | if ( $args->{private} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 410 | 0 | ▶ | defined ( $args->{user_key} || $self->user_key ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{'user_key'} || $self->user_key
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
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | api_user_key => ( $args->{user_key} || $self->user_key ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args->{'user_key'} || $self->user_key
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
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | if ( $args->{expiry} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 433 | my $expiry = $self->_translate_expiry( $args->{expiry} ) | ||||||||||||||||||||||||||||
| 434 | 0 | ▶ | or return $self->_set_error('Invalid `expiry` argument'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 0 | push @out_args, api_paste_expire_date => $expiry; | |||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 0 | return @out_args; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | 0 | ▶ | sub _translate_expiry { | ||||||||||||||||||||||||||
|
Subroutine
_translate_expiry: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 443 | 0 | my ( $self, $expiry ) = @_; | |||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | 0 | 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 | 0 | ▶ | return $expiries{ lc $expiry } | ||||||||||||||||||||||||||
|
Condition0%0/3
$expiries{lc $expiry} || $self->_set_error('Invalid expiry value')
MC/DC0%0/2
$expiries{lc $expiry} || $self->_set_error('Invalid expiry value')
$expiries{lc $expiry}
$self->_set_error('Invalid expiry value')
Truth table0%0/3
A || B
A= $expiries{lc $expiry}B= $self->_set_error('Invalid expiry value')
| |||||||||||||||||||||||||||||
| 479 | || $self->_set_error('Invalid expiry value'); | ||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | 6 | ▶ | sub _set_error { | ||||||||||||||||||||||||||
|
Subroutine
_set_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 483 | 6 | my ( $self, $error ) = @_; | |||||||||||||||||||||||||||
| 484 | 6 | $self->error( $error ); | |||||||||||||||||||||||||||
| 485 | 6 | return; | |||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | 0 | ▶ | sub _is_valid_format { | ||||||||||||||||||||||||||
|
Subroutine
_is_valid_format: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 489 | 0 | my ( $self, $format ) = @_; | |||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | 0 | 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 | 0 | ▶ | return $formats{ $format } | ||||||||||||||||||||||||||
|
Condition0%0/3
$formats{$format} || $self->_set_error('Invalid syntax highlighting code')
MC/DC0%0/2
$formats{$format} || $self->_set_error('Invalid syntax highlighting code')
$formats{$format}
$self->_set_error('Invalid syntax highlighting code')
Truth table0%0/3
A || B
A= $formats{$format}B= $self->_set_error('Invalid syntax highlighting code')
| |||||||||||||||||||||||||||||
| 714 | || $self->_set_error('Invalid syntax highlighting code'); | ||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | 3 | 1; | |||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||
| 719 | __END__ | ||||||||||||||||||||||||||||