Object-ID-v0.1.2000755000765000765 011637531363 13727 5ustar00schwernschwern000000000000Object-ID-v0.1.2/.perlcriticrc000444000765000765 240611637531363 16554 0ustar00schwernschwern000000000000# Change the default message to show the policy name so we can shut it up if necessary verbose = %m [%p] at %f line %l, near '%r'\n # Force perlcritic to use color, even when run through a pager. color = 1 # Use a pager. pager = $PAGER # Nuthin wrong with any of these. [-BuiltinFunctions::RequireBlockMap] [-BuiltinFunctions::RequireBlockGrep] [-ValuesAndExpressions::ProhibitEmptyQuotes] [-ValuesAndExpressions::ProhibitNoisyQuotes] [-ValuesAndExpressions::ProhibitInterpolationOfLiterals] [-Variables::RequireInitializationForLocalVars] [-Variables::ProhibitPunctuationVars] [-ControlStructures::ProhibitPostfixControls] [-References::ProhibitDoubleSigils] [-Documentation::RequirePodAtEnd] [-Modules::ProhibitAutomaticExportation] # RCS keywords? Get real. [-Miscellanea::RequireRcsKeywords] # No point putting a /x on really short regexes. [RegularExpressions::RequireExtendedFormatting] minimum_regex_length_to_complain_about = 5 # Extend the ability to play with @_ to 3 line subroutines. [Subroutines::RequireArgUnpacking] short_subroutine_statements = 3 # Inform perlcritic that Mouse turns on strictures [TestingAndDebugging::RequireUseStrict] equivalent_modules = Mouse [TestingAndDebugging::RequireUseWarnings] equivalent_modules = MouseObject-ID-v0.1.2/.perltidyrc000444000765000765 116511637531363 16251 0ustar00schwernschwern000000000000--maximum-line-length=100 # we have widescreen now --indent-columns=4 --continuation-indentation=2 --no-opening-sub-brace-on-new-line --paren-tightness=1 --square-bracket-tightness=1 --brace-tightness=1 --no-space-for-semicolon --no-outdent-long-quotes --output-line-ending=unix --no-outdent-labels --no-blanks-before-comments --blanks-before-subs --blanks-before-blocks --nospace-after-keyword="my local our and or eq ne if else elsif until unless while for foreach return switch case given when" --want-break-before="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=" Object-ID-v0.1.2/Build.PL000444000765000765 235711637531363 15367 0ustar00schwernschwern000000000000#!/usr/bin/perl -w use 5.008_008; use strict; use lib 'inc'; use MyBuilder; my $builder = MyBuilder->new( module_name => 'Object::ID', license => 'perl', dist_author => 'Michael G Schwern ', no_index => { package => [ "UNIVERSAL" ], }, meta_merge => { resources => { repository => 'http://github.com/schwern/Object-ID', }, keywords => [ 'id', 'identifier', 'universal', 'object' ], configure_requires => { 'Module::Build' => '0.340201' # what shipped with 5.10.1 }, }, build_requires => { 'Test::More' => '0.88', # for done_testing version => '0.77', }, requires => { perl => '5.8.8', "Sub::Name" => '0.03', 'Hash::FieldHash' => '0.10', }, auto_features => { object_uuid => { description => "Unique object idenifier using UUIDs", requires => { "Data::UUID" => 1.148 } } }, create_license => 1, create_readme => 1, ); $builder->create_build_script(); Object-ID-v0.1.2/Changes000444000765000765 271511637531363 15364 0ustar00schwernschwern000000000000v0.1.2 Sat Sep 24 21:49:25 PDT 2011 Bug Fixes * Quiet overzealous "v-string in use/require non-portable" warning from Perl 5.10.0. v0.1.1 Thu May 20 14:17:23 PDT 2010 Distribution Changes * Lowered the requirement on version.pm to 0.77 (what came with 5.10.1) at the request of Debian to make packaging easier. [rt.cpan.org 57650] v0.1.0 Wed May 5 18:06:31 PDT 2010 New Features * Now works back to 5.8.8 Performance * 2x performance boost on the first call to object_id() for each object thanks to Hash::FieldHash. Bug Fixes * object_id() will work with threads, but object_uuid() will not. Will fix itself when Data::UUID fixes threads. v0.0.5 Sun May 2 10:26:55 PDT 2010 Bug Fixes * Work with classes that use namespace::autoclean v0.0.4 Sat May 1 13:53:39 PDT 2010 Distribution fixes * I said I don't provide UNIVERSAL! v0.0.3 Sat May 1 13:24:24 PDT 2010 Distribution fixes * Trying again to convince PAUSE we don't provide UNIVERSAL v0.0.2 Sat May 1 11:15:41 PDT 2010 New Features * Added a README and explicit license Distribution Fixes * Don't say we provide UNIVERSAL v0.0.1 Sat May 1 09:01:51 PDT 2010 New Features * Object::ID role to give objects a unique identifier * $obj->object_id returns a unique object identifier for any object * $obj->object_uuid does the same but returns a UUID (Data::UUID required) * UNIVERSAL::Object::ID makes the methods available to all objects Object-ID-v0.1.2/LICENSE000444000765000765 4401311637531363 15113 0ustar00schwernschwern000000000000This software is copyright (c) 2011 by Michael G Schwern . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2011 by Michael G Schwern . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2011 by Michael G Schwern . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Object-ID-v0.1.2/MANIFEST000444000765000765 53211637531363 15175 0ustar00schwernschwern000000000000.perlcriticrc .perltidyrc Build.PL Changes inc/MyBuilder.pm lib/Object/ID.pm lib/UNIVERSAL/Object/ID.pm LICENSE MANIFEST This list of files MANIFEST.SKIP META.yml README t/00compile.t t/autoclean.t t/destroy.t t/immutable.t t/lib/AutoCleanWidget.pm t/role.t t/threads.t t/universal.t t/uuid.t META.json SIGNATURE Added here by Module::Build Object-ID-v0.1.2/MANIFEST.SKIP000444000765000765 177511637531363 15774 0ustar00schwernschwern000000000000 #!start included /Users/schwern/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1/ExtUtils/MANIFEST.SKIP # Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \B\.gitignore\b \b_darcs\b \B\.cvsignore$ # Avoid VMS specific MakeMaker generated files \bDescrip.MMS$ \bDESCRIP.MMS$ \bdescrip.mms$ # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ \bBuild.bat$ \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ \.tmp$ \.# \.rej$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ # Avoid Devel::Cover and Devel::CoverX::Covered files. \bcover_db\b \bcovered\b # Avoid MYMETA files ^MYMETA\. #!end included /Users/schwern/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1/ExtUtils/MANIFEST.SKIP Object-ID-v0.1.2/META.json000444000765000765 271511637531363 15512 0ustar00schwernschwern000000000000{ "abstract" : "A unique identifier for any object", "author" : [ "Michael G Schwern " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 2.112150", "keywords" : [ "id", "identifier", "universal", "object" ], "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Object-ID", "no_index" : { "package" : [ "UNIVERSAL" ] }, "prereqs" : { "build" : { "requires" : { "Test::More" : "0.88", "version" : "0.77" } }, "configure" : { "requires" : { "Module::Build" : "0.340201" } }, "runtime" : { "requires" : { "Hash::FieldHash" : "0.10", "Sub::Name" : "0.03", "perl" : "v5.8.8" } } }, "provides" : { "Object::ID" : { "file" : "lib/Object/ID.pm", "version" : "v0.1.2" }, "UNIVERSAL::Object::ID" : { "file" : "lib/UNIVERSAL/Object/ID.pm", "version" : "v0.1.2" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "http://github.com/schwern/Object-ID" } }, "version" : "v0.1.2" } Object-ID-v0.1.2/META.yml000444000765000765 152411637531363 15337 0ustar00schwernschwern000000000000--- abstract: 'A unique identifier for any object' author: - 'Michael G Schwern ' build_requires: Test::More: 0.88 version: 0.77 configure_requires: Module::Build: 0.340201 dynamic_config: 1 generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 2.112150' keywords: - id - identifier - universal - object license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Object-ID no_index: package: - UNIVERSAL provides: Object::ID: file: lib/Object/ID.pm version: v0.1.2 UNIVERSAL::Object::ID: file: lib/UNIVERSAL/Object/ID.pm version: v0.1.2 requires: Hash::FieldHash: 0.10 Sub::Name: 0.03 perl: v5.8.8 resources: license: http://dev.perl.org/licenses/ repository: http://github.com/schwern/Object-ID version: v0.1.2 Object-ID-v0.1.2/README000444000765000765 617611637531363 14756 0ustar00schwernschwern000000000000NAME Object::ID - A unique identifier for any object SYNOPSIS package My::Object; # Imports the object_id method use Object::ID; DESCRIPTION This is a unique identifier for any object, regardless of its type, structure or contents. Its features are: * Works on ANY object of any type * Does not modify the object in any way * Does not change with the object's contents * Is O(1) to calculate (ie. doesn't matter how big the object is) * The id is unique for the life of the process * The id is always a true value USAGE Object::ID is a role, rather than inheriting its methods they are imported into your class. To make your class use Object::ID, simply "use Object::ID" in your class. package My::Class; use Object::ID; Then write your class however you want. METHODS The following methods are made available to your class. object_id my $id = $object->object_id; Returns an identifier unique to the $object. The identifier is not related to the content of the object. It is only unique for the life of the process. There is no guarantee as to the format of the identifier from version to version. For example: my $obj = My::Class->new; my $copy = $obj; # This is true, $obj and $copy refer to the same object $obj->object_id eq $copy->object_id; my $obj2 = My::Class->new; # This is false, $obj and $obj2 are different objects. $obj->object_id eq $obj2->object_id; use Clone; my $clone = clone($obj); # This is false, even though they contain the same data. $obj->object_id eq $clone->object_id; object_uuid my $uuid = $object->object_uuid Like "$object->object_id" but returns a UUID unique to the $object. Only works if Data::UUID is installed. See Data::UUID for more details about UUID. FAQ Why not just use the object's reference? References are not unique over the life of a process. Perl will reuse references of destroyed objects, as demonstrated by this code snippet: { package Foo; sub new { my $class = shift; my $string = shift; return bless {}, $class; } } for(1..3) { my $obj = Foo->new; print "Object's reference is $obj\n"; } This will print, for example, "Object's reference is Foo=HASH(0x803704)" three times. How much memory does it use? Very little. Object::ID stores the ID and address of each object you've asked the ID of. Once the object has been destroyed it no longer stores it. In other words, you only pay for what you use. When you're done with it, you don't pay for it any more. LICENSE Copyright 2010, Michael G Schwern . This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See THANKS Thank you to Vincent Pit for coming up with the implementation. Object-ID-v0.1.2/SIGNATURE000644000765000765 375111637531363 15360 0ustar00schwernschwern000000000000This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.68. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 893aa2038b35266055d32e4906a6e5227df41327 .perlcriticrc SHA1 b1792a796e85dfbf8a74b4d1ad41ad32ddea48bb .perltidyrc SHA1 1eae695235653dfdeabd343fe83a5add17b11aa2 Build.PL SHA1 cb8a49cc2d81f261790f2ebe7a6a3078643cbe0a Changes SHA1 61c777820e70593419593ecb9680c5839f611595 LICENSE SHA1 f893af334763db3d658d5b349bb2e663d341a016 MANIFEST SHA1 f1ae8c236fb9a727ebec5bb70de2d4dd6e2f7c28 MANIFEST.SKIP SHA1 40776f8cbaeba3b797e589ef92e94625725c896b META.json SHA1 b33fbea74a2b31ec8dbe7a94727f736bf09848b2 META.yml SHA1 ab5e9533c1d96ad404782c4df0bdef47ceacd052 README SHA1 d51b8f82f755d2e8e456ad5e0b7195e92d07a3e4 inc/MyBuilder.pm SHA1 54002aac4b97d60a2d3333f3c888776e18c194ed lib/Object/ID.pm SHA1 3a6091e59f96fef0cf76d3c76a78e72057a18167 lib/UNIVERSAL/Object/ID.pm SHA1 0c48cd304451ed6f7b82cad9c870981a44d6a92d t/00compile.t SHA1 3f78f31d53e9c28f8367da10ba3056ab73dac263 t/autoclean.t SHA1 2285e395d39771a7554aae46aff6991e0096f942 t/destroy.t SHA1 33325fa08e39a7c0c92720ac51fb71d4cb3e20fd t/immutable.t SHA1 179dcdc43b067802aff5cdc6e58bfee7a06f8d0a t/lib/AutoCleanWidget.pm SHA1 edf20baf017122f5c7ac77b50416302698ec0b66 t/role.t SHA1 a5224407abd07c1ff17f5f606bccd48ad354bed5 t/threads.t SHA1 552f3aacb7e6b655d6b17170b1239c286a786bbc t/universal.t SHA1 83cb8b8988721d987a096d44a132ae84ac821959 t/uuid.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (Darwin) iEYEARECAAYFAk5+svMACgkQWMohlhD1QyfYkQCfeW89O98Ggi+fUN08S9NgOMUg Q4AAnjmFT7Jw6dDywEf8hjUZPOXatech =/Efu -----END PGP SIGNATURE----- Object-ID-v0.1.2/inc000755000765000765 011637531363 14500 5ustar00schwernschwern000000000000Object-ID-v0.1.2/inc/MyBuilder.pm000444000765000765 31311637531363 17044 0ustar00schwernschwern000000000000package MyBuilder; use base qw(Module::Build); sub get_metadata { my $self = shift; my $data = $self->SUPER::get_metadata(@_); delete $data->{provides}{UNIVERSAL}; return $data; } 1; Object-ID-v0.1.2/lib000755000765000765 011637531363 14475 5ustar00schwernschwern000000000000Object-ID-v0.1.2/lib/Object000755000765000765 011637531363 15703 5ustar00schwernschwern000000000000Object-ID-v0.1.2/lib/Object/ID.pm000444000765000765 1132711637531363 16716 0ustar00schwernschwern000000000000package 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::UUID } ) { my $UG; *object_uuid = sub { my $self = shift; # Because the mere presense of a Data::UUID object will # cause problems with threads, don't initialize it until # absolutely necessary. $UG ||= Data::UUID->new; return $UUIDs{$self} if exists $UUIDs{$self}; return $UUIDs{$self} = $UG->create_str; } } else { *object_uuid = sub { require Carp; Carp::croak("object_uuid() requires Data::UUID"); }; } } =head1 NAME Object::ID - A unique identifier for any object =head1 SYNOPSIS package My::Object; # Imports the object_id method use Object::ID; =head1 DESCRIPTION This is a unique identifier for any object, regardless of its type, structure or contents. Its features are: * Works on ANY object of any type * Does not modify the object in any way * Does not change with the object's contents * Is O(1) to calculate (ie. doesn't matter how big the object is) * The id is unique for the life of the process * The id is always a true value =head1 USAGE Object::ID is a role, rather than inheriting its methods they are imported into your class. To make your class use Object::ID, simply C<< use Object::ID >> in your class. package My::Class; use Object::ID; Then write your class however you want. =head1 METHODS The following methods are made available to your class. =head2 object_id my $id = $object->object_id; Returns an identifier unique to the C<$object>. The identifier is not related to the content of the object. It is only unique for the life of the process. There is no guarantee as to the format of the identifier from version to version. For example: my $obj = My::Class->new; my $copy = $obj; # This is true, $obj and $copy refer to the same object $obj->object_id eq $copy->object_id; my $obj2 = My::Class->new; # This is false, $obj and $obj2 are different objects. $obj->object_id eq $obj2->object_id; use Clone; my $clone = clone($obj); # This is false, even though they contain the same data. $obj->object_id eq $clone->object_id; =head2 object_uuid my $uuid = $object->object_uuid Like C<< $object->object_id >> but returns a UUID unique to the $object. Only works if Data::UUID is installed. See L for more details about UUID. =head1 FAQ =head2 Why not just use the object's reference? References are not unique over the life of a process. Perl will reuse references of destroyed objects, as demonstrated by this code snippet: { package Foo; sub new { my $class = shift; my $string = shift; return bless {}, $class; } } for(1..3) { my $obj = Foo->new; print "Object's reference is $obj\n"; } This will print, for example, C<< Object's reference is Foo=HASH(0x803704) >> three times. =head2 How much memory does it use? Very little. Object::ID stores the ID and address of each object you've asked the ID of. Once the object has been destroyed it no longer stores it. In other words, you only pay for what you use. When you're done with it, you don't pay for it any more. =head1 LICENSE Copyright 2010, Michael G Schwern . This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =head1 THANKS Thank you to Vincent Pit for coming up with the implementation. =cut 1; Object-ID-v0.1.2/lib/UNIVERSAL000755000765000765 011637531363 16045 5ustar00schwernschwern000000000000Object-ID-v0.1.2/lib/UNIVERSAL/Object000755000765000765 011637531363 17253 5ustar00schwernschwern000000000000Object-ID-v0.1.2/lib/UNIVERSAL/Object/ID.pm000444000765000765 154511637531363 20247 0ustar00schwernschwern000000000000package UNIVERSAL::Object::ID; use 5.008_008; use strict; use warnings; use version; our $VERSION = qv("v0.1.2"); { package UNIVERSAL; use Object::ID; } =head1 NAME UNIVERSAL::Object::ID - Supply a unique object identifier to every object =head1 SYNOPSIS use DateTime; # for example use UNIVERSAL::Object::ID; my $date = DateTime->now; print $date->object_id; =head1 DESCRIPTION Loading UNIVERSAL::Object::ID makes the C<< Object::ID >> role available to every object. Use at your own risk, polluting UNIVERSAL is not to be taken lightly. The best place to use this module is in your own personal or internal use code rather than a widely distributed software library. Or you can use L to safely apply the UNIVERSAL effect to just your lexical scope. =head1 SEE ALSO L, L =cut 1; Object-ID-v0.1.2/t000755000765000765 011637531363 14172 5ustar00schwernschwern000000000000Object-ID-v0.1.2/t/00compile.t000444000765000765 17511637531363 16267 0ustar00schwernschwern000000000000#!/usr/bin/perl use strict; use warnings; use Test::More tests => 2; use_ok 'Object::ID'; use_ok 'UNIVERSAL::Object::ID'; Object-ID-v0.1.2/t/autoclean.t000444000765000765 46711637531363 16456 0ustar00schwernschwern000000000000#!/usr/bin/perl use strict; use warnings; use lib 't/lib'; use Test::More; plan skip_all => 'namespace::autoclean not available' unless eval { require namespace::autoclean; 1 }; require AutoCleanWidget; my $widget = new_ok('AutoCleanWidget'); can_ok($widget, qw); done_testing; Object-ID-v0.1.2/t/destroy.t000444000765000765 135611637531363 16212 0ustar00schwernschwern000000000000#!/usr/bin/perl # Ensure that a class having a DESTROY method does not interfere # Ensure objects with the same ref still get different IDs. use strict; use warnings; use Test::More; { package My::Class; use Object::ID; sub new { my $class = shift; my $ref = shift; bless $ref, $class; } my $Destroyed; sub destroy_called { return $Destroyed; } sub DESTROY { $Destroyed++; } } { my %ids; for(1..3) { my $obj = new_ok "My::Class", [{}]; $ids{$obj->object_id}++; } is keys %ids, 3, "got different IDs for each object" or diag explain \%ids; is( My::Class->destroy_called, 3, "all three objects destroyed" ); } done_testing(); Object-ID-v0.1.2/t/immutable.t000444000765000765 65311637531363 16457 0ustar00schwernschwern000000000000#!/usr/bin/perl # Demonstrate that the ID does not change with the object's contents. use strict; use warnings; use Test::More; { package My::Class; use Object::ID; sub new { my $class = shift; bless {}, $class; } } { my $obj = new_ok "My::Class"; my $id = $obj->object_id; $obj->{foo} = 42; is $obj->object_id, $id, "ID is independent of object content"; } done_testing; Object-ID-v0.1.2/t/role.t000444000765000765 140411637531363 15454 0ustar00schwernschwern000000000000#!/usr/bin/perl use strict; use warnings; use Test::More; { package My::Class; use Object::ID; sub new { my $class = shift; my $ref = shift; bless $ref, $class; } } # Hashref { my $obj = new_ok "My::Class", [{}]; ok $obj->object_id; is $obj->object_id, $obj->object_id; my $copy = $obj; is $obj->object_id, $copy->object_id; my $obj2 = new_ok "My::Class", [{}]; isnt $obj->object_id, $obj2->object_id; } # Coderef { my $obj = new_ok "My::Class", [sub { 42 }]; ok $obj->object_id; my $copy = $obj; is $obj->object_id, $copy->object_id; my $obj2 = new_ok "My::Class", [sub { 42 }]; ok $obj2->object_id; isnt $obj->object_id, $obj2->object_id; } done_testing(); Object-ID-v0.1.2/t/threads.t000444000765000765 143111637531363 16145 0ustar00schwernschwern000000000000#!/usr/bin/perl use strict; use warnings; my $Have_Threads; BEGIN { $Have_Threads = eval { require threads }; require Test::More; Test::More->import; } plan skip_all => "Needs threads" unless $Have_Threads; { package Foo; use Object::ID; sub new { my $class = shift; bless {}, $class; } } TODO: for my $method (qw(object_id object_uuid)) { note "*** Trying $method ***"; todo_skip "uuid known to be thread hostile", 5 if $method eq 'object_uuid'; my $obj = new_ok "Foo"; my $id = $obj->$method; for(1..5) { threads->create(sub { is $obj->$method, $id, "$method in a thread"; }); } note "threads started"; $_->join for threads->list; note "threads joined"; } done_testing(); Object-ID-v0.1.2/t/universal.t000444000765000765 121211637531363 16520 0ustar00schwernschwern000000000000#!/usr/bin/perl -w use strict; use warnings; use Test::More; { package My::Class; sub new { my $class = shift; bless {}, $class; } } use UNIVERSAL::Object::ID; # Is it universal? { my $obj = new_ok "My::Class"; ok $obj->object_id; } # What about a totally unrelated module? { use DirHandle; my $dh = DirHandle->new("."); ok $dh->object_id; my $dh2 = DirHandle->new("."); ok $dh2->object_id; isnt $dh->object_id, $dh2->object_id; } # A regex object? { my $re = qr/foo/; ok $re->object_id; my $re2 = qr/foo/; isnt $re->object_id, $re2->object_id; } done_testing; Object-ID-v0.1.2/t/uuid.t000444000765000765 115111637531363 15460 0ustar00schwernschwern000000000000#!/usr/bin/perl # Test the optional object_uuid use strict; use warnings; use Module::Build; use Test::More; plan skip_all => "Data::UUID not available for object_uuid" unless do { my $build = Module::Build->resume; $build->feature("object_uuid"); }; { package My::Class; use Object::ID; sub new { my $class = shift; bless {}, $class; } } { my $obj = new_ok "My::Class"; ok $obj->object_uuid; my $copy = $obj; is $obj->object_uuid, $copy->object_uuid; my $obj2 = new_ok "My::Class"; isnt $obj->object_uuid, $obj2->object_uuid; } done_testing; Object-ID-v0.1.2/t/lib000755000765000765 011637531363 14740 5ustar00schwernschwern000000000000Object-ID-v0.1.2/t/lib/AutoCleanWidget.pm000444000765000765 33611637531363 20434 0ustar00schwernschwern000000000000package AutoCleanWidget; # A test module for t/autoclean.t to demonstrate a class which # uses namespace::autoclean. use strict; use warnings; use namespace::autoclean; use Object::ID; sub new { bless {}, $_[0] } 1;