line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::RU::OpenCorpora::Tokenizer::Updater; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5634
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3899
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
148256
|
|
|
1
|
|
|
|
|
45
|
|
7
|
1
|
|
|
1
|
|
14
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
107
|
|
8
|
1
|
|
|
1
|
|
6
|
use Lingua::RU::OpenCorpora::Tokenizer::List; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
9
|
1
|
|
|
1
|
|
6
|
use Lingua::RU::OpenCorpora::Tokenizer::Vectors; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
890
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.06; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $self = bless {@_}, $class; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
$self->_init; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
$self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
0
|
0
|
|
sub vectors_update_available { $_[0]->_update_available('vectors', $_[1]) } |
24
|
0
|
|
|
0
|
0
|
|
sub hyphens_update_available { $_[0]->_update_available('hyphens', $_[1]) } |
25
|
0
|
|
|
0
|
0
|
|
sub exceptions_update_available { $_[0]->_update_available('exceptions', $_[1]) } |
26
|
0
|
|
|
0
|
0
|
|
sub prefixes_update_available { $_[0]->_update_available('prefixes', $_[1]) } |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
0
|
0
|
|
sub update_vectors { $_[0]->_update('vectors') } |
29
|
0
|
|
|
0
|
0
|
|
sub update_hyphens { $_[0]->_update('hyphens') } |
30
|
0
|
|
|
0
|
0
|
|
sub update_exceptions { $_[0]->_update('exceptions') } |
31
|
0
|
|
|
0
|
0
|
|
sub update_prefixes { $_[0]->_update('prefixes') } |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _init { |
34
|
0
|
|
|
0
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new( |
37
|
|
|
|
|
|
|
agent => __PACKAGE__ . ' ' . $VERSION . ', ', |
38
|
|
|
|
|
|
|
env_proxy => 1, |
39
|
|
|
|
|
|
|
); |
40
|
0
|
|
|
|
|
|
$self->{ua} = $ua; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
for(qw(exceptions prefixes hyphens)) { |
43
|
0
|
|
|
|
|
|
$self->{$_} = Lingua::RU::OpenCorpora::Tokenizer::List->new($_); |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
$self->{vectors} = Lingua::RU::OpenCorpora::Tokenizer::Vectors->new; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _update_available { |
51
|
0
|
|
|
0
|
|
|
my($self, $mode, $force) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $url = $self->{$mode}->_url('version'); |
54
|
0
|
|
|
|
|
|
my $res = $self->{ua}->get($url); |
55
|
0
|
0
|
|
|
|
|
croak "$url: " . $res->code unless $res->is_success; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
chomp(my $latest = $res->content); |
58
|
0
|
|
|
|
|
|
my $current = $self->{$mode}->{version}; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$self->{"${mode}_latest"} = $latest; |
61
|
0
|
|
|
|
|
|
$self->{"${mode}_current"} = $current; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
return $force |
64
|
|
|
|
|
|
|
? 1 |
65
|
|
|
|
|
|
|
: $latest > $current; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _update { |
69
|
0
|
|
|
0
|
|
|
my($self, $mode) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $url = $self->{$mode}->_url('file'); |
72
|
0
|
|
|
|
|
|
my $res = $self->{ua}->get($url); |
73
|
0
|
0
|
|
|
|
|
croak "$url: " . $res->code unless $res->is_success; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$self->{$mode}->_update($res->content); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |