AnyMongo
view release on metacpan or search on metacpan
lib/AnyMongo/BSON/OID.pm view on Meta::CPAN
package AnyMongo::BSON::OID;
BEGIN {
$AnyMongo::BSON::OID::VERSION = '0.03';
}
# ABSTRACT: A Mongo ObjectId
use strict;
use warnings;
# use namespace::autoclean;
use AnyMongo;
use Any::Moose;
has value => (
is => 'ro',
isa => 'Str',
required => 1,
builder => 'build_value',
);
sub BUILDARGS {
my $class = shift;
return $class->SUPER::BUILDARGS(flibble => @_) if @_ % 2;
return $class->SUPER::BUILDARGS(@_);
}
sub build_value {
my ($self, $str) = @_;
$str = '' unless defined $str;
_build_value($self, $str);
}
sub to_string {
my ($self) = @_;
$self->value;
}
sub get_time {
my ($self) = @_;
my $ts = 0;
for (my $i = 0; $i<4; $i++) {
$ts = ($ts * 256) + hex(substr($self->value, $i*2, 2));
}
return $ts;
}
sub TO_JSON {
my ($self) = @_;
return {'$oid' => $self->value};
}
use overload
'""' => \&to_string,
'fallback' => 1;
no Any::Moose;
# __PACKAGE__->meta->make_immutable (inline_destructor => 0);
__PACKAGE__->meta->make_immutable;
1;
( run in 0.872 second using v1.01-cache-2.11-cpan-5837b0d9d2c )