blib/lib/Number/YAUID.pm

filter: Statementstmt 82.9% 34 / 41 Branchbran 50.0% 4 / 8 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 87.5% 7 / 8 Podpod 100% 2 / 2 totaltotal 71.6% 48 / 67 CC 8 SCAR 16.9
CC
8
Cov
72%
new
9.0
timestamp_to_datetime
6.0
BEGIN
1.0
CRAP 5.4
↑ Summary YAUID.xs »
1 package Number::YAUID;
2  
3 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw($AUTOLOAD $VERSION $ABSTRACT @ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $VERSION = 1.50;
9 1 $ABSTRACT = "A decentralized unique ID generator (int64)";
10
11 1 @ISA = qw(Exporter DynaLoader);
12 1 @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 1 bootstrap Number::YAUID $VERSION;
21  
22 1 ▶use DynaLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 my %opt = (
26 try_count => 0,
27 sleep_usec => 35000,
28 node_id => 0
29 );
30  
31 1 ▶sub new {
Subroutine new: called CC=7 SCAR=22.0
Pod documented
32 1 my ($class, $fuid_lock, $fnode_id) =
33 (shift, shift, shift);
34 1 my %args = (
35 %opt,
36 @_
37 );
38
39 1 my $node_id = delete $args{node_id};
40 1 my $self = $class->init($fuid_lock, $fnode_id);
41
42 1 ▶ if(ref $self)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 1 0 1
43 {
44 1 ▶ if(my $error = $self->get_error_code())
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $self->get_error_code) 0 1 1
45 {
46 0 undef $self;
47 0 return $error;
48 }
49
50 1 foreach my $pname (keys %args)
51 {
52 2 my $sub_name = "set_$pname";
53 2 ▶ $self->$sub_name($args{$pname}) if exists $args{$pname};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$pname} 2 0 2
54 }
55
56 1 ▶ unless($fnode_id || !ref $self)
Branch: 1 branch
BranchTrueFalseTotal
unless ($fnode_id or not ref $self) 1 0 1
Condition33%1/3
$fnode_id or not ref $self
l!l&&r!l&&!r
001
MC/DC0%0/2
$fnode_id or not ref $self
$fnode_id not ref $self
Truth table33%1/3
A or not(B)
A= $fnode_idB= not ref $self
ABresult
1X1
011
000
57 {
58 1 $self->set_node_id($node_id);
59 }
60 }
61 else {
62 0 return YAUID_ERROR_CREATE_OBJECT();
63 }
64
65 1 $self;
66 }
67  
68 0 ▶sub timestamp_to_datetime {
Subroutine timestamp_to_datetime: not called CC=2 SCAR=17.9
Pod documented
69 0 ▶ my @parts = (localtime( $_[0] || time ))[0..5];
Condition0%0/2
$_[0] || time
l!l
00
MC/DC0%0/1
$_[0] || time
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
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 1;
79  
80  
81 __END__
↑ Summary YAUID.xs »