Created
July 14, 2015 16:09
-
-
Save dagolden/7bdfa243d61e48decac9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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