# override instead of 'around' to avoid overhead of calling | |
# the default BUILDARGS | |
sub BUILDARGS { | |
my $class = shift; | |
if ( @_ == 0 ) { | |
return { value => MongoDB::BSON::generate_oid() }; | |
} | |
if ( @_ == 1 ) { | |
if ( ref( $_[0] ) eq 'HASH' ) { | |
return $_[0]; | |
} | |
elsif ( $_[0]->isa($class) ) { | |
return { value => $_[0]->value }; | |
} | |
else { | |
return { value => $_[0] }; | |
} | |
} | |
if ( @_ % 2 == 0 ) { | |
return {@_}; | |
} | |
die "Arguments to MongoDB::OID->new must be hash or hash reference\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment