NAME

BSON::ObjectId - ObjectId data element for BSON

SYNOPSIS

use BSON;

my $oid  = BSON::ObjectId->new;
my $oid2 = BSON::ObjectId->new($string);
my $oid3 = BSON::ObjectId->new($binary_string);

DESCRIPTION

This module is needed for BSON and it manages BSON's ObjectId element.

METHODS

new

Main constructor which takes one optional parameter, a string with ObjectId. ObjectId can be either a 24 character hexadecimal value or a 12 character binary value.

my $oid  = BSON::ObjectId->new("4e24d6249ccf967313000000");
my $oid2 = BSON::ObjectId->new("\x4e\x24\xd6\x24\x9c\xcf\x96\x73\x13\0\0\0");

If no ObjectId string is specified, a new one will be generated based on the machine ID, process ID and the current time.

value

Returns or sets the ObjectId value.

$oid->value("4e262c24422ad15e6a000000");
print $oid->value; # Will print it in binary

Returns true if the 24 character string passed matches an ObjectId.

if ( BSON::ObjectId->is_legal($id) ) {
    ...
}

OVERLOAD

The string operator is overloaded so any string operations will actually use the 24-character value of the ObjectId.

THREADS

This module is thread safe.

SEE ALSO

BSON

AUTHOR

minimalist, <minimalist at lavabit.com>

BUGS

Bug reports and patches are welcome. Reports which include a failing Test::More style test are helpful and will receive priority.

LICENSE AND COPYRIGHT

Copyright 2011 minimalist.

This program is free software; you can redistribute it and/or modify it under the terms as perl itself.