package Object::ID; use 5.008_008; use strict; use warnings; use
version; our $VERSION = qv("v0.1.2"); # Over 2x faster than
Hash::Util::FieldHash use Hash::FieldHash qw(fieldhashes); use
Sub::Name qw(subname); # Even though we're not using Exporter,
be polite for introspection purposes our @EXPORT = qw(object_id
object_uuid); sub import { my $caller = caller; for my $method
(qw) { my $name = "$caller\::$method"; no strict 'refs'; # In a
client class using namespace::autoclean, the exported methods #
are indistinguishable from exported functions, and therefore get
# autocleaned out of existence. So use subname() to rename them
as # things that namespace::autoclean will interpret as methods.
*$name = subname($name, \&$method); } } # All glory to Vincent
Pit for coming up with this implementation { fieldhashes
\my(%IDs, %UUIDs); my $Last_ID = "a"; sub object_id { my $self =
shift; # This is 15% faster than ||= return $IDs{$self} if
exists $IDs{$self}; return $IDs{$self} = ++$Last_ID; } if ( eval
{ require Data: