1use 5.010001; 2use strict; 3use warnings; 4 5package BSON::ObjectId; 6# ABSTRACT: Legacy BSON type wrapper for Object IDs (DEPRECATED) 7 8use version; 9our $VERSION = 'v1.12.2'; 10 11use Carp; 12 13use BSON::OID; 14our @ISA = qw/BSON::OID/; 15 16sub new { 17 my ( $class, $value ) = @_; 18 my $self = bless {}, $class; 19 if ( $value ) { 20 $self->value( $value ); 21 } 22 else { 23 $self->{oid} = BSON::OID::_packed_oid(); 24 } 25 return $self; 26} 27 28sub value { 29 my ( $self, $new_value ) = @_; 30 if ( defined $new_value ) { 31 if ( length($new_value) == 12 ) { 32 $self->{oid} = $new_value; 33 } 34 elsif ( length($new_value) == 24 && $self->is_legal($new_value) ) { 35 $self->{oid} = pack("H*", $new_value); 36 } 37 else { 38 croak("BSON::ObjectId must be a 12 byte or 24 char hex value"); 39 } 40 } 41 return $self->{oid}; 42} 43 44sub is_legal { 45 $_[1] =~ /^[0-9a-f]{24}$/i; 46} 47 48sub to_s { $_[0]->to_string } 49 501; 51 52=pod 53 54=encoding UTF-8 55 56=head1 NAME 57 58BSON::ObjectId - Legacy BSON type wrapper for Object IDs (DEPRECATED) 59 60=head1 VERSION 61 62version v1.12.2 63 64=head1 DESCRIPTION 65 66This module has been deprecated as it was not compatible with 67the official MongoDB BSON implementation on CPAN. 68 69You are strongly encouraged to use L<BSON::OID> instead. 70 71=for Pod::Coverage to_s is_legal new value 72 73=head1 AUTHORS 74 75=over 4 76 77=item * 78 79David Golden <david@mongodb.com> 80 81=item * 82 83Stefan G. <minimalist@lavabit.com> 84 85=back 86 87=head1 COPYRIGHT AND LICENSE 88 89This software is Copyright (c) 2020 by Stefan G. and MongoDB, Inc. 90 91This is free software, licensed under: 92 93 The Apache License, Version 2.0, January 2004 94 95=cut 96 97__END__ 98 99 100# vim: set ts=4 sts=4 sw=4 et tw=75: 101