Build.PL100644000765000024 325113045746371 14607 0ustar00gfxstaff000000000000Hash-FieldHash-0.15# ========================================================================= # THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA. # DO NOT EDIT DIRECTLY. # ========================================================================= use 5.008_001; use strict; use warnings; use utf8; use builder::MyBuilder; use File::Basename; use File::Spec; my %args = ( license => 'perl_5', dynamic_config => 0, configure_requires => { 'Module::Build' => '0.4005', }, requires => { 'XSLoader' => '0.02', 'parent' => '0.221', 'perl' => '5.008005', }, recommends => { }, suggests => { }, build_requires => { 'Devel::PPPort' => '3.19', 'ExtUtils::MakeMaker' => '6.59', 'ExtUtils::ParseXS' => '2.21', 'Test::LeakTrace' => '0.07', 'Test::More' => '0.62', }, test_requires => { }, name => 'Hash-FieldHash', module_name => 'Hash::FieldHash', allow_pureperl => 0, script_files => [glob('script/*'), glob('bin/*')], c_source => [qw()], PL_files => {}, test_files => ((-d '.git' || $ENV{RELEASE_TESTING}) && -d 'xt') ? 't/ xt/' : 't/', recursive_test_files => 1, ); if (-d 'share') { $args{share_dir} = 'share'; } my $builder = builder::MyBuilder->subclass( class => 'MyBuilder', code => q{ sub ACTION_distmeta { die "Do not run distmeta. Install Minilla and `minil install` instead.\n"; } sub ACTION_installdeps { die "Do not run installdeps. Run `cpanm --installdeps .` instead.\n"; } } )->new(%args); $builder->create_build_script(); Changes100644000765000024 320013045746371 14600 0ustar00gfxstaff000000000000Hash-FieldHash-0.15Revision history for Perl extension Hash::FieldHash 0.15 2017-02-06T01:10:09Z - Fix #1: t/orig/03_class.t fails if FamilyTreeInfo-2.3.24 is installed 0.14 2013-05-18T23:54:21Z - Fix a build issue on 5.8.x 0.13 2013-04-13T11:09:06Z - Use Module::Build instead of Module::Install with minil(1) - No code changes 0.12 2011-10-18 13:37:07 - Mention to what accessors return (RT #68408 by Ron Savage) 0.11 2011-10-18 13:28:07 - Update M::I::XSUtil to 0.41 - Skip system depended tests 0.10 Sun Jan 10 15:27:10 2010 - Add parent.pm to dependencies 0.09 Wed Jan 6 15:06:58 2010 - Make warnings on subroutine redefinition (RT #52073) - Minimum perl version is now 5.8.5 - Modernize Makefile.PL 0.08 Mon Jun 15 22:45:02 2009 - update ppport.h to 3.19 0.07 Sat Jun 6 08:52:44 2009 - pod fix - make from_hash()/to_hash() exportable 0.06 Sat Mar 28 12:30:51 2009 - support for named fields - add fieldhash(my %foo => 'foo') syntax as an accessor generator - add Hash::FieldHash::from_hash($obj, \%params) function - add Hash::FieldHash::to_hash($obj) function - fix some bugs 0.05 Fri Mar 13 11:29:16 2009 - performance improvement - now IDs are zero origin - internal cleanup - use Test::LeakTrace for testing 0.04 Mon Feb 16 12:29:09 2009 - fix issues on bleadperl (5.11) - update ppport.h 0.03 Wed Feb 4 11:51:32 2009 - change an object id from refaddr to be an arbitrary natural number - improve performance 0.02 Mon Feb 2 12:48:16 2009 - add some type checks - fix a double-free problem (checked in t/11_panic_malloc.t) 0.01 Wed Jan 28 10:09:03 2009 - original version; created by Module::Setup LICENSE100644000765000024 4376513045746371 14356 0ustar00gfxstaff000000000000Hash-FieldHash-0.15This software is copyright (c) 2013 by Fuji, Goro (gfx) .. 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) 2013 by Fuji, Goro (gfx) .. 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, Suite 500, Boston, MA 02110-1335 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) 2013 by Fuji, Goro (gfx) .. 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 META.json100644000765000024 417413045746371 14741 0ustar00gfxstaff000000000000Hash-FieldHash-0.15{ "abstract" : "Lightweight field hash for inside-out objects", "author" : [ "Fuji, Goro (gfx) ." ], "dynamic_config" : 0, "generated_by" : "Minilla/v3.0.9", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Hash-FieldHash", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples", "author", "builder" ] }, "prereqs" : { "build" : { "requires" : { "Devel::PPPort" : "3.19", "ExtUtils::MakeMaker" : "6.59", "ExtUtils::ParseXS" : "2.21", "Test::LeakTrace" : "0.07", "Test::More" : "0.62" } }, "configure" : { "requires" : { "Module::Build" : "0.4005" } }, "develop" : { "requires" : { "Test::CPAN::Meta" : "0", "Test::MinimumVersion::Fast" : "0.04", "Test::PAUSE::Permissions" : "0.04", "Test::Pod" : "1.41", "Test::Spellunker" : "v0.2.7" } }, "runtime" : { "requires" : { "XSLoader" : "0.02", "parent" : "0.221", "perl" : "5.008005" } } }, "provides" : { "Hash::FieldHash" : { "file" : "lib/Hash/FieldHash.pm", "version" : "0.15" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/gfx/p5-Hash-FieldHash/issues" }, "homepage" : "https://github.com/gfx/p5-Hash-FieldHash", "repository" : { "url" : "git://github.com/gfx/p5-Hash-FieldHash.git", "web" : "https://github.com/gfx/p5-Hash-FieldHash" } }, "version" : "0.15", "x_contributors" : [ "Fuji Goro ", "Fuji, Goro ", "Todd Rinaldo ", "FUJI Goro (gfx) " ], "x_serialization_backend" : "JSON::PP version 2.27400" } README.md100644000765000024 1322513045746371 14614 0ustar00gfxstaff000000000000Hash-FieldHash-0.15\[!\[Build Status\](https://travis-ci.org/gfx/p5-Hash-FieldHash.svg?branch=master)\](https://travis-ci.org/gfx/p5-Hash-FieldHash) # NAME Hash::FieldHash - Lightweight field hash for inside-out objects # VERSION This document describes Hash::FieldHash version 0.15. # SYNOPSIS use Hash::FieldHash qw(:all); fieldhash my %foo; fieldhashes \my(%bar, %baz); { my $o = Something->new(); $foo{$o} = 42; print $foo{$o}; # => 42 } # when $o is released, $foo{$o} is also deleted, # so %foo is empty in here. # in a class { package Foo; use Hash::FieldHash qw(:all); fieldhash my %bar, 'bar'; # make an accessor } my $obj = bless {}, 'Foo'; $obj->bar(10); # does $bar{$obj} = 10 # DESCRIPTION `Hash::FieldHash` provides the field hash mechanism which supports the inside-out technique. You may know `Hash::Util::FieldHash`. It's a very useful module, but too complex to understand the functionality and only available in 5.10. `H::U::F::Compat` is available for pre-5.10, but it is too slow to use. This is a better alternative to `H::U::F` with following features: - Simpler interface `Hash::FieldHash` provides a few functions: `fieldhash()` and `fieldhashes()`. That's enough. - Higher performance `Hash::FieldHash` is faster than `Hash::Util::FieldHash`, because its internals use simpler structures. - Relic support Although `Hash::FieldHash` uses a new feature introduced in Perl 5.10, _the uvar magic for hashes_ described in ["GUTS" in Hash::Util::Fieldhash](https://metacpan.org/pod/Hash::Util::Fieldhash#GUTS), it supports Perl 5.8 using the traditional tie-hash layer. # INTERFACE ## Exportable functions - `fieldhash(%hash, ?$name, ?$package)` Creates a field hash. The first argument must be a hash. Optional _$name_ and _$package_ indicate the name of the field, which will create rw-accessors, using the same name as _$name_. Returns nothing. - `fieldhashes(@hash_refs)` Creates a number of field hashes. All the arguments must be hash references. Returns nothing. - `from_hash($object, \%fields)` Fills the named fields associated with _$object_ with _%fields_. The keys of _%fields_ can be simple or fully qualified. Returns _$object_. - `to_hash($object, ?-fully_qualify)` Serializes _$object_ into a hash reference. If the `-fully_qualify` option is supplied , field keys are fully qualified. For example: package MyClass; use FieldHash qw(:all); fieldhash my %foo => 'foo'; sub new{ my $class = shift; my $self = bless {}, $class; return from_hash($self, @_); } package MyDerivedClass; use parent -norequire => 'MyClass'; use FieldHash qw(:all); fieldhash my %bar => 'bar'; package main; my $o = MyDerivedClass->new(foo => 10, bar => 20); my $p = MyDerivedClass->new('MyClass::foo' => 10, 'MyDerivedClass::bar' => 20); use Data::Dumper; print Dumper($o->to_hash()); # $VAR1 = { foo => 10, bar => 20 } print Dumper($o->to_hash(-fully_qualify)); # $VAR1 = { 'MyClass::foo' => 10, 'MyDerived::bar' => 20 } # ROBUSTNESS ## Thread support As `Hash::Util::FieldHash` does, `Hash::FieldHash` fully supports threading using the `CLONE` method. ## Memory leaks `Hash::FieldHash` itself does not leak memory, but it may leak memory when you uses hash references as field hash keys because of an issue of perl 5.10.0. # NOTES ## The type of field hash keys `Hash::FieldHash` accepts only references and registered addresses as its keys, whereas `Hash::Util::FieldHash` accepts any type of scalars. According to ["The Generic Object" in Hash::Util::FieldHash](https://metacpan.org/pod/Hash::Util::FieldHash#The-Generic-Object), Non-reference keys in `H::U::F` are used for class fields. That is, all the fields defined by `H::U::F` act as both object fields and class fields by default. It seems confusing; if you do not want them to be class fields, you must check the type of _$self_ explicitly. In addition, these class fields are never inherited. This behavior seems problematic, so `Hash::FieldHash` restricts the type of keys. ## The ID of field hash keys While `Hash::Util::FieldHash` uses `refaddr` as the IDs of field hash keys, `Hash::FieldHash` allocates arbitrary integers as the IDs. ## What accessors return The accessors `fieldhash()` creates are **chainable** accessors. That is, it returns the _$object_ (i.e. `$self`) with a parameter, where as it returns the _$value_ without it. For example: my $o = YourClass->new(); $o->foo(42); # returns $o itself my $value = $o->foo(); # retuns 42 # DEPENDENCIES Perl 5.8.5 or later, and a C compiler. # BUGS No bugs have been reported. Please report any bugs or feature requests to the author. # SEE ALSO [Hash::Util::FieldHash](https://metacpan.org/pod/Hash::Util::FieldHash). [Hash::Util::FieldHash::Compat](https://metacpan.org/pod/Hash::Util::FieldHash::Compat). ["Magic Virtual Tables" in perlguts](https://metacpan.org/pod/perlguts#Magic-Virtual-Tables). [Class::Std](https://metacpan.org/pod/Class::Std) describes the inside-out technique. # AUTHOR Fuji, Goro (gfx) <gfuji(at)cpan.org>. # LICENSE AND COPYRIGHT Copyright (c) 2009-2010, Fuji, Goro. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. create_many.pl100644000765000024 153613045746371 20075 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/benchmark#!perl -w use strict; use Benchmark qw(:all); use Hash::FieldHash (); my $HUF; BEGIN{ if( eval{ require Hash::Util::FieldHash } ){ $HUF = 'Hash::Util::FieldHash'; } else{ require Hash::Util::FieldHash::Compat; $HUF = 'Hash::Util::FieldHash::Compat'; } $HUF->import(qw(fieldhash)); } printf "Perl %vd on $^O\n", $^V; print "$HUF ", $HUF->VERSION, "\n"; print "Hash::FieldHash ", Hash::FieldHash->VERSION, "\n"; fieldhash my %huf; Hash::FieldHash::fieldhash my %hf; my %hash; cmpthese timethese -1 => { 'H::U::F' => sub{ my @list; for(1 .. 1000){ my $o = bless {}; $huf{$o}++; push @list, $o; } }, 'H::F' => sub{ my @list; for(1 .. 1000){ my $o = bless {}; $hf{$o}++; push @list, $o; } }, 'normal' => sub{ my @list; for(1 .. 1000){ my $o = bless {}; $o->{value}++; push @list, $o; } }, }; fieldhash.pl100644000765000024 201113045746371 17522 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/benchmark#!perl -w use strict; use Benchmark qw(:all); use Hash::FieldHash (); my $HUF; BEGIN{ if( eval{ require Hash::Util::FieldHash } ){ $HUF = 'Hash::Util::FieldHash'; } else{ require Hash::Util::FieldHash::Compat; $HUF = 'Hash::Util::FieldHash::Compat'; } $HUF->import(qw(fieldhash)); } printf "Perl %vd on $^O\n", $^V; print "$HUF ", $HUF->VERSION, "\n"; print "Hash::FieldHash ", Hash::FieldHash->VERSION, "\n"; fieldhash my %huf; Hash::FieldHash::fieldhash my %hf; my %hash; cmpthese timethese -1 => { 'H::U::F' => sub{ my $o = bless {}; for(1 .. 10){ $huf{$o} = $_; $huf{$o} = $huf{$o} + $huf{$o} + $huf{$o}; $huf{$o} == ($_*3) or die $huf{$o}; } }, 'H::F' => sub{ my $o = bless {}; for(1 .. 10){ $hf{$o} = $_; $hf{$o} = $hf{$o} + $hf{$o} + $hf{$o}; $hf{$o} == ($_*3) or die $hf{$o}; } }, 'normal' => sub{ my $o = bless {}; for(1 .. 10){ $o->{value} = $_; $o->{value} = $o->{value} + $o->{value} + $o->{value}; $o->{value} == ($_*3) or die $o->{value}; } }, }; hand-written.pl100644000765000024 216213045746371 20206 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/benchmark#!perl -w use strict; use warnings; use Benchmark qw(:all); use Hash::FieldHash; { package ByHand; use Scalar::Util qw(refaddr); my %foo_of; my %bar_of; my %baz_of; sub new { my($class, $a, $b, $c) = @_; my $self = bless {}, $class; $foo_of{refaddr $self} = $a; $bar_of{refaddr $self} = $b; $baz_of{refaddr $self} = $c; return $self; } sub DESTROY { my($self) = @_; delete $foo_of{refaddr $self}; delete $bar_of{refaddr $self}; delete $baz_of{refaddr $self}; } } { package ByFH; use Hash::FieldHash qw(fieldhashes); fieldhashes\my(%foo_of, %bar_of, %baz_of); sub new { my($class, $a, $b, $c) = @_; my $self = bless {}, $class; $foo_of{$self} = $a; $bar_of{$self} = $b; $baz_of{$self} = $c; return $self; } } cmpthese timethese -1, { ByHand => sub { for(1 .. 100) { my $o = ByHand->new(10, 20, 30); } }, ByFieldHash => sub { for(1 .. 100) { my $o = ByFH->new(10, 20, 30); } }, }; mouse.pl100644000765000024 333613045746371 16736 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/benchmark#!perl -w use strict; use Benchmark qw(:all); BEGIN{ package M; use Mouse; has foo => ( is => 'rw', ); has bar => ( is => 'rw', ); has baz => ( is => 'rw', ); __PACKAGE__->meta->make_immutable; } BEGIN{ package HF; use Hash::FieldHash qw(:all); fieldhash my %foo => 'foo'; fieldhash my %bar => 'bar'; fieldhash my %baz => 'baz'; sub new{ my $o; bless \$o, shift } # sub new{ # my $class = shift; # my $self = bless do{ \my $o }, $class; # return Hash::FieldHash::from_hash($self, @_); # } } BEGIN{ package HUF; use Hash::Util::FieldHash::Compat qw(:all); fieldhashes \my(%foo, %bar, %baz); sub new{ my $o; bless \$o, shift } sub foo{ @_ > 1 ? ($foo{$_[0]} = $_[1]) : $foo{$_[0]} } sub bar{ @_ > 1 ? ($bar{$_[0]} = $_[1]) : $bar{$_[0]} } sub baz{ @_ > 1 ? ($baz{$_[0]} = $_[1]) : $baz{$_[0]} } } printf "Perl %vd on $^O\n", $^V; foreach my $count(1, 100){ print "new, and access(read:write 11:3)*$count\n"; cmpthese timethese -1 => { 'H::F' => sub{ my $o = HF->new(); for(1 .. $count){ $o->foo($_); $o->bar($o->foo + $o->foo + $o->foo + $o->foo + $o->foo); $o->baz($o->bar + $o->bar + $o->bar + $o->bar + $o->bar); $o->baz == ($_ * 5 * 5) or die $o->baz; } }, 'H::U::F' => sub{ my $o = HUF->new(); for(1 .. $count){ $o->foo($_); $o->bar($o->foo + $o->foo + $o->foo + $o->foo + $o->foo); $o->baz($o->bar + $o->bar + $o->bar + $o->bar + $o->bar); $o->baz == ($_ * 5 * 5) or die $o->baz; } }, 'Mouse' => sub{ my $o = M->new(); for(1 .. $count){ $o->foo($_); $o->bar($o->foo + $o->foo + $o->foo + $o->foo + $o->foo); $o->baz($o->bar + $o->bar + $o->bar + $o->bar + $o->bar); $o->baz == ($_ * 5 * 5) or die $o->baz; } }, }; } threads.pl100644000765000024 200613045746371 17231 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/benchmark#!perl -w use strict; use Benchmark qw(:all); use threads (); use Hash::FieldHash (); my $HUF; BEGIN{ if( eval{ require Hash::Util::FieldHash } ){ $HUF = 'Hash::Util::FieldHash'; } else{ require Hash::Util::FieldHash::Compat; $HUF = 'Hash::Util::FieldHash::Compat'; } $HUF->import(qw(fieldhash fieldhashes id)); } printf "Perl %vd on $^O\n", $^V; print "$HUF ", $HUF->VERSION, "\n"; print "Hash::FieldHash ", Hash::FieldHash->VERSION, "\n"; cmpthese timethese -2 => { 'H::U::F' => sub{ fieldhashes \my(%huf1, %huf2, %huf3); my @objects; for(1 .. 100){ my $o = bless {}; $huf1{$o} = 1; $huf2{$o} = 2; $huf3{$o} = 3; push @objects, $o; } for(1 .. 3){ threads->new(sub{ my @a = @objects })->join(); } }, 'H::F' => sub{ Hash::FieldHash::fieldhashes \my(%hf1, %hf2, %hf3); my @objects; for(1 .. 100){ my $o = bless {}; $hf1{$o} = 1; $hf2{$o} = 2; $hf3{$o} = 3; push @objects, $o; } for(1 .. 3){ threads->new(sub{ my @a = @objects })->join(); } }, }; MyBuilder.pm100644000765000024 353413045746371 17177 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/builderpackage builder::MyBuilder; use strict; use warnings; use warnings FATAL => qw(recursion); use parent qw(Module::Build); use File::Basename; use Devel::PPPort; my $xs_src = 'src'; my $xs_build = '_xs_build'; sub new { my($class, %args) = @_; Devel::PPPort::WriteFile("$xs_src/ppport.h"); my $so_prefix = $args{module_name}; $so_prefix =~ s/::\w+$//; $so_prefix =~ s{::}{/}g; #$args{c_source} = $xs_src; $args{needs_compiler} = 1; $args{xs_files} = { map { $_ => "./$xs_build/" . $_ } glob("$xs_src/*.xs"), }; $args{extra_compiler_flags} = ["-I$xs_src"]; return $class->SUPER::new(%args); } sub process_xs_files { my($self) = @_; # NOTE: # XS modules are consist of not only *.xs, but also *.c, *.xsi, and etc. foreach my $from(glob "$xs_src/*.{c,cpp,cxx,xsi,xsh}") { my $to = "$xs_build/$from"; $self->add_to_cleanup($to); $self->copy_if_modified(from => $from, to => $to); } $self->SUPER::process_xs_files(); } sub _infer_xs_spec { my($self, $xs_file) = @_; my $spec = $self->SUPER::_infer_xs_spec($xs_file); $spec->{module_name} = $self->module_name; my @d = split /::/, $spec->{module_name}; my $basename = pop @d; # NOTE: # They've been infered from the XS filename, but it's a bad idea! # That's because these names are used by XSLoader, which # deduces filenames from the module name, not an XS filename. $spec->{archdir} = File::Spec->catfile( $self->blib, 'arch', 'auto', @d, $basename); $spec->{bs_file} = File::Spec->catfile( $spec->{archdir}, $basename . '.bs'); $spec->{lib_file} = File::Spec->catfile( $spec->{archdir}, $basename . '.' . $self->{config}->get('dlext')); #use Data::Dumper; print Dumper $spec; return $spec; } 1; cpanfile100644000765000024 46313045746371 15001 0ustar00gfxstaff000000000000Hash-FieldHash-0.15requires 'XSLoader', '0.02'; requires 'parent', '0.221'; requires 'perl', '5.008005'; on build => sub { requires 'Devel::PPPort', '3.19'; requires 'ExtUtils::MakeMaker', '6.59'; requires 'ExtUtils::ParseXS', '2.21'; requires 'Test::LeakTrace', '0.07'; requires 'Test::More', '0.62'; }; namedfields.pl100644000765000024 120713045746371 17555 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/example#!perl -w use strict; package MyClass; use Hash::FieldHash qw(:all); fieldhash my %foo => 'foo'; sub new{ my $class = shift; my $self = bless {}, $class; return from_hash($self, @_); } package MyDerivedClass; use parent -norequire => 'MyClass'; use Hash::FieldHash qw(:all); fieldhash my %bar => 'bar'; package main; my $o = MyDerivedClass->new(foo => 10, bar => 20); my $p = MyDerivedClass->new('MyClass::foo' => 10, 'MyDerivedClass::bar' => 20); use Data::Dumper; print Dumper($o->to_hash()); # $VAR1 = { foo => 10, bar => 20 } print Dumper($o->to_hash(-fully_qualify)); # $VAR1 = { 'MyClass::foo' => 10, 'MyDerived::bar' => 20 } simpleuse.pl100644000765000024 66713045746371 17301 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/example#!perl -w use strict; use Hash::FieldHash qw(:all); use Data::Dumper; fieldhashes \my(%foo, %bar);; { my $o = [42]; my $x = {}; $foo{$o} = 3.14; $bar{$o} = 1.14; $foo{$x} = 'x.foo'; $bar{$x} = 'x.bar'; print "inside the scope:\n"; print Data::Dumper->Dump([\%foo, \%bar], [qw(*foo *bar)]); #my $y = $o; #use Devel::Peek; Dump $y; } print "outside the scope:\n"; print Data::Dumper->Dump([\%foo, \%bar], [qw(*foo *bar)]); FieldHash.pm100644000765000024 1271613045746371 17157 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/lib/Hashpackage Hash::FieldHash; use 5.008_005; use strict; our $VERSION = '0.15'; use parent qw(Exporter); our @EXPORT_OK = qw(fieldhash fieldhashes from_hash to_hash); our %EXPORT_TAGS = (all => \@EXPORT_OK); use XSLoader; XSLoader::load(__PACKAGE__, $VERSION); sub fieldhashes{ foreach my $hash_ref(@_){ &fieldhash($hash_ref); } } 1; __END__ =for stopwords uvar CPAN rw-accessors chainable [![Build Status](https://travis-ci.org/gfx/p5-Hash-FieldHash.svg?branch=master)](https://travis-ci.org/gfx/p5-Hash-FieldHash) =head1 NAME Hash::FieldHash - Lightweight field hash for inside-out objects =head1 VERSION This document describes Hash::FieldHash version 0.15. =head1 SYNOPSIS use Hash::FieldHash qw(:all); fieldhash my %foo; fieldhashes \my(%bar, %baz); { my $o = Something->new(); $foo{$o} = 42; print $foo{$o}; # => 42 } # when $o is released, $foo{$o} is also deleted, # so %foo is empty in here. # in a class { package Foo; use Hash::FieldHash qw(:all); fieldhash my %bar, 'bar'; # make an accessor } my $obj = bless {}, 'Foo'; $obj->bar(10); # does $bar{$obj} = 10 =head1 DESCRIPTION C provides the field hash mechanism which supports the inside-out technique. You may know C. It's a very useful module, but too complex to understand the functionality and only available in 5.10. C is available for pre-5.10, but it is too slow to use. This is a better alternative to C with following features: =over 4 =item Simpler interface C provides a few functions: C and C. That's enough. =item Higher performance C is faster than C, because its internals use simpler structures. =item Relic support Although C uses a new feature introduced in Perl 5.10, I described in L, it supports Perl 5.8 using the traditional tie-hash layer. =back =head1 INTERFACE =head2 Exportable functions =over 4 =item C<< fieldhash(%hash, ?$name, ?$package) >> Creates a field hash. The first argument must be a hash. Optional I<$name> and I<$package> indicate the name of the field, which will create rw-accessors, using the same name as I<$name>. Returns nothing. =item C<< fieldhashes(@hash_refs) >> Creates a number of field hashes. All the arguments must be hash references. Returns nothing. =item C<< from_hash($object, \%fields) >> Fills the named fields associated with I<$object> with I<%fields>. The keys of I<%fields> can be simple or fully qualified. Returns I<$object>. =item C<< to_hash($object, ?-fully_qualify) >> Serializes I<$object> into a hash reference. If the C<-fully_qualify> option is supplied , field keys are fully qualified. For example: package MyClass; use FieldHash qw(:all); fieldhash my %foo => 'foo'; sub new{ my $class = shift; my $self = bless {}, $class; return from_hash($self, @_); } package MyDerivedClass; use parent -norequire => 'MyClass'; use FieldHash qw(:all); fieldhash my %bar => 'bar'; package main; my $o = MyDerivedClass->new(foo => 10, bar => 20); my $p = MyDerivedClass->new('MyClass::foo' => 10, 'MyDerivedClass::bar' => 20); use Data::Dumper; print Dumper($o->to_hash()); # $VAR1 = { foo => 10, bar => 20 } print Dumper($o->to_hash(-fully_qualify)); # $VAR1 = { 'MyClass::foo' => 10, 'MyDerived::bar' => 20 } =back =head1 ROBUSTNESS =head2 Thread support As C does, C fully supports threading using the C method. =head2 Memory leaks C itself does not leak memory, but it may leak memory when you uses hash references as field hash keys because of an issue of perl 5.10.0. =head1 NOTES =head2 The type of field hash keys C accepts only references and registered addresses as its keys, whereas C accepts any type of scalars. According to L, Non-reference keys in C are used for class fields. That is, all the fields defined by C act as both object fields and class fields by default. It seems confusing; if you do not want them to be class fields, you must check the type of I<$self> explicitly. In addition, these class fields are never inherited. This behavior seems problematic, so C restricts the type of keys. =head2 The ID of field hash keys While C uses C as the IDs of field hash keys, C allocates arbitrary integers as the IDs. =head2 What accessors return The accessors C creates are B accessors. That is, it returns the I<$object> (i.e. C<$self>) with a parameter, where as it returns the I<$value> without it. For example: my $o = YourClass->new(); $o->foo(42); # returns $o itself my $value = $o->foo(); # retuns 42 =head1 DEPENDENCIES Perl 5.8.5 or later, and a C compiler. =head1 BUGS No bugs have been reported. Please report any bugs or feature requests to the author. =head1 SEE ALSO L. L. L. L describes the inside-out technique. =head1 AUTHOR Fuji, Goro (gfx) Egfuji(at)cpan.orgE. =head1 LICENSE AND COPYRIGHT Copyright (c) 2009-2010, Fuji, Goro. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut minil.toml100644000765000024 11113045746371 15270 0ustar00gfxstaff000000000000Hash-FieldHash-0.15module_maker = "ModuleBuild" [build] build_class = "builder::MyBuilder" FieldHash.xs100644000765000024 3110513045746371 16324 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/src#define NEED_newSV_type #include "xshelper.h" #include "mgx.h" #define NEED_mro_get_linear_isa #include "mro_compat.h" #ifndef HvNAMELEN_get #define HvNAMELEN_get(stash) strlen(HvNAME_get(stash)) #endif #if PERL_BCDVERSION < 0x5010000 #define HF_USE_TIE TRUE #endif #define PACKAGE "Hash::FieldHash" #ifdef HF_USE_TIE #include "compat58.h" #endif #define OBJECT_REGISTRY_KEY PACKAGE "::" "::META" #define NAME_REGISTRY_KEY OBJECT_REGISTRY_KEY #define INVALID_OBJECT "Invalid object \"%"SVf"\" as a fieldhash key" #define MY_CXT_KEY PACKAGE "::_guts" XS_VERSION typedef struct { AV* object_registry; /* the global object registry */ I32 last_id; /* the last allocated id */ SV* free_id; /* the top of the linked list */ HV* name_registry; bool name_registry_is_stale; } my_cxt_t; START_MY_CXT #define ObjectRegistry (MY_CXT.object_registry) #define LastId (MY_CXT.last_id) #define FreeId (MY_CXT.free_id) #define NameRegistry (MY_CXT.name_registry) #define NameRegistryIsStale (MY_CXT.name_registry_is_stale) static int fieldhash_key_free(pTHX_ SV* const sv, MAGIC* const mg); static MGVTBL fieldhash_key_vtbl = { NULL, /* get */ NULL, /* set */ NULL, /* len */ NULL, /* clear */ fieldhash_key_free, NULL, /* copy */ NULL, /* dup */ #ifdef MGf_LOCAL NULL, /* local */ #endif }; #define fieldhash_key_mg(sv) MgFind(sv, &fieldhash_key_vtbl) #ifndef HF_USE_TIE static I32 fieldhash_watch(pTHX_ IV const action, SV* const fieldhash); static struct ufuncs fieldhash_ufuncs = { fieldhash_watch, /* uf_val */ NULL, /* uf_set */ 0, /* uf_index */ }; #define fieldhash_mg(sv) hf_fieldhash_mg(aTHX_ sv) static MAGIC* hf_fieldhash_mg(pTHX_ SV* const sv){ MAGIC* mg; assert(sv != NULL); for(mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic){ if(((struct ufuncs*)mg->mg_ptr) == &fieldhash_ufuncs){ break; } } return mg; } static SV* fieldhash_fetch(pTHX_ HV* const fieldhash, SV* const key){ HE* const he = hv_fetch_ent(fieldhash, key, FALSE, 0U); return he ? HeVAL(he) : &PL_sv_undef; } static void fieldhash_store(pTHX_ HV* const fieldhash, SV* const key, SV* const val){ (void)hv_store_ent(fieldhash, key, val, 0U); } #endif /* !HF_USE_TIE */ static SV* hf_new_id(pTHX_ pMY_CXT){ SV* obj_id; if(!FreeId){ obj_id = newSV_type(SVt_PVIV); sv_setiv(obj_id, ++LastId); } else{ obj_id = FreeId; FreeId = INT2PTR(SV*, SvIVX(obj_id)); /* next node */ (void)sv_2iv(obj_id); } return obj_id; } static void hf_free_id(pTHX_ pMY_CXT_ SV* const obj_id){ assert(SvTYPE(obj_id) >= SVt_PVIV); SvIV_set(obj_id, PTR2IV(FreeId)); SvIOK_off(obj_id); FreeId = obj_id; } static SV* hf_av_find(pTHX_ AV* const av, SV* const sv){ SV** const ary = AvARRAY(av); I32 const len = AvFILLp(av)+1; I32 i; for(i = 0; i < len; i++){ if(ary[i] == sv){ return sv; } } return NULL; } /* defined actions (in 5.10.0) are: HV_FETCH_ISSTORE = 0x04 HV_FETCH_ISEXISTS = 0x08 HV_FETCH_LVALUE = 0x10 HV_FETCH_JUST_SV = 0x20 HV_DELETE = 0x40 */ #define HF_CREATE_KEY(a) (a & (HV_FETCH_ISSTORE | HV_FETCH_LVALUE)) static I32 fieldhash_watch(pTHX_ IV const action, SV* const fieldhash){ MAGIC* const mg = fieldhash_mg(fieldhash); SV* obj_ref; SV* obj; const MAGIC* key_mg; AV* reg; /* field registry */ assert(mg != NULL); obj_ref = mg->mg_obj; /* the given hash key */ if(!SvROK(obj_ref)){ /* it can be an object ID */ if(!looks_like_number(obj_ref)){ /* looks like an ID? */ Perl_croak(aTHX_ INVALID_OBJECT, obj_ref); } if(!HF_CREATE_KEY(action)){ /* fetch, exists, delete */ return 0; } else{ /* store, lvalue fetch */ dMY_CXT; SV** const svp = av_fetch(ObjectRegistry, (I32)SvIV(obj_ref), FALSE); if(!svp){ Perl_croak(aTHX_ INVALID_OBJECT, obj_ref); } /* retrieve object from ID */ assert(SvIOK(*svp)); obj = INT2PTR(SV*, SvIVX(*svp)); obj_ref = NULL; } } else{ obj = SvRV(obj_ref); } assert(!SvIS_FREED(obj)); key_mg = fieldhash_key_mg(obj); if(!key_mg){ /* first access */ if(!HF_CREATE_KEY(action)){ /* fetch, exists, delete */ /* replace the key with a sv that is not a registered ID */ mg->mg_obj = &PL_sv_no; return 0; } else{ /* store, lvalue fetch */ dMY_CXT; SV* const obj_id = hf_new_id(aTHX_ aMY_CXT); SV* const obj_weakref = newSViv(PTR2IV(obj)); av_store(ObjectRegistry, (I32)SvIVX(obj_id), obj_weakref); mg->mg_obj = obj_id; /* key replacement */ reg = newAV(); /* field registry for obj */ key_mg = sv_magicext( obj, (SV*)reg, PERL_MAGIC_ext, &fieldhash_key_vtbl, (char*)obj_id, HEf_SVKEY ); SvREFCNT_dec(reg); /* refcnt++ in sv_magicext() */ } } else{ /* key_mg->mg_ptr is obj_id */ mg->mg_obj = (SV*)key_mg->mg_ptr; /* key replacement */ if(!HF_CREATE_KEY(action)){ return 0; } reg = (AV*)key_mg->mg_obj; assert(SvTYPE(reg) == SVt_PVAV); } /* add a new fieldhash to the field registry if needed */ if(!hf_av_find(aTHX_ reg, (SV*)fieldhash)){ av_push(reg, (SV*)SvREFCNT_inc_simple_NN(fieldhash)); } return 0; } static int fieldhash_key_free(pTHX_ SV* const sv, MAGIC* const mg){ PERL_UNUSED_ARG(sv); //warn("key_free(sv=0x%p, mg=0x%p, id=%"SVf")", sv, mg, (SV*)mg->mg_ptr); /* Does nothing during global destruction, because some data may have been released. */ if(!PL_dirty){ dMY_CXT; AV* const reg = (AV*)mg->mg_obj; /* field registry */ SV* const obj_id = (SV*)mg->mg_ptr; I32 const len = AvFILLp(reg)+1; I32 i; assert(SvTYPE(reg) == SVt_PVAV); /* delete $fieldhash{$obj} for each fieldhash */ for(i = 0; i < len; i++){ HV* const fieldhash = (HV*)AvARRAY(reg)[i]; assert(SvTYPE(fieldhash) == SVt_PVHV); /* NOTE: Don't use G_DISCARD, because it may cause a double-free problem (t/11_panic_malloc.t). */ (void)hv_delete_ent(fieldhash, obj_id, 0, 0U); } av_delete(ObjectRegistry, (I32)SvIVX(obj_id), G_DISCARD); hf_free_id(aTHX_ aMY_CXT_ obj_id); } return 0; } MGVTBL hf_accessor_vtbl; XS(XS_Hash__FieldHash_accessor); XS(XS_Hash__FieldHash_accessor){ dVAR; dXSARGS; SV* const obj_ref = ST(0); MAGIC* const mg = mg_find_by_vtbl((SV*)cv, &hf_accessor_vtbl); HV* const fieldhash = (HV*)mg->mg_obj; if(items < 1 || !SvROK(obj_ref)){ Perl_croak(aTHX_ "The %s() method must be called as an instance method", GvNAME(CvGV(cv))); } if(items > 2){ Perl_croak(aTHX_ "Cannot set a list of values to \"%s\"", GvNAME(CvGV(cv))); } if(items == 1){ /* get */ ST(0) = fieldhash_fetch(aTHX_ fieldhash, obj_ref); } else{ /* set */ fieldhash_store(aTHX_ fieldhash, obj_ref, newSVsv(ST(1))); /* returns self */ } XSRETURN(1); } static HV* hf_get_named_fields(pTHX_ HV* const stash, const char** const pkg_ptr, I32* const pkglen_ptr){ dMY_CXT; const char* const pkg = HvNAME_get(stash); I32 const pkglen = HvNAMELEN_get(stash); SV** const svp = hv_fetch(NameRegistry, pkg, pkglen, FALSE); HV* fields; if(!svp){ fields = newHV(); (void)hv_store(NameRegistry, pkg, pkglen, newRV_noinc((SV*)fields), 0U); NameRegistryIsStale = TRUE; } else{ assert(SvROK(*svp)); fields = (HV*)SvRV(*svp); assert(SvTYPE(fields) == SVt_PVHV); } if(NameRegistryIsStale){ AV* const isa = mro_get_linear_isa(stash); I32 const len = AvFILLp(isa)+1; I32 i; for(i = 1 /* skip this class */; i < len; i++){ HE* const he = hv_fetch_ent(NameRegistry, AvARRAY(isa)[i], FALSE, 0U); HV* const base_fields = he && SvROK(HeVAL(he)) ? (HV*)SvRV(HeVAL(he)) : NULL; if(base_fields){ char* key; I32 keylen; SV* val; hv_iterinit(base_fields); while((val = hv_iternextsv(base_fields, &key, &keylen))){ (void)hv_store(fields, key, keylen, newSVsv(val), 0U); } } } } if(pkg_ptr) *pkg_ptr = pkg; if(pkglen_ptr) *pkglen_ptr = pkglen; return fields; } static void hf_add_field(pTHX_ HV* const fieldhash, SV* const name, SV* const package){ if(name){ dMY_CXT; HV* const stash = package ? gv_stashsv(package, TRUE) : CopSTASH(PL_curcop); I32 pkglen; const char* pkg; HV* const fields = hf_get_named_fields(aTHX_ stash, &pkg, &pkglen); STRLEN namelen; const char* namepv = SvPV_const(name, namelen); CV* xsub; if(hv_exists_ent(fields, name, 0U) && ckWARN(WARN_REDEFINE)){ Perl_warner(aTHX_ packWARN(WARN_REDEFINE), "field \"%"SVf"\" redefined or overridden", name); } (void)hv_store_ent(fields, name, newRV_inc((SV*)fieldhash), 0U); namepv = Perl_form(aTHX_ "%s::%s", pkg, namepv); /* fully qualified name */ namelen += sizeof("::")-1 + pkglen; (void)hv_store(fields, namepv, namelen, newRV_inc((SV*)fieldhash), 0U); if(ckWARN(WARN_REDEFINE) && get_cv(namepv, 0x00)){ Perl_warner(aTHX_ packWARN(WARN_REDEFINE), "Subroutine %s redefined", namepv); } xsub = newXS( (char*)namepv, XS_Hash__FieldHash_accessor, __FILE__); sv_magicext( (SV*)xsub, (SV*)fieldhash, PERL_MAGIC_ext, &hf_accessor_vtbl, NULL, 0 ); CvMETHOD_on(xsub); NameRegistryIsStale = TRUE; } } MODULE = Hash::FieldHash PACKAGE = Hash::FieldHash PROTOTYPES: DISABLE BOOT: { MY_CXT_INIT; ObjectRegistry = get_av(OBJECT_REGISTRY_KEY, GV_ADDMULTI); NameRegistry = get_hv( NAME_REGISTRY_KEY, GV_ADDMULTI); LastId = -1; } #ifdef USE_ITHREADS void CLONE(...) CODE: MY_CXT_CLONE; ObjectRegistry = get_av(OBJECT_REGISTRY_KEY, GV_ADDMULTI); NameRegistry = get_hv( NAME_REGISTRY_KEY, GV_ADDMULTI); FreeId = NULL; PERL_UNUSED_VAR(items); #endif /* !USE_ITHREADS */ #ifndef HF_USE_TIE void fieldhash(HV* hash, SV* name = NULL, SV* package = NULL) PROTOTYPE: \%;$$ CODE: assert(SvTYPE(hash) >= SVt_PVMG); if(!fieldhash_mg((SV*)hash)){ hv_clear(hash); sv_magic((SV*)hash, NULL, /* mg_obj */ PERL_MAGIC_uvar, /* mg_type */ (char*)&fieldhash_ufuncs, /* mg_ptr as the ufuncs table */ 0 /* mg_len (0 indicates static data) */ ); hf_add_field(aTHX_ hash, name, package); } #else /* HF_USE_TIE */ INCLUDE: compat58.xsi #endif #ifdef FIELDHASH_DEBUG void _dump_internals() PREINIT: dMY_CXT; SV* obj_id; CODE: for(obj_id = FreeId; obj_id; obj_id = INT2PTR(SV*, SvIVX(obj_id))){ sv_dump(obj_id); } HV* _name_registry() PREINIT: dMY_CXT; CODE: RETVAL = NameRegistry; OUTPUT: RETVAL #endif /* !FIELDHASH_DEBUG */ void from_hash(SV* object, ...) PREINIT: const char* stashname; HV* stash; HV* fields; INIT: if(!sv_isobject(object)){ Perl_croak(aTHX_ "The %s() method must be called as an instance method", GvNAME(CvGV(cv))); } CODE: stash = SvSTASH(SvRV(object)); fields = hf_get_named_fields(aTHX_ stash, &stashname, NULL); if(items == 2){ SV* const arg = ST(1); HV* hv; char* key; I32 keylen; SV* val; if(!(SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVHV)){ Perl_croak(aTHX_ "Single parameters to %s() must be a HASH reference", GvNAME(CvGV(cv))); } hv = (HV*)SvRV(arg); hv_iterinit(hv); while((val = hv_iternextsv(hv, &key, &keylen))){ SV** const svp = hv_fetch(fields, key, keylen, FALSE); if(!(svp && SvROK(*svp))){ Perl_croak(aTHX_ "No such field \"%s\" for %s", key, stashname); } fieldhash_store(aTHX_ (HV*)SvRV(*svp), object, newSVsv(val)); } } else{ I32 i; if( ((items-1) % 2) != 0 ){ Perl_croak(aTHX_ "Odd number of parameters for %s()", GvNAME(CvGV(cv))); } for(i = 1; i < items; i += 2){ HE* const he = hv_fetch_ent(fields, ST(i), FALSE, 0U); if(!(he && SvROK(HeVAL(he)))){ Perl_croak(aTHX_ "No such field \"%s\" for %s", SvPV_nolen_const(ST(i)), stashname); } fieldhash_store(aTHX_ (HV*)SvRV(HeVAL(he)), object, newSVsv(ST(i+1))); } } XSRETURN(1); /* returns the first argument */ HV* to_hash(SV* object, ...) PREINIT: HV* stash; HV* fields; char* key; I32 keylen; SV* val; bool fully_qualify = FALSE; INIT: if(!sv_isobject(object)){ Perl_croak(aTHX_ "The %s() method must be called as an instance method", GvNAME(CvGV(cv))); } while(items > 1){ SV* const option = ST(--items); if(SvOK(option)){ if(strEQ(SvPV_nolen_const(option), "-fully_qualify")){ fully_qualify = TRUE; } else{ Perl_croak(aTHX_ "Unknown option \"%"SVf"\"", option); } } } CODE: stash = SvSTASH(SvRV(object)); fields = hf_get_named_fields(aTHX_ stash, NULL, NULL); RETVAL = newHV(); hv_iterinit(fields); while((val = hv_iternextsv(fields, &key, &keylen))){ bool const need_to_store = strchr(key, ':') ? fully_qualify : !fully_qualify; if( need_to_store && SvROK(val) ){ HV* const fieldhash = (HV*)SvRV(val); SV* const value = fieldhash_fetch(aTHX_ fieldhash, object); (void)hv_store(RETVAL, key, keylen, newSVsv(value), 0U); } } OUTPUT: RETVAL compat58.h100644000765000024 302413045746371 15711 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/src/* compat58.h */ #ifndef HV_FETCH #define HV_FETCH 0x00 #endif #ifndef HV_FETCH_ISSTORE #define HV_FETCH_ISSTORE 0x04 #define HV_FETCH_ISEXISTS 0x08 #define HV_FETCH_LVALUE 0x10 #define HV_FETCH_JUST_SV 0x20 #define HV_DELETE 0x40 #endif static MGVTBL fieldhash_vtbl; #define fieldhash_mg(sv) mg_find_by_vtbl(sv, &fieldhash_vtbl) static I32 fieldhash_watch(pTHX_ IV const action, SV* const fieldhash); static SV* hf_replace_key(pTHX_ HV* const impl, SV* key, IV const action){ MAGIC* const mg = fieldhash_mg((SV*)impl); if(!mg){ Perl_croak(aTHX_ "panic: invalid fieldhash"); } mg->mg_obj = key; fieldhash_watch(aTHX_ action, (SV*)impl); key = mg->mg_obj; mg->mg_obj = NULL; return key; } static HV* fieldhash_get_impl(pTHX_ HV* const fieldhash){ MAGIC* const tied_mg = SvTIED_mg((SV*)fieldhash, PERL_MAGIC_tied); SV* const tied_obj = SvTIED_obj((SV*)fieldhash, tied_mg); assert(sv_derived_from(tied_obj, PACKAGE)); assert(SvROK(tied_obj)); assert(SvTYPE(SvRV(tied_obj)) == SVt_PVHV); return (HV*)SvRV(tied_obj); } static SV* fieldhash_fetch(pTHX_ HV* const fieldhash, SV* const key){ HV* const impl = fieldhash_get_impl(aTHX_ fieldhash); HE* he; he = hv_fetch_ent(impl, hf_replace_key(aTHX_ impl, key, HV_FETCH), FALSE, 0U); return he ? HeVAL(he) : &PL_sv_undef; } static void fieldhash_store(pTHX_ HV* const fieldhash, SV* const key, SV* const val){ HV* const impl = fieldhash_get_impl(aTHX_ fieldhash); (void)hv_store_ent(impl, hf_replace_key(aTHX_ impl, key, HV_FETCH_ISSTORE), val, 0U); } compat58.xsi100644000765000024 312713045746371 16271 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/src# vim: set filetype=XS: void fieldhash(HV* hash, SV* name = NULL, SV* package = NULL) PROTOTYPE: \%;$ PREINIT: MAGIC* tied_mg; CODE: tied_mg = SvTIED_mg((SV*)hash, PERL_MAGIC_tied); if(!tied_mg || !sv_derived_from(SvTIED_obj((SV*)hash, tied_mg), PACKAGE)){ SV* const self = newRV_noinc((SV*)newHV()); hv_clear(hash); sv_bless(self, gv_stashpvs(PACKAGE, GV_ADD)); if(tied_mg) sv_unmagic((SV*)hash, PERL_MAGIC_tied); /* untie */ sv_magic((SV*)hash, self, PERL_MAGIC_tied, NULL, 0); /* tie */ SvREFCNT_dec(self); /* refcnt++ in sv_magic() */ sv_magicext(SvRV(self), NULL, PERL_MAGIC_ext, &fieldhash_vtbl, NULL, 0); hf_add_field(aTHX_ hash, name, package); } SV* FETCH(HV* self, SV* key, SV* val = &PL_sv_undef) ALIAS: FETCH = HV_FETCH STORE = HV_FETCH_ISSTORE EXISTS = HV_FETCH_ISEXISTS DELETE = HV_DELETE CODE: key = hf_replace_key(aTHX_ self, key, ix /* action */); switch(ix){ default:{ /* FETCH */ HE* const he = hv_fetch_ent(self, key, 0, 0U); RETVAL = he ? HeVAL(he) : NULL; break; } case HV_FETCH_ISSTORE: (void)hv_store_ent(self, key, newSVsv(val), 0U); RETVAL = val; break; case HV_FETCH_ISEXISTS: RETVAL = boolSV(hv_exists_ent(self, key, 0U)); break; case HV_DELETE: RETVAL = hv_delete_ent(self, key, 0, 0U); break; } ST(0) = RETVAL ? RETVAL : &PL_sv_undef; XSRETURN(1); void FIRSTKEY(HV* self, ...) ALIAS: FIRSTKEY = 0 NEXTKEY = 1 PREINIT: HE* he; CODE: if(ix == 0){ /* FIRSTKEY */ hv_iterinit(self); } he = hv_iternext(self); ST(0) = he ? hv_iterkeysv(he) : &PL_sv_undef; XSRETURN(1); void CLEAR(HV* self) CODE: hv_clear(self); mgx.h100644000765000024 77713045746371 15040 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/src/* mgx.h - provides extra mg functions */ #ifndef mg_find_by_vtbl #define mg_find_by_vtbl(sv, vtbl) my_mg_find_by_vtbl(aTHX_ sv, vtbl) static MAGIC* my_mg_find_by_vtbl(pTHX_ SV* const sv, const MGVTBL* const vtbl){ MAGIC* mg; assert(sv != NULL); for(mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic){ if(mg->mg_virtual == vtbl){ break; } } return mg; } /* safe version of mg_find_by_vtbl() */ #define MgFind(sv, vtbl) (SvMAGICAL(sv) ? mg_find_by_vtbl(sv, vtbl) : NULL) #endif /* !mg_find_by_vtbl */ mro_compat.h100644000765000024 765013045746371 16422 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/src/* ---------------------------------------------------------------------------- Devel::MRO/mro_compat.h - Provides mro functions for XS modules Copyright (c) 2008-2009, Goro Fuji (gfx) . This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. ---------------------------------------------------------------------------- Usage: #include "mro_compat.h" Functions: AV* mro_get_linear_isa(HV* stash) UV mro_get_pkg_gen(HV* stash) void mro_method_changed_in(HV* stash) See "perldoc Devel::MRO" for details. */ #ifdef mro_get_linear_isa /* >= 5.10.0 */ /* NOTE: Because ActivePerl 5.10.0 does not provide Perl_mro_meta_init(), which is used in HvMROMETA() macro, this mro_get_pkg_gen() refers to xhv_mro_meta directly. */ /* compatible with &mro::get_pkg_gen() */ #ifndef mro_get_pkg_gen #define mro_get_pkg_gen(stash) (HvAUX(stash) ? HvAUX(stash)->xhv_mro_meta->pkg_gen : (U32)0) #endif #ifndef mro_get_cache_gen #define mro_get_cache_gen(stash) (HvAUX(stash) ? HvAUX(stash)->xhv_mro_meta->cache_gen : (U32)0) #endif /* pkg_gen + cache_gen */ #ifndef mro_get_gen #define mro_get_gen(stash) (HvAUX(stash) ? (HvAUX(stash)->xhv_mro_meta->pkg_gen + HvAUX(stash)->xhv_mro_meta->cache_gen) : (U32)0) #endif #else /* < 5.10.0 */ #define mro_get_linear_isa(stash) my_mro_get_linear_isa(aTHX_ stash) #define mro_method_changed_in(stash) ((void)stash, (void)PL_sub_generation++) #define mro_get_pkg_gen(stash) ((void)stash, PL_sub_generation) #define mro_get_cache_gen(stash) ((void)stash, (I32)0) /* ??? */ #define mro_get_gen(stash) ((void)stash, PL_sub_generation) #if defined(NEED_mro_get_linear_isa) && !defined(NEED_mro_get_linear_isa_GLOBAL) static AV* my_mro_get_linear_isa(pTHX_ HV* const stash); static #else extern AV* my_mro_get_linear_isa(pTHX_ HV* const stash); #endif /* !NEED_mro_get_linear_isa */ #if defined(NEED_mro_get_linear_isa) || defined(NEED_mro_get_linear_isa_GLOBAL) #define ISA_CACHE "::Devel::MRO::" /* call &mro::get_linear_isa, which is actually &MRO::Compat::__get_linear_isa */ AV* my_mro_get_linear_isa(pTHX_ HV* const stash){ GV* cachegv; AV* isa; /* linearized ISA cache */ SV* gen; /* package generation */ CV* get_linear_isa; assert(stash); assert(SvTYPE(stash) == SVt_PVHV); assert(HvNAME(stash)); /* PerlIO_printf(Perl_debug_log, "mro_get_linear_isa(%s)\n", HvNAME(stash)); //*/ cachegv = *(GV**)hv_fetchs(stash, ISA_CACHE, TRUE); if(!isGV(cachegv)) gv_init(cachegv, stash, ISA_CACHE, sizeof(ISA_CACHE)-1, GV_ADD); isa = GvAVn(cachegv); #ifdef GvSVn gen = GvSVn(cachegv); #else gen = GvSV(cachegv); #endif if(SvIOK(gen) && SvIVX(gen) == (IV)mro_get_pkg_gen(stash)){ return isa; /* returns the cache if available */ } get_linear_isa = get_cv("mro::get_linear_isa", FALSE); if(!get_linear_isa){ ENTER; SAVETMPS; Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, newSVpvs("MRO::Compat"), NULL, NULL); get_linear_isa = get_cv("mro::get_linear_isa", TRUE); FREETMPS; LEAVE; } { SV* avref; dSP; ENTER; SAVETMPS; PUSHMARK(SP); mXPUSHp(HvNAME(stash), strlen(HvNAME(stash))); PUTBACK; call_sv((SV*)get_linear_isa, G_SCALAR); SPAGAIN; avref = POPs; PUTBACK; if(SvROK(avref) && SvTYPE(SvRV(avref)) == SVt_PVAV){ AV* const av = (AV*)SvRV(avref); I32 const len = AvFILLp(av) + 1; I32 i; SvREADONLY_off(isa); av_fill(isa, len-1); for(i = 0; i < len; i++){ HV* const st = gv_stashsv(AvARRAY(av)[i], TRUE); /* to normalize the stash name */ SV* const sv = *av_fetch(isa, i, TRUE); sv_setpv(sv, HvNAME(st)); } SvREADONLY_on(isa); } else{ Perl_croak(aTHX_ "panic: mro::get_linear_isa() didn't return an ARRAY reference"); } FREETMPS; LEAVE; } sv_setiv(gen, (IV)mro_get_pkg_gen(stash)); return isa; } #undef ISA_CACHE #endif /* !(defined(NEED_mro_get_linear_isa) || defined(NEED_mro_get_linear_isa_GLOBAL)) */ #endif /* end of the file */ xshelper.h100644000765000024 453213045746371 16110 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/src/* THIS FILE IS AUTOMATICALLY GENERATED BY Module::Install::XSUtil 0.43. */ /* =head1 NAME xshelper.h - Helper C header file for XS modules =head1 DESCRIPTION // This includes all the perl header files and ppport.h #include "xshelper.h" =head1 SEE ALSO L, where this file is distributed as a part of =head1 AUTHOR Fuji, Goro (gfx) Egfuji at cpan.orgE =head1 LISENCE Copyright (c) 2010, Fuji, Goro (gfx). All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut */ #ifdef __cplusplus extern "C" { #endif #define PERL_NO_GET_CONTEXT /* we want efficiency */ #include #include #define NO_XSLOCKS /* for exceptions */ #include #ifdef __cplusplus } /* extern "C" */ #endif #include "ppport.h" /* portability stuff not supported by ppport.h yet */ #ifndef STATIC_INLINE /* from 5.13.4 */ # if defined(__GNUC__) || defined(__cplusplus) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) # define STATIC_INLINE static inline # else # define STATIC_INLINE static # endif #endif /* STATIC_INLINE */ #ifndef __attribute__format__ #define __attribute__format__(a,b,c) /* nothing */ #endif #ifndef LIKELY /* they are just a compiler's hint */ #define LIKELY(x) (!!(x)) #define UNLIKELY(x) (!!(x)) #endif #ifndef newSVpvs_share #define newSVpvs_share(s) Perl_newSVpvn_share(aTHX_ STR_WITH_LEN(s), 0U) #endif #ifndef get_cvs #define get_cvs(name, flags) get_cv(name, flags) #endif #ifndef GvNAME_get #define GvNAME_get GvNAME #endif #ifndef GvNAMELEN_get #define GvNAMELEN_get GvNAMELEN #endif #ifndef CvGV_set #define CvGV_set(cv, gv) (CvGV(cv) = (gv)) #endif /* general utility */ #if PERL_BCDVERSION >= 0x5008005 #define LooksLikeNumber(x) looks_like_number(x) #else #define LooksLikeNumber(x) (SvPOKp(x) ? looks_like_number(x) : (I32)SvNIOKp(x)) #endif #define newAV_mortal() (AV*)sv_2mortal((SV*)newAV()) #define newHV_mortal() (HV*)sv_2mortal((SV*)newHV()) #define newRV_inc_mortal(sv) sv_2mortal(newRV_inc(sv)) #define newRV_noinc_mortal(sv) sv_2mortal(newRV_noinc(sv)) #define DECL_BOOT(name) EXTERN_C XS(CAT2(boot_, name)) #define CALL_BOOT(name) STMT_START { \ PUSHMARK(SP); \ CALL_FPTR(CAT2(boot_, name))(aTHX_ cv); \ } STMT_END 00_load.t100644000765000024 21113045746371 15132 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use Test::More tests => 1; BEGIN { use_ok 'Hash::FieldHash' } diag "Hash::FieldHash/$Hash::FieldHash::VERSION"; 01_basic.t100644000765000024 250013045746371 15320 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use Test::More tests => 24; #use Hash::Util::FieldHash::Compat qw(fieldhash fieldhashes); use Hash::FieldHash qw(:all); fieldhash my %hash; fieldhash our %ghash; ok !scalar(%hash); my $r = {}; $hash{$r} = 'r'; $ghash{$r} = 'g'; ok scalar(%hash); is_deeply [values %hash], ['r']; is_deeply [values %ghash], ['g']; { my $o = bless {foo => 'bar'}; my $x = ['baz']; $hash{$o} = 10; is $hash{$o}, 10; $hash{$x} = 42; is $hash{$o}, 10; is $hash{$x}, 42; $ghash{$o} = 10; $ghash{$x} = 42; is_deeply [sort values %hash], [sort('r', 10, 42)]; is_deeply [sort values %ghash], [sort('g', 10, 42)]; is_deeply $o, {foo => 'bar'}; is_deeply $x, ['baz']; is ref($o), __PACKAGE__; is ref($x), 'ARRAY'; } is_deeply [values %hash], ['r']; is_deeply [values %ghash], ['g']; { my $o = bless {}; $hash{$o} = 10; is $hash{$o}, 10; $hash{$o}++; is $hash{$o}, 11; } is_deeply [values %hash], ['r']; is_deeply [values %ghash], ['g']; undef $r; is_deeply \%hash, {}; is_deeply \%ghash, {}; { my %hash = (foo => 'bar'); fieldhash %hash; is_deeply \%hash, {}; } eval{ my %hash; foreach (1 .. 10){ fieldhash %hash; } }; is $@, ''; my $o = do{ fieldhash my %hash; bless \%hash }; is ref($o), __PACKAGE__; #use Data::Dumper; #print Dumper *{$Hash::FieldHash::{'::OBJECT_REGISTRY'}}{ARRAY}; 02_class.t100644000765000024 156313045746371 15355 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use Test::More tests => 10; use Hash::FieldHash qw(:all); BEGIN{ package InsideOut; use Hash::FieldHash qw(fieldhashes); fieldhashes \my(%foo, %bar); sub new{ bless {}, shift; } sub foo{ my $self = shift; $foo{$self} = shift if @_; return $foo{$self}; } sub bar{ my $self = shift; $bar{$self} = shift if @_; return $bar{$self}; } sub registry{ [\(%foo, %bar)]; } } my $registry = InsideOut->registry(); is_deeply $registry, [{}, {}]; { my $x = InsideOut->new(); my $y = InsideOut->new(); $x->foo(42); is $x->foo, 42; is $x->bar, undef; is $y->foo, undef; is $y->bar, undef; $x->foo('x.foo'); $x->bar('x.bar'); $y->foo('y.foo'); $y->bar('y.bar'); is $x->foo, 'x.foo'; is $x->bar, 'x.bar'; is $y->foo, 'y.foo'; is $y->bar, 'y.bar'; } #use Data::Dumper; diag(Dumper $registry); is_deeply $registry, [{}, {}]; 03_touch.t100644000765000024 53413045746371 15350 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use Test::More tests => 10; use Hash::FieldHash qw(:all); fieldhash my %hash; my $r = {}; ok !delete $hash{$r}; is_deeply \%hash, {}; ok !exists $hash{$r}; is_deeply \%hash, {}; ok !$hash{$r}; is_deeply \%hash, {}; my $dummy = $hash{$r}; is_deeply \%hash, {}; ok !delete $hash{1}; ok !exists $hash{1}; ok !$hash{1}; 04_copy.t100644000765000024 135413045746371 15222 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use Test::More tests => 12; #use Hash::Util::FieldHash::Compat qw(:all); use Hash::FieldHash qw(:all); fieldhashes \my(%a, %b, %c); { my $o = {}; my $p = {}; $a{$o} = 42; $a{$p} = 3.14; %b = %a; is_deeply [sort values %a], [sort 42, 3.14]; is_deeply [sort values %b], [sort 42, 3.14]; $a{$o}++; is_deeply [sort values %a], [sort 43, 3.14]; is_deeply [sort values %b], [sort 42, 3.14]; %b = %a; is_deeply [sort values %a], [sort 43, 3.14]; is_deeply [sort values %b], [sort 43, 3.14]; %c = %b; is_deeply [sort values %c], [sort 43, 3.14]; %c = (); is_deeply [sort values %a], [sort 43, 3.14]; is_deeply [sort values %b], [sort 43, 3.14]; is_deeply \%c, {}; } is_deeply \%a, {}; is_deeply \%b, {}; 05_threads.t100644000765000024 237213045746371 15704 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use constant HAS_THREADS => eval{ require threads }; use Test::More; BEGIN{ if(HAS_THREADS){ plan tests => 15*3; } else{ plan skip_all => 'require threads'; } } use threads; #use Hash::Util::FieldHash::Compat qw(:all); use Hash::FieldHash qw(:all); for(1 .. 3){ fieldhashes \my(%a, %b); { my $x = {}; my $y = {}; $a{$x} = 'a-x'; $a{$y} = 'a-y'; $b{$x} = 'b-x'; $b{$y} = 'b-y'; my $thr = async { is $a{$x}, 'a-x'; is $a{$y}, 'a-y'; is $b{$x}, 'b-x'; is $b{$y}, 'b-y'; my $thr1 = async{ is $a{$x}, 'a-x'; threads->yield(); $a{$x} = 3.14; threads->yield(); is $a{$x}, 3.14; }; my $thr2 = async{ fieldhash my %c; my $z = []; $c{$x} = $a{$x}; $c{$z} = 'c-z'; $a{$x}++; $b{$x}++; is_deeply [sort values %c], [sort qw(a-x c-z)]; }; threads->yield(); is $a{$x}, 'a-x'; my $z = {}; threads->yield(); is $a{$x}, 'a-x'; $a{$z} = 42; is $a{$z}, 42; $thr1->join(); $thr2->join(); }; ok $thr, sprintf 'count=%d, tid=%d', $_, $thr->tid; $thr->yield; is_deeply [sort values %a], [sort 'a-x', 'a-y']; $thr->join; is_deeply [sort values %a], [sort 'a-x', 'a-y']; } is_deeply \%a, {}; is_deeply \%b, {}; } 06_ensure_released.t100644000765000024 111313045746371 17410 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use Test::More tests => 4; #use Hash::Util::FieldHash::Compat qw(fieldhash fieldhashes); use Hash::FieldHash qw(:all); my $count = 0; { package CountedObject; sub new{ $count++; return bless {}, shift } sub DESTROY{ $count-- } } fieldhash my %a; { my $o = {}; $a{$o} = CountedObject->new; delete $a{$o}; is $count, 0, 'field is released'; $o = CountedObject->new; $a{$o}++; delete $a{$o}; undef $o; is $count, 0, 'key object is released'; $o = CountedObject->new; $a{$o} = CountedObject->new; } is_deeply \%a, {}; is $count, 0, 'finished'; 07_local.t100644000765000024 46013045746371 15322 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use Test::More tests => 2; #use Hash::Util::FieldHash::Compat qw(fieldhash fieldhashes); use Hash::FieldHash qw(:all); fieldhash my %hash; { my $o = {}; $hash{$o} = 42; { local $hash{$o} = 'localized'; is_deeply [values %hash], ['localized']; } is $hash{$o}, 42; } 08_overload.t100644000765000024 61513045746371 16046 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use Test::More tests => 4; #use Hash::Util::FieldHash::Compat qw(fieldhash fieldhashes); use Hash::FieldHash qw(:all); { package T; use overload '""' => sub{ die 'stringify' }; sub new{ bless {}, @_ } } fieldhash my %hash; ok !exists $hash{T->new}; is_deeply \%hash, {}; { my $t = T->new; $hash{$t} = 42; is_deeply [values %hash], [42]; } is_deeply \%hash, {}; 09_magic.t100644000765000024 100113045746371 15322 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use constant HUF => eval{ require Hash::Util::FieldHash }; use Test::More HUF ? (tests => 8) : (skip_all => 'require Hash::Util::FieldHash'); use Hash::FieldHash; Hash::FieldHash::fieldhash my %x; Hash::Util::FieldHash::fieldhash my %y; { my $o = []; $x{$o} = 100; $y{$o} = 200; is_deeply [values %x], [100]; is_deeply [values %y], [200]; is $x{$o}, 100; is $y{$o}, 200; $x{$o}++; $y{$o}++; is $x{$o}, 101; is $y{$o}, 201; } is_deeply \%x, {}; is_deeply \%y, {}; 10_bad_use.t100644000765000024 100513045746371 15640 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use Test::More tests => 8; #use Hash::Util::FieldHash::Compat qw(fieldhash fieldhashes); use Hash::FieldHash qw(:all); fieldhash my %hash; eval{ $hash{foo}++; }; ok $@; eval{ $hash{1}++; }; ok $@; eval{ my $o = {}; $hash{"$o"}++; }; ok $@; eval{ exists $hash{foo}; }; ok $@; eval{ my $x = $hash{foo}; }; ok $@; eval{ delete $hash{foo}; }; ok $@; eval{ fieldhashes []; }; ok $@; my $o = {foo => 'bar'}; { fieldhash my %hash; $hash{$o} = 42; } is_deeply $o, {foo => 'bar'}; 11_panic_malloc.t100644000765000024 173513045746371 16672 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w # fix "panic: malloc" error in fieldhash_key_free() use strict; use constant HAS_WEAKEN => eval { require Scalar::Util; Scalar::Util->import('weaken'); return 1; }; use if !HAS_WEAKEN, 'Test::More' => 'skip_all', 'missing weaken()'; use Test::More tests => 2; BEGIN{ package Hook::Finalizer; use Hash::FieldHash qw(:all); use Scalar::Util qw(weaken); fieldhash my %finalizers_of; sub add_finalizer{ my $ref = shift; my $code = shift; my $finalizers_ref = $finalizers_of{$ref} ||= bless []; unshift @_, $code, $ref; unshift @{$finalizers_ref}, \@_; # $code, $ref, @args weaken $_[1]; # $ref return $ref; } sub DESTROY{ my($finalizers_ref) = @_; foreach my $finalizer (@{$finalizers_ref}){ my $code = shift @{$finalizer}; $code->(@{$finalizer}); } } } use Scalar::Util qw(weaken); { my $a = [42]; my $b = $a; weaken $b; Hook::Finalizer::add_finalizer $a => sub{ my @a = @_; pass 'in finalizer'; }; } pass 'scope out'; 12_leaktrace.t100644000765000024 146213045746371 16202 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use constant HAS_LEAKTRACE => eval q{use Test::LeakTrace 0.07; 1}; use Test::More HAS_LEAKTRACE ? (tests => 5) : (skip_all => 'require Test::LeakTrace'); use Hash::FieldHash qw(:all); my %hash; { package A; use Hash::FieldHash qw(:all); fieldhash %hash, 'foo'; sub new{ my $class = shift; my $obj = bless do{ \my $o }, $class; return Hash::FieldHash::from_hash($obj, {@_}); } } no_leaks_ok{ my $x = A->new(); my $y = A->new(); $hash{$x} = 'Hello'; $hash{$y} = 0.5; $hash{$y}++ for 1 .. 10; }; is_deeply \%hash, {}; no_leaks_ok{ my $x = A->new(foo => 10); my $y = A->new(foo => 100); $x->foo($x->foo+1); $y->foo($y->foo+1); }; is_deeply \%hash, {}; no_leaks_ok{ fieldhash my %h; for(1){ my $o = [42]; my $p = [3.14]; $h{$o} = 100; $h{$p} = 200; } }; 13_leaktrace_thr.t100644000765000024 125113045746371 17054 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use constant HAS_THREADS => eval q{ use threads; 1 }; use constant HAS_LEAKTRACE => eval q{use Test::LeakTrace 0.06; 1}; use Test::More; BEGIN{ if(HAS_THREADS && HAS_LEAKTRACE){ plan tests => 2; } else{ plan skip_all => 'require both threads and Test::LeakTrace'; } } use Hash::FieldHash qw(:all); { package A; sub new{ bless [], shift; } } fieldhash my %hash; leaks_cmp_ok{ # NOTE: weaken({}) leaks an AV in 5.10.0, so I use [] in here. my $x = A->new(); my $y = A->new(); $hash{$x} = 'Hello'; $hash{$y} = 42; $hash{$y}++ for 1 .. 10; async{ my $z = ['thx']; $hash{$z}++; }->join(); } '<=', 1; is_deeply \%hash, {}; 14_named.t100644000765000024 332713045746371 15337 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use Test::More tests => 24; sub XXX{ require Data::Dumper; diag(Data::Dumper::Dumper(@_)); } BEGIN{ package InsideOut; use Hash::FieldHash qw(:all); fieldhash my %foo, 'foo'; fieldhash my %bar, 'bar'; sub new{ my $class = shift; my $obj = bless do{ \my $o }, $class; return from_hash($obj, @_); } sub registry{ [\(%foo, %bar)]; } } my $registry = InsideOut->registry(); is_deeply $registry, [{}, {}]; { my $x = InsideOut->new(); my $y = InsideOut->new(); isa_ok $x, 'InsideOut'; isa_ok $y, 'InsideOut'; $x->foo(42); is $x->foo, 42 or XXX(InsideOut->registry); is $x->bar, undef; is $y->foo, undef; is $y->bar, undef; $x->foo('x.foo'); $x->bar('x.bar'); $y->foo('y.foo'); $y->bar('y.bar'); is $x->foo, 'x.foo'; is $x->bar, 'x.bar'; is $y->foo, 'y.foo'; is $y->bar, 'y.bar'; is_deeply $x->to_hash, { foo => 'x.foo', bar => 'x.bar' }; is_deeply $y->to_hash, { foo => 'y.foo', bar => 'y.bar' }; } { my $x = InsideOut->new(foo => 42, bar => 52); my $y = InsideOut->new(foo => 10, bar => 20); is_deeply $x->to_hash, { foo => 42, bar => 52 } or XXX($x->dump); is_deeply $y->to_hash, { foo => 10, bar => 20 } or XXX($x->dump); } is_deeply $registry, [{}, {}]; eval{ InsideOut->new([]); }; like $@, qr/must be a HASH reference/; eval{ InsideOut->new(1, 2, 3); }; like $@, qr/Odd number of parameters/; eval{ InsideOut->new(xxx => 42); }; like $@, qr/No such field "xxx"/; eval{ InsideOut->new({xxx => 42}); }; like $@, qr/No such field "xxx"/; eval{ InsideOut->foo; }; like $@, qr/The foo\(\) method must be called as an instance method/; eval{ Hash::FieldHash::from_hash([]); }; ok $@; eval{ Hash::FieldHash::to_hash([]); }; ok $@; is_deeply $registry, [{}, {}]; 15_named_inherit.t100644000765000024 267213045746371 17064 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w use strict; use Test::More tests => 8; use constant VERBOSE => !!$ENV{TEST_VERBOSE}; sub XXX{ require Data::Dumper; my $ddx = Data::Dumper->new(\@_); $ddx->Indent(1); $ddx->Sortkeys(1); diag($ddx->Dump); } BEGIN{ package A; use Hash::FieldHash qw(:all); fieldhash my %foo, 'foo'; fieldhash my %bar, 'bar'; sub new{ my $class = shift; my $obj = bless do{ \my $o }, $class; return Hash::FieldHash::from_hash($obj, @_); } sub dump{ my($self, $fully_qualify) = @_; return $self->to_hash($fully_qualify ? -fully_qualify : undef); } package B; use Hash::FieldHash qw(:all); our @ISA = qw(A); fieldhash my %baz, 'baz'; package C; use Hash::FieldHash qw(:all); our @ISA = qw(B); } { my $x = B->new('A::foo' => 10, 'A::bar' => 20, 'B::baz' => 30); is_deeply $x->dump, { foo => 10, bar => 20, baz => 30 }; is_deeply $x->dump(1), { 'A::foo' => 10, 'A::bar' => 20, 'B::baz' => 30 }; } { my $x = C->new('A::foo' => 10, 'A::bar' => 20, 'B::baz' => 30); is_deeply $x->dump, { foo => 10, bar => 20, baz => 30 }; is_deeply $x->dump(1), { 'A::foo' => 10, 'A::bar' => 20, 'B::baz' => 30 }; is_deeply $x->dump(0), C->new($x->dump(0))->dump(0); is_deeply $x->dump(0), C->new($x->dump(1))->dump(0); is_deeply $x->dump(1), C->new($x->dump(0))->dump(1); is_deeply $x->dump(1), C->new($x->dump(1))->dump(1); } if(VERBOSE){ if(defined &Hash::FieldHash::_name_registry){ XXX( Hash::FieldHash::_name_registry() ); } } 16_redefine.t100644000765000024 52513045746371 16013 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl -w # for RT #52073 use strict; use Test::More tests => 2; eval { package Foo; use Hash::FieldHash qw(:all); use warnings FATAL => 'redefine'; fieldhash my %marine => 'marine'; sub new { bless {}, shift } sub marine { 42 } }; like $@, qr/Subroutine .+ redefined/xms; my $o = Foo->new; is $o->marine, 42; 17_overload.t100644000765000024 124613045746371 16067 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t#!perl # https://rt.cpan.org/Public/Bug/Display.html?id=58030 use strict; use warnings; use Test::More; use if $] < 5.010_000, 'Test::More', skip_all => 'Perl 5.8.8 triggers stringification'; my $stringified = 0; { package Foo; use overload '""' => \&stringify; sub new { bless {}, shift @_ }; sub stringify { #use Carp qw(cluck); cluck "stringified"; $stringified++; 'foo'; }; } use Hash::FieldHash qw[ fieldhash ]; fieldhash my %h; my $x = Foo->new; my $y = Foo->new; $h{$x} = 'X'; $h{$y} = 'Y'; #use Data::Dumper; print Dumper \%h; is $h{$x}, 'X'; is $h{$y}, 'Y'; is $stringified, 0, 'not stringified'; done_testing; 02_function.t100644000765000024 1027513045746371 17055 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t/orig#!perl -w # This test originally comes from the Hash-Util-FieldHash distribution use strict; use Test::More tests => 41; use Hash::FieldHash qw(:all); ######################### # define ref types to use with some tests my @test_types; BEGIN { # skipping CODE refs, they are differently scoped @test_types = qw( SCALAR ARRAY HASH GLOB); } ### existence/retrieval/deletion { no warnings 'misc'; my $val = 123; fieldhash my %h; for ( [ ref => {}] ) { my ( $keytype, $key) = @$_; $h{ $key} = $val; ok( exists $h{ $key}, "existence ($keytype)"); is( $h{ $key}, $val, "retrieval ($keytype)"); delete $h{ $key}; is( keys %h, 0, "deletion ($keytype)"); } } ### id-action (stringification independent of bless) { my( %f, %g, %h, %i); fieldhashes \(%f, %g); my $val = 123; my $key = []; $f{ $key} = $val; is( $f{ $key}, $val, "plain key set in field"); bless $key; is( $f{ $key}, $val, "access through blessed"); $key = []; $h{ $key} = $val; is( $h{ $key}, $val, "plain key set in hash"); bless $key; isnt( $h{ $key}, $val, "no access through blessed"); } { my %h; fieldhash %h; $h{ []} = 123; is( keys %h, 0, "blip"); } for my $preload ( [], [ map {}, 1 .. 3] ) { my $pre = @$preload ? ' (preloaded)' : ''; my %f; fieldhash %f; my @preval = map "$_", @$preload; @f{ @$preload} = @preval; # Garbage collection separately for my $type ( @test_types) { { my $ref = gen_ref( $type); $f{ $ref} = $type; my ( $val) = grep $_ eq $type, values %f; is( $val, $type, "$type visible$pre"); } is( keys %f, @$preload, "$type gone$pre"); } # Garbage collection collectively { my @refs = map gen_ref( $_), @test_types; @f{ @refs} = @test_types; ok( eq_set( [ values %f], [ @test_types, @preval]), "all types present$pre", ); } die "preload gone" unless defined $preload; ok( eq_set( [ values %f], \ @preval), "all types gone$pre"); } # autovivified key { my %h; fieldhash %h; my $ref = {}; my $x = $h{ $ref}->[ 0]; is keys %h, 1, "autovivified key present"; undef $ref; is keys %h, 0, "autovivified key collected"; } # big key sets { my $size = 10_000; my %f; fieldhash %f; { my @refs = map [], 1 .. $size; $f{ $_} = 1 for @refs; is( keys %f, $size, "many keys singly"); } is( keys %f, 0, "many keys singly gone"); { my @refs = map [], 1 .. $size; @f{ @refs } = ( 1) x @refs; is( keys %f, $size, "many keys at once"); } is( keys %f, 0, "many keys at once gone"); } # many field hashes { my $n_fields = 1000; my @fields = map {}, $n_fields; fieldhashes @fields; my @obs = map gen_ref( $_), @test_types; my $n_obs = @obs; for my $field ( @fields ) { @{ $field }{ @obs} = map ref, @obs; } my $err = grep keys %$_ != @obs, @fields; is( $err, 0, "$n_obs entries in $n_fields fields"); pop @obs; $err = grep keys %$_ != @obs, @fields; is( $err, 0, "one entry gone from $n_fields fields"); @obs = (); $err = grep keys %$_ != @obs, @fields; is( $err, 0, "all entries gone from $n_fields fields"); } # direct hash assignment { fieldhashes \my( %f, %g, %h); my $size = 6; my @obs = map [], 1 .. $size; @f{ @obs} = ( 1) x $size; $g{ $_} = $f{ $_} for keys %f; # single assignment %h = %f; # wholesale assignment @obs = (); is keys %f, 0, "orig garbage-collected"; is keys %g, 0, "single-copy garbage-collected"; is keys %h, 0, "wholesale-copy garbage-collected"; } { fieldhash my %h; bless \ %h, 'abc'; # this bus-errors with a certain bug ok( 1, "no bus error on bless") } ####################################################################### use Symbol qw( gensym); BEGIN { my %gen = ( SCALAR => sub { \ my $o }, ARRAY => sub { [] }, HASH => sub { {} }, GLOB => sub { gensym }, CODE => sub { sub {} }, ); sub gen_ref { $gen{ shift()}->() } } 03_class.t100644000765000024 523313045746371 16314 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t/orig#!perl # This test originally comes from the Hash-Util-FieldHash distribution use strict; use warnings; use constant HAS_THREADS => eval{ require threads }; use Test::More; my $n_tests = 0; BEGIN { $n_tests += 2 } { my $p = Impostor->new( 'Donald Duck'); is( $p->greeting, "Hi, I'm Donald Duck", "blank title"); $p->assume_title( 'Mr'); is( $p->greeting, "Hi, I'm Mr Donald Duck", "changed title"); } # thread support? BEGIN { $n_tests += 5 } SKIP: { skip "No thread support", 5 unless HAS_THREADS; treads->import; my $ans; my $p = Impostor->new( 'Donald Duck'); $ans = threads->create( sub { $p->greeting })->join; is( $ans, "Hi, I'm Donald Duck", "thread: blank title"); $p->assume_title( 'Mr'); $ans = threads->create( sub { $p->greeting })->join; is( $ans, "Hi, I'm Mr Donald Duck", "thread: changed title"); $ans = threads->create( sub { $p->assume_title( 'Uncle'); $p->greeting; } )->join; is( $ans, "Hi, I'm Uncle Donald Duck", "thread: local change"); is( $p->greeting, "Hi, I'm Mr Donald Duck", "thread: change is local"); # second generation thread $ans = threads->create( sub { threads->create( sub { $p->greeting })->join; } )->join; is( $ans, "Hi, I'm Mr Donald Duck", "double thread: got greeting"); } BEGIN { plan tests => $n_tests } ############################################################################ # must do this in BEGIN so that field hashes are declared before # first use above BEGIN { package CFF; use Hash::FieldHash qw( :all); package Person; { CFF::fieldhash my %name; CFF::fieldhash my %title; sub init { my $p = shift; $name{ $p} = shift || ''; $title{ $p} = shift || ''; $p; } sub name { $name{ shift()} } sub title { $title{ shift() } } } sub new { my $class = shift; bless( \ my $x, $class)->init( @_); } sub greeting { my $p = shift; my $greet = "Hi, I'm "; $_ and $greet .= "$_ " for $p->title; $greet .= $p->name; $greet; } package Impostor; use parent -norequire, 'Person'; { CFF::fieldhash my %assumed_title; sub init { my $p = shift; my ( $name, $title) = @_; $p->Person::init( $name, $title); $p->assume_title( $title); $p; } sub title { $assumed_title{ shift()} } sub assume_title { my $p = shift; $assumed_title{ $p} = shift || ''; $p; } } } 04_thread.t100644000765000024 261613045746371 16461 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/t/orig#!perl # This test originally comes from the Hash-Util-FieldHash distribution use strict; use warnings; use Test::More; my $n_tests; use Hash::FieldHash qw( :all); { my $n_basic; BEGIN { $n_basic = 3; # 3 tests per call of basic_func() $n_tests += 5*$n_basic; } my %h; fieldhash %h; sub basic_func { my $level = shift; my @res; my $push_is = sub { my ( $hash, $should, $name) = @_; push @res, [ scalar keys %$hash, $should, $name]; }; my $obj = []; $push_is->( \ %h, 0, "$level: initially clear"); $h{ $obj} = 123; $push_is->( \ %h, 1, "$level: one object"); undef $obj; $push_is->( \ %h, 0, "$level: garbage collected"); @res; } &is( @$_) for basic_func( "home"); SKIP: { require Config; skip "No thread support", 3*$n_basic unless $Config::Config{ usethreads}; require threads; my ( $t) = threads->create( \ &basic_func, "thread 1"); &is( @$_) for $t->join; &is( @$_) for basic_func( "back home"); ( $t) = threads->create( sub { my ( $t) = threads->create( \ &basic_func, "thread 2"); $t->join; }); &is( @$_) for $t->join; } &is( @$_) for basic_func( "back home again"); } BEGIN { plan tests => $n_tests } 02_pod.t100644000765000024 23413045746371 15174 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/xt#!perl -w use strict; use Test::More; eval q{use Test::Pod 1.14}; plan skip_all => 'Test::Pod 1.14 required for testing PODU' if $@; all_pod_files_ok(); 03_pod-coverage.t100644000765000024 34213045746371 16766 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/xt#!perl -w use Test::More; eval q{use Test::Pod::Coverage 1.04}; plan skip_all => 'Test::Pod::Coverage 1.04 required for testing POD coverage' if $@; all_pod_coverage_ok({ also_private => [qw(unimport BUILD DEMOLISH)], }); 04_synopsis.t100644000765000024 22313045746371 16301 0ustar00gfxstaff000000000000Hash-FieldHash-0.15/xt#!perl -w use strict; use Test::More; eval q{use Test::Synopsis}; plan skip_all => 'Test::Synopsis required for testing' if $@; all_synopsis_ok(); META.yml100644000765000024 226213045746371 14565 0ustar00gfxstaff000000000000Hash-FieldHash-0.15--- abstract: 'Lightweight field hash for inside-out objects' author: - 'Fuji, Goro (gfx) .' build_requires: Devel::PPPort: '3.19' ExtUtils::MakeMaker: '6.59' ExtUtils::ParseXS: '2.21' Test::LeakTrace: '0.07' Test::More: '0.62' configure_requires: Module::Build: '0.4005' dynamic_config: 0 generated_by: 'Minilla/v3.0.9, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Hash-FieldHash no_index: directory: - t - xt - inc - share - eg - examples - author - builder provides: Hash::FieldHash: file: lib/Hash/FieldHash.pm version: '0.15' requires: XSLoader: '0.02' parent: '0.221' perl: '5.008005' resources: bugtracker: https://github.com/gfx/p5-Hash-FieldHash/issues homepage: https://github.com/gfx/p5-Hash-FieldHash repository: git://github.com/gfx/p5-Hash-FieldHash.git version: '0.15' x_contributors: - 'Fuji Goro ' - 'Fuji, Goro ' - 'Todd Rinaldo ' - 'FUJI Goro (gfx) ' x_serialization_backend: 'CPAN::Meta::YAML version 0.012' MANIFEST100644000765000024 137413045746371 14450 0ustar00gfxstaff000000000000Hash-FieldHash-0.15Build.PL Changes LICENSE META.json README.md benchmark/create_many.pl benchmark/fieldhash.pl benchmark/hand-written.pl benchmark/mouse.pl benchmark/threads.pl builder/MyBuilder.pm cpanfile example/namedfields.pl example/simpleuse.pl lib/Hash/FieldHash.pm minil.toml src/FieldHash.xs src/compat58.h src/compat58.xsi src/mgx.h src/mro_compat.h src/xshelper.h t/00_load.t t/01_basic.t t/02_class.t t/03_touch.t t/04_copy.t t/05_threads.t t/06_ensure_released.t t/07_local.t t/08_overload.t t/09_magic.t t/10_bad_use.t t/11_panic_malloc.t t/12_leaktrace.t t/13_leaktrace_thr.t t/14_named.t t/15_named_inherit.t t/16_redefine.t t/17_overload.t t/orig/02_function.t t/orig/03_class.t t/orig/04_thread.t xt/02_pod.t xt/03_pod-coverage.t xt/04_synopsis.t META.yml MANIFEST