line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::YAUID; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1704
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
26
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
4
|
use vars qw($AUTOLOAD $VERSION $ABSTRACT @ISA @EXPORT); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
121
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
1
|
|
|
1
|
|
1
|
$VERSION = 1.40; |
9
|
1
|
|
|
|
|
2
|
$ABSTRACT = "A decentralized unique ID generator (int64)"; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
17
|
@ISA = qw(Exporter DynaLoader); |
12
|
1
|
|
|
|
|
32
|
@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
|
|
4
|
use DynaLoader (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
23
|
1
|
|
|
1
|
|
4
|
use Exporter (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
300
|
|
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
|
13
|
my ($class, $fuid_lock, $fnode_id) = |
33
|
|
|
|
|
|
|
(shift, shift, shift); |
34
|
1
|
|
|
|
|
9
|
my %args = ( |
35
|
|
|
|
|
|
|
%opt, |
36
|
|
|
|
|
|
|
@_ |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
3
|
my $node_id = delete $args{node_id}; |
40
|
1
|
|
|
|
|
232
|
my $self = $class->init($fuid_lock, $fnode_id); |
41
|
|
|
|
|
|
|
|
42
|
1
|
50
|
|
|
|
7
|
if(ref $self) |
43
|
|
|
|
|
|
|
{ |
44
|
1
|
50
|
|
|
|
12
|
if(my $error = $self->get_error_code()) |
45
|
|
|
|
|
|
|
{ |
46
|
0
|
|
|
|
|
0
|
undef $self; |
47
|
0
|
|
|
|
|
0
|
return $error; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
4
|
foreach my $pname (keys %args) |
51
|
|
|
|
|
|
|
{ |
52
|
2
|
|
|
|
|
5
|
my $sub_name = "set_$pname"; |
53
|
2
|
50
|
|
|
|
24
|
$self->$sub_name($args{$pname}) if exists $args{$pname}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1
|
50
|
33
|
|
|
12
|
unless($fnode_id || !ref $self) |
57
|
|
|
|
|
|
|
{ |
58
|
1
|
|
|
|
|
4
|
$self->set_node_id($node_id); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
0
|
|
|
|
|
0
|
return YAUID_ERROR_CREATE_OBJECT(); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
5
|
$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__ |