This file is indexed.

/usr/lib/x86_64-linux-gnu/perl5/5.22/MongoDB/OID.pm is in libmongodb-perl 1.2.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#
#  Copyright 2009-2013 MongoDB, Inc.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#

package MongoDB::OID;

# ABSTRACT: A Mongo Object ID

use version;
our $VERSION = 'v1.2.2';

use MongoDB::BSON;
use Moo;
use MongoDB;
use MongoDB::_Constants;
use MongoDB::_Types qw(
    OID
);
use Types::Standard qw(
    Str
);
use namespace::clean;

#pod =head1 ATTRIBUTES
#pod
#pod =head2 value
#pod
#pod The OID value. A random value will be generated if none exists already.
#pod It is a 24-character hexadecimal string (12 bytes).
#pod
#pod Its string representation is the 24-character string.
#pod
#pod =cut

has value => (
    is      => 'ro',
    required => 1,
    builder => '_build_value',
    isa => OID,
    coerce => OID->coercion,
);

# XXX need to set up typedef with str length
# msg: "OIDs need to have a length of 24 bytes"

sub _build_value {
    my ($self) = @_;
    return MongoDB::BSON::generate_oid();
}

around BUILDARGS => sub {
    my $orig = shift;
    my $class = shift;
    if ( @_ == 0 ) {
        return { value => MongoDB::BSON::generate_oid() };
    }
    if ( @_ == 1 ) {
        return { value => "$_[0]" };
    }
    return $orig->($class, @_);
};

# This private constructor bypasses everything Moo does for us and just
# jams an OID into a blessed hashref.  This is only for use in super-hot
# code paths, like document insertion.
sub _new_oid {
    return bless { value => MongoDB::BSON::generate_oid() }, $_[0];
}

#pod =head1 METHODS
#pod
#pod =head2 to_string
#pod
#pod     my $hex = $oid->to_string;
#pod
#pod Gets the value of this OID as a 24-digit hexadecimal string.
#pod
#pod =cut

sub to_string { $_[0]->{value} }

#pod =head2 get_time
#pod
#pod     my $date = DateTime->from_epoch(epoch => $id->get_time);
#pod
#pod Each OID contains a 4 bytes timestamp from when it was created.  This method
#pod extracts the timestamp.
#pod
#pod =cut

sub get_time {
    my ($self) = @_;

    return hex(substr($self->value, 0, 8));
}

# for testing purposes
sub _get_pid {
    my ($self) = @_;

    return hex(substr($self->value, 14, 4));
}

#pod =head2 TO_JSON
#pod
#pod     my $json = JSON->new;
#pod     $json->allow_blessed;
#pod     $json->convert_blessed;
#pod
#pod     $json->encode(MongoDB::OID->new);
#pod
#pod Returns a JSON string for this OID.  This is compatible with the strict JSON
#pod representation used by MongoDB, that is, an OID with the value
#pod "012345678901234567890123" will be represented as
#pod C<{"$oid" : "012345678901234567890123"}>.
#pod
#pod =cut

sub TO_JSON {
    my ($self) = @_;
    return {'$oid' => $self->value};
}

use overload
    '""' => \&to_string,
    'fallback' => 1;

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

MongoDB::OID - A Mongo Object ID

=head1 VERSION

version v1.2.2

=head1 SYNOPSIS

If no C<_id> field is provided when a document is inserted into the database, an
C<_id> field will be added with a new C<MongoDB::OID> as its value.

    my $id = $collection->insert({'name' => 'Alice', age => 20});

C<$id> will be a C<MongoDB::OID> that can be used to retrieve or update the
saved document:

    $collection->update({_id => $id}, {'age' => {'$inc' => 1}});
    # now Alice is 21

To create a copy of an existing OID, you must set the value attribute in the
constructor.  For example:

    my $id1 = MongoDB::OID->new;
    my $id2 = MongoDB::OID->new(value => $id1->value);
    my $id3 = MongoDB::OID->new($id1->value);
    my $id4 = MongoDB::OID->new($id1);

Now C<$id1>, C<$id2>, C<$id3> and C<$id4> will have the same value.

OID generation is thread safe.

=head1 ATTRIBUTES

=head2 value

The OID value. A random value will be generated if none exists already.
It is a 24-character hexadecimal string (12 bytes).

Its string representation is the 24-character string.

=head1 METHODS

=head2 to_string

    my $hex = $oid->to_string;

Gets the value of this OID as a 24-digit hexadecimal string.

=head2 get_time

    my $date = DateTime->from_epoch(epoch => $id->get_time);

Each OID contains a 4 bytes timestamp from when it was created.  This method
extracts the timestamp.

=head2 TO_JSON

    my $json = JSON->new;
    $json->allow_blessed;
    $json->convert_blessed;

    $json->encode(MongoDB::OID->new);

Returns a JSON string for this OID.  This is compatible with the strict JSON
representation used by MongoDB, that is, an OID with the value
"012345678901234567890123" will be represented as
C<{"$oid" : "012345678901234567890123"}>.

=head1 SEE ALSO

Core documentation on object ids: L<http://dochub.mongodb.org/core/objectids>.

=head1 AUTHORS

=over 4

=item *

David Golden <david@mongodb.com>

=item *

Mike Friedman <friedo@friedo.com>

=item *

Kristina Chodorow <k.chodorow@gmail.com>

=item *

Florian Ragwitz <rafl@debian.org>

=back

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2016 by MongoDB, Inc..

This is free software, licensed under:

  The Apache License, Version 2.0, January 2004

=cut