line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
71
|
|
|
71
|
|
28734
|
use 5.010001; |
|
71
|
|
|
|
|
238
|
|
2
|
71
|
|
|
71
|
|
367
|
use strict; |
|
71
|
|
|
|
|
133
|
|
|
71
|
|
|
|
|
1400
|
|
3
|
71
|
|
|
71
|
|
318
|
use warnings; |
|
71
|
|
|
|
|
183
|
|
|
71
|
|
|
|
|
2357
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package BSON::Timestamp; |
6
|
|
|
|
|
|
|
# ABSTRACT: BSON type wrapper for timestamps |
7
|
|
|
|
|
|
|
|
8
|
71
|
|
|
71
|
|
379
|
use version; |
|
71
|
|
|
|
|
126
|
|
|
71
|
|
|
|
|
306
|
|
9
|
|
|
|
|
|
|
our $VERSION = 'v1.12.1'; |
10
|
|
|
|
|
|
|
|
11
|
71
|
|
|
71
|
|
5462
|
use Carp (); |
|
71
|
|
|
|
|
191
|
|
|
71
|
|
|
|
|
1559
|
|
12
|
71
|
|
|
71
|
|
368
|
use Tie::IxHash; |
|
71
|
|
|
|
|
155
|
|
|
71
|
|
|
|
|
1745
|
|
13
|
|
|
|
|
|
|
|
14
|
71
|
|
|
71
|
|
380
|
use Moo; |
|
71
|
|
|
|
|
139
|
|
|
71
|
|
|
|
|
371
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#pod =attr seconds |
17
|
|
|
|
|
|
|
#pod |
18
|
|
|
|
|
|
|
#pod A value representing seconds since the Unix epoch. The default is |
19
|
|
|
|
|
|
|
#pod current value of C |
20
|
|
|
|
|
|
|
#pod |
21
|
|
|
|
|
|
|
#pod =attr increment |
22
|
|
|
|
|
|
|
#pod |
23
|
|
|
|
|
|
|
#pod A numeric value to disambiguate timestamps in the same second. The |
24
|
|
|
|
|
|
|
#pod default is 0. |
25
|
|
|
|
|
|
|
#pod |
26
|
|
|
|
|
|
|
#pod =cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has [qw/seconds increment/] => ( |
29
|
|
|
|
|
|
|
is => 'ro' |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
71
|
|
|
71
|
|
23328
|
use namespace::clean -except => 'meta'; |
|
71
|
|
|
|
|
149
|
|
|
71
|
|
|
|
|
476
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $max_int32 = 2147483647; |
35
|
|
|
|
|
|
|
my $max_uint32 = 4_294_967_295; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Support back-compat 'sec' and inc' and legacy constructor shortcut |
38
|
|
|
|
|
|
|
sub BUILDARGS { |
39
|
17971
|
|
|
17971
|
0
|
531553
|
my ($class) = shift; |
40
|
|
|
|
|
|
|
|
41
|
17971
|
|
|
|
|
27369
|
my %args; |
42
|
17971
|
100
|
100
|
|
|
83434
|
if ( @_ && $_[0] !~ /^[s|i]/ ) { |
43
|
17929
|
|
|
|
|
40786
|
$args{seconds} = $_[0]; |
44
|
17929
|
|
|
|
|
29955
|
$args{increment} = $_[1]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
42
|
50
|
|
|
|
131
|
Carp::croak( __PACKAGE__ . "::new called with an odd number of elements\n" ) |
48
|
|
|
|
|
|
|
unless @_ % 2 == 0; |
49
|
|
|
|
|
|
|
|
50
|
42
|
|
|
|
|
108
|
%args = @_; |
51
|
42
|
50
|
33
|
|
|
202
|
$args{seconds} = $args{sec} if exists $args{sec} && !exists $args{seconds}; |
52
|
42
|
50
|
33
|
|
|
98
|
$args{increment} = $args{inc} if exists $args{inc} && !exists $args{increment}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
17971
|
100
|
|
|
|
35719
|
$args{seconds} = time unless defined $args{seconds}; |
56
|
17971
|
100
|
|
|
|
32514
|
$args{increment} = 0 unless defined $args{increment}; |
57
|
17971
|
|
|
|
|
55520
|
$args{$_} = int( $args{$_} ) for qw/seconds increment/; |
58
|
|
|
|
|
|
|
|
59
|
17971
|
|
|
|
|
293308
|
return \%args; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub BUILD { |
63
|
17971
|
|
|
17971
|
0
|
184608
|
my ($self) = @_; |
64
|
|
|
|
|
|
|
|
65
|
17971
|
|
|
|
|
29985
|
for my $attr (qw/seconds increment/) { |
66
|
35940
|
|
|
|
|
75033
|
my $v = $self->$attr; |
67
|
35940
|
100
|
100
|
|
|
120628
|
Carp::croak("BSON::Timestamp '$attr' must be uint32") |
68
|
|
|
|
|
|
|
unless $v >= 0 && $v <= $max_uint32; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
17967
|
|
|
|
|
69436
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# For backwards compatibility |
75
|
|
|
|
|
|
|
{ |
76
|
71
|
|
|
71
|
|
42039
|
no warnings 'once'; |
|
71
|
|
|
|
|
179
|
|
|
71
|
|
|
|
|
22012
|
|
77
|
|
|
|
|
|
|
*sec = \&seconds; |
78
|
|
|
|
|
|
|
*inc = \&increment; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#pod =method TO_JSON |
82
|
|
|
|
|
|
|
#pod |
83
|
|
|
|
|
|
|
#pod If the C option is true, returns a hashref compatible with |
84
|
|
|
|
|
|
|
#pod MongoDB's L |
85
|
|
|
|
|
|
|
#pod format, which represents it as a document as follows: |
86
|
|
|
|
|
|
|
#pod |
87
|
|
|
|
|
|
|
#pod {"$timestamp" : { "t":, "i": }} |
88
|
|
|
|
|
|
|
#pod |
89
|
|
|
|
|
|
|
#pod If the C option is false, an error is thrown, as this value |
90
|
|
|
|
|
|
|
#pod can't otherwise be represented in JSON. |
91
|
|
|
|
|
|
|
#pod |
92
|
|
|
|
|
|
|
#pod =cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub TO_JSON { |
95
|
11
|
100
|
|
11
|
1
|
175
|
if ( $ENV{BSON_EXTJSON} ) { |
96
|
10
|
|
|
|
|
21
|
my %data; |
97
|
10
|
|
|
|
|
47
|
tie %data, 'Tie::IxHash'; |
98
|
10
|
|
|
|
|
172
|
$data{t} = int($_[0]->{seconds}); |
99
|
10
|
|
|
|
|
159
|
$data{i} = int($_[0]->{increment}); |
100
|
10
|
|
|
|
|
155
|
return { '$timestamp' => \%data }; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
156
|
Carp::croak( "The value '$_[0]' is illegal in JSON" ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _cmp { |
107
|
8
|
|
|
8
|
|
20
|
my ( $l, $r, $swap ) = @_; |
108
|
8
|
100
|
66
|
|
|
28
|
if ( !defined($l) || !defined($r) ) { |
109
|
3
|
|
|
|
|
298
|
Carp::carp "Use of uninitialized value in BSON::Timestamp comparison (<=>); will be treated as 0,0"; |
110
|
|
|
|
|
|
|
} |
111
|
8
|
|
50
|
|
|
141
|
$l //= { seconds => 0, increment => 0 }; |
112
|
8
|
|
100
|
|
|
28
|
$r //= { seconds => 0, increment => 0 }; |
113
|
8
|
100
|
|
|
|
16
|
($r, $l) = ($l, $r) if $swap; |
114
|
|
|
|
|
|
|
my $cmp = ( $l->{seconds} <=> $r->{seconds} ) |
115
|
8
|
|
100
|
|
|
29
|
|| ( $l->{increment} <=> $r->{increment} ); |
116
|
8
|
|
|
|
|
52
|
return $cmp; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
use overload ( |
120
|
71
|
|
|
|
|
506
|
'<=>' => \&_cmp, |
121
|
|
|
|
|
|
|
fallback => 1, |
122
|
71
|
|
|
71
|
|
524
|
); |
|
71
|
|
|
|
|
157
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=pod |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=encoding UTF-8 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 NAME |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
BSON::Timestamp - BSON type wrapper for timestamps |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 VERSION |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
version v1.12.1 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SYNOPSIS |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
use BSON::Types ':all'; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
bson_timestamp( $seconds ); |
143
|
|
|
|
|
|
|
bson_timestamp( $seconds, $increment ); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 DESCRIPTION |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This module provides a BSON type wrapper for a BSON timestamp value. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Generally, it should not be used by end-users, but is provided for |
150
|
|
|
|
|
|
|
backwards compatibility. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 seconds |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
A value representing seconds since the Unix epoch. The default is |
157
|
|
|
|
|
|
|
current value of C |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 increment |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
A numeric value to disambiguate timestamps in the same second. The |
162
|
|
|
|
|
|
|
default is 0. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 METHODS |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 TO_JSON |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
If the C option is true, returns a hashref compatible with |
169
|
|
|
|
|
|
|
MongoDB's L |
170
|
|
|
|
|
|
|
format, which represents it as a document as follows: |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
{"$timestamp" : { "t":, "i": }} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
If the C option is false, an error is thrown, as this value |
175
|
|
|
|
|
|
|
can't otherwise be represented in JSON. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=for Pod::Coverage BUILD BUILDARGS sec inc |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 AUTHORS |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over 4 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
David Golden |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Stefan G. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=back |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This software is Copyright (c) 2019 by Stefan G. and MongoDB, Inc. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This is free software, licensed under: |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
__END__ |