line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Shorten::0rz; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
97752
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
71
|
|
4
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
56
|
|
5
|
3
|
|
|
3
|
|
8
|
use Carp (); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
29
|
|
6
|
3
|
|
|
3
|
|
1412
|
use Mojo::DOM58 (); |
|
3
|
|
|
|
|
55329
|
|
|
3
|
|
|
|
|
65
|
|
7
|
3
|
|
|
3
|
|
1374
|
use Try::Tiny qw(try catch); |
|
3
|
|
|
|
|
4517
|
|
|
3
|
|
|
|
|
227
|
|
8
|
3
|
|
|
3
|
|
1898
|
use WWW::Mechanize (); |
|
3
|
|
|
|
|
257994
|
|
|
3
|
|
|
|
|
88
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
22
|
use base qw( WWW::Shorten::generic Exporter ); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1261
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw( makeashorterlink makealongerlink ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $_error_message = ''; |
14
|
|
|
|
|
|
|
our $VERSION = '0.072'; |
15
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub makeashorterlink { |
18
|
2
|
50
|
|
2
|
1
|
38
|
my $url = shift or Carp::croak("No URL passed to makeashorterlink"); |
19
|
2
|
|
|
|
|
3
|
$_error_message = ''; |
20
|
|
|
|
|
|
|
return try { |
21
|
2
|
|
|
2
|
|
137
|
my $mech = WWW::Mechanize->new; |
22
|
2
|
|
|
|
|
19745
|
$mech->add_header('Accept' => 'text/html'); |
23
|
2
|
|
|
|
|
24
|
$mech->get('http://0rz.tw/create'); |
24
|
2
|
|
|
|
|
3228138
|
$mech->submit_form( |
25
|
|
|
|
|
|
|
form_id => 'redirect-form', |
26
|
|
|
|
|
|
|
fields => {url => $url,}, |
27
|
|
|
|
|
|
|
); |
28
|
2
|
50
|
|
|
|
2754705
|
return undef unless $mech->response->is_success; |
29
|
2
|
|
|
|
|
26
|
my $dom = Mojo::DOM58->new($mech->response->decoded_content); |
30
|
2
|
|
|
|
|
25240
|
return $dom->find('div#doneurl > a')->last->attr('href'); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
catch { |
33
|
1
|
|
|
1
|
|
3445
|
$_error_message = $_; |
34
|
1
|
|
|
|
|
8
|
return undef; |
35
|
2
|
|
|
|
|
16
|
}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub makealongerlink { |
39
|
1
|
50
|
|
1
|
1
|
3122
|
my $url = shift or Carp::croak('No URL passed to makealongerlink'); |
40
|
1
|
|
|
|
|
2
|
$_error_message = ''; |
41
|
1
|
|
|
|
|
12
|
my $ua = __PACKAGE__->ua(); |
42
|
1
|
50
|
|
|
|
286
|
$url = "http://0rz.tw/$url" unless $url =~ m!^http://!i; |
43
|
1
|
|
|
|
|
4
|
my $resp = $ua->get($url); |
44
|
1
|
50
|
|
|
|
538215
|
unless ($resp->is_redirect) { |
45
|
0
|
|
|
|
|
0
|
my $content = $resp->content; |
46
|
0
|
0
|
|
|
|
0
|
if ($content =~ /Error/) { |
47
|
0
|
0
|
|
|
|
0
|
if ($content =~ /
|
|
|
0
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
$_error_message = 'Error is a html page'; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif (length($content) > 100) { |
51
|
0
|
|
|
|
|
0
|
$_error_message = substr($content, 0, 100); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
0
|
$_error_message = $content; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
0
|
$_error_message = 'Unknown error'; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
return undef; |
62
|
|
|
|
|
|
|
} |
63
|
1
|
|
|
|
|
11
|
my $long = $resp->header('Location'); |
64
|
1
|
|
|
|
|
32
|
return $long; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |