line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Yandex::BarTIC; |
2
|
2
|
|
|
2
|
|
120982
|
use 5.006; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
71
|
|
3
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
57
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
105
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
10
|
use base 'Object::Accessor'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2119
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
31857
|
use base 'Exporter'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
182
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(get_tic); |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
1133
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
55384
|
|
|
2
|
|
|
|
|
66
|
|
13
|
2
|
|
|
2
|
|
19
|
use URI::Escape; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
186
|
|
14
|
2
|
|
|
2
|
|
14
|
use Carp qw/carp croak/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1043
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Defaults |
17
|
|
|
|
|
|
|
my $DEF_URL_TEMPLATE = 'http://bar-navig.yandex.ru/u?url=%s&show=1'; |
18
|
|
|
|
|
|
|
my $DEF_UA_AGENT = 'Mozilla/5.0 (Ubuntu; X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 YB/6.5.0-en'; |
19
|
|
|
|
|
|
|
my $TIC_RE = qr##; |
20
|
|
|
|
|
|
|
my @ATTRS = qw/ua url_template/; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
1
|
|
|
1
|
1
|
16
|
my ($class, %args) = @_; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
15
|
my $self = $class->SUPER::new(@ATTRS); |
26
|
1
|
|
33
|
|
|
82
|
$self->ua($args{ua} || LWP::UserAgent->new(agent => $DEF_UA_AGENT)); |
27
|
1
|
|
|
|
|
5395
|
$self->url_template($DEF_URL_TEMPLATE); |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
110
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get { |
34
|
1
|
|
|
1
|
1
|
2924
|
my ($self, $url) = @_; |
35
|
|
|
|
|
|
|
|
36
|
1
|
50
|
|
|
|
6
|
croak 'I am waiting for url param' unless defined $url; |
37
|
1
|
50
|
|
|
|
9
|
unless ($url =~ m[^https?://]i) { |
38
|
1
|
|
|
|
|
1142
|
carp 'use "http://some.domain" format for url'; |
39
|
1
|
|
|
|
|
3630
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $query = sprintf($self->url_template, uri_escape($url)); |
43
|
0
|
|
|
|
|
|
my $resp = $self->ua->get($query); |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
0
|
|
|
|
if ($resp->is_success and $resp->content =~ $TIC_RE) { |
46
|
0
|
0
|
|
|
|
|
return wantarray ? ($1, $resp) : $1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
0
|
0
|
|
|
|
|
return wantarray ? (undef, $resp) : undef; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get_tic { |
55
|
0
|
|
|
0
|
1
|
|
my ($url) = @_; |
56
|
0
|
|
|
|
|
|
return __PACKAGE__->new()->get($url); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 NAME |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
WWW::Yandex::BarTIC - Query Yandex citation index (Яндекс ТИЦ in russian) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 VERSION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Version 0.04 |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SYNOPSIS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use WWW::Yandex::BarTIC 'get_tic'; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# OO Style |
76
|
|
|
|
|
|
|
my $yb = WWW::Yandex::BarTIC->new(); |
77
|
|
|
|
|
|
|
my ($tic, $resp) = $yb->get('http://cpan.org'); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Function |
80
|
|
|
|
|
|
|
my ($tic, $resp) = get_tic('http://cpan.org'); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 DESCRIPTION |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The C is a class implementing a interface for |
87
|
|
|
|
|
|
|
querying yandex citation index. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
It uses L for making request to Yandex. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 FUNCTIONS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 C |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
You can use C function, but you must import it before |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
use WWW::Yandex::BarTIC 'get_tic'; |
98
|
|
|
|
|
|
|
my ($tic, $resp) = get_tic('http://mail.ru'); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
See L"get"> method for description |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 METHODS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
C implements the following methods. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 C |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $yb = WWW::Yandex::BarTIC->new; |
109
|
|
|
|
|
|
|
my $yb = WWW::Yandex::BarTIC->new(ua => LWP::UserAgent->new); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Creates a new object. If C attribute is empty, it will be created automatically with following defaults: |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
KEY DEFAULT |
114
|
|
|
|
|
|
|
----------- -------------------- |
115
|
|
|
|
|
|
|
agent "Mozilla/5.0 (Ubuntu; X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 YB/6.5.0-en" |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 C |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my ($tic, $resp) = $yb->get('http://cpan.org'); |
121
|
|
|
|
|
|
|
my $tic = $yb->get('http://cpan.org'); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Queries Yandex for a specified URL and returns TIC. If |
124
|
|
|
|
|
|
|
query successfull, integer value > 0 returned. If query fails |
125
|
|
|
|
|
|
|
for some reason (yandex unreachable, url does not begin from |
126
|
|
|
|
|
|
|
'http://', undefined url passed) it returns C. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
In list context this function returns list from two elements where |
129
|
|
|
|
|
|
|
first is the result as in scalar context and the second is the |
130
|
|
|
|
|
|
|
C object (returned by C). This |
131
|
|
|
|
|
|
|
can be usefull for debugging purposes and for querying failure |
132
|
|
|
|
|
|
|
details. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 C |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$yb->ua(LWP::UserAgent->new); |
140
|
|
|
|
|
|
|
$yb->ua->agent('MyAgent'); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Get/Set L object for making request to Yandex |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHOR |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Alex, C<< >> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 BUGS |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
151
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
152
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SUPPORT |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
perldoc WWW::Yandex::BarTIC |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
You can also look for information at: |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=over 4 |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * CPAN Ratings |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * Search CPAN |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Copyright 2012 Alex. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
195
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
196
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; # End of WWW::Yandex::BarTIC |