line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::YAUID; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1275
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
37
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
5
|
1
|
|
|
1
|
|
6
|
use vars qw($AUTOLOAD $VERSION $ABSTRACT @ISA @EXPORT); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
161
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
1
|
|
|
1
|
|
2
|
$VERSION = 1.50; |
9
|
1
|
|
|
|
|
2
|
$ABSTRACT = "A decentralized unique ID generator (int64)"; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
14
|
@ISA = qw(Exporter DynaLoader); |
12
|
1
|
|
|
|
|
92
|
@EXPORT = qw( |
13
|
|
|
|
|
|
|
get_error_text_by_code |
14
|
|
|
|
|
|
|
get_max_inc get_max_node_id get_max_timestamp |
15
|
|
|
|
|
|
|
timestamp_to_datetime |
16
|
|
|
|
|
|
|
get_period_key_by_timestamp get_period_key_by_datetime |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
bootstrap Number::YAUID $VERSION; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
9
|
use DynaLoader (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
23
|
1
|
|
|
1
|
|
6
|
use Exporter (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
431
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %opt = ( |
26
|
|
|
|
|
|
|
try_count => 0, |
27
|
|
|
|
|
|
|
sleep_usec => 35000, |
28
|
|
|
|
|
|
|
node_id => 0 |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
1
|
|
|
1
|
1
|
11
|
my ($class, $fuid_lock, $fnode_id) = |
33
|
|
|
|
|
|
|
(shift, shift, shift); |
34
|
1
|
|
|
|
|
6
|
my %args = ( |
35
|
|
|
|
|
|
|
%opt, |
36
|
|
|
|
|
|
|
@_ |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
3
|
my $node_id = delete $args{node_id}; |
40
|
1
|
|
|
|
|
146
|
my $self = $class->init($fuid_lock, $fnode_id); |
41
|
|
|
|
|
|
|
|
42
|
1
|
50
|
|
|
|
4
|
if(ref $self) |
43
|
|
|
|
|
|
|
{ |
44
|
1
|
50
|
|
|
|
10
|
if(my $error = $self->get_error_code()) |
45
|
|
|
|
|
|
|
{ |
46
|
0
|
|
|
|
|
0
|
undef $self; |
47
|
0
|
|
|
|
|
0
|
return $error; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
3
|
foreach my $pname (keys %args) |
51
|
|
|
|
|
|
|
{ |
52
|
2
|
|
|
|
|
5
|
my $sub_name = "set_$pname"; |
53
|
2
|
50
|
|
|
|
18
|
$self->$sub_name($args{$pname}) if exists $args{$pname}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1
|
50
|
33
|
|
|
8
|
unless($fnode_id || !ref $self) |
57
|
|
|
|
|
|
|
{ |
58
|
1
|
|
|
|
|
15
|
$self->set_node_id($node_id); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
0
|
|
|
|
|
0
|
return YAUID_ERROR_CREATE_OBJECT(); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
4
|
$self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub timestamp_to_datetime { |
69
|
0
|
|
0
|
0
|
1
|
|
my @parts = (localtime( $_[0] || time ))[0..5]; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$parts[4] += 1; |
72
|
0
|
|
|
|
|
|
$parts[5] += 1900; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
sprintf("%04d-%02d-%02d %02d:%02d:%02d", reverse @parts); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |