COPYRIGHT000664001750001750 311213044133376 13755 0ustar00taitai000000000000MooX-Struct-0.014Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: MooX-Struct Upstream-Contact: Toby Inkster (TOBYINK) Source: https://metacpan.org/release/MooX-Struct Files: t/01basic.t t/02basicusage.t t/03inherit.t t/04flag.t t/05methods.t t/06sigils.t t/07overloading.t t/08alt-constructor.t t/09roles.t t/10strict-constructor.t t/11extend.t t/12lexical.t t/13basestruct.t t/14trace.t t/96processor.t t/97dataprinter.t t/98baseclass.t t/99lazy.t Copyright: This software is copyright (c) 2012 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: INSTALL LICENSE NEWS examples/triangle.pl t/readme.pod Copyright: Unknown License: Unknown Files: Changes META.json META.yml doap.ttl Copyright: Copyright 2017 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: COPYRIGHT CREDITS SIGNATURE Copyright: None License: public-domain Files: README lib/MooX/Struct.pm lib/MooX/Struct/Util.pm Copyright: This software is copyright (c) 2012-2013, 2017 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: Makefile.PL Copyright: Copyright 2013 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: dist.ini Copyright: Copyright 2014 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 License: Artistic-1.0 This software is Copyright (c) 2017 by the copyright holder(s). This is free software, licensed under: The Artistic License 1.0 License: GPL-1.0 This software is Copyright (c) 2017 by the copyright holder(s). This is free software, licensed under: The GNU General Public License, Version 1, February 1989 CREDITS000664001750001750 31213044133376 13461 0ustar00taitai000000000000MooX-Struct-0.014Maintainer: - Toby Inkster (TOBYINK) Contributor: - NOBODY Thanks: - - Chris Prather (PERIGRIN) - Graham Knop (HAARG) Changes000664001750001750 565213044133376 13770 0ustar00taitai000000000000MooX-Struct-0.014MooX-Struct =========== Created: 2012-10-04 Home page: Bug tracker: Maintainer: Toby Inkster (TOBYINK) 0.014 2017-01-31 [ Bug Fixes ] - Work with Data::Printer 0.36. Graham Knop++ 0.013 2014-09-10 [ Packaging ] - Switch to Dist::Inkt. 0.012 2013-05-18 [ Bug Fixes ] - Stop relying on hash order to pass t/14trace.t. 0.011 2013-05-12 [ Documentation ] - Add CAVEATS section to documentation. Chris Prather++ 0.010 2012-12-21 100% Devel::Cover coverage! [ Bug Fixes ] - Passing objects overloading hash dereference to the constructor was supposed to be supported; now it actually works. - Processing flags in EXTEND method could cause infinite loop. - Usage with Data::Printer was causing an exception related to prototypes. [ Other ] - Added: Many new test cases. 0.009 2012-12-18 [ Bug Fixes ] - Fix an internal issue in MooX::Struct::Processor, whereby it would ignore attributes inherited from the default base class when building the FIELDS method. [ Packaging ] - Moar test cases. [ Other ] - Attributes inherited from roles are no longer included in FIELDS. - Moo-style constructor is no longer strict. (This may change back!) 0.008 2012-12-17 [ Documentation ] - Add pod to test suite. [ Other ] - Added: Provide '-class' feature (currently tested for but not documented). 0.007 2012-10-28 - Added: Allow namespace::clean behaviour to be avoided via a '-retain' flag. 0.006 2012-10-09 [ Bug Fixes ] - Fix minor pod syntax error. [ Other ] - Added: Allow structs to consume roles using '-with' option. - Added: Bundle MooX::Struct::Util. - Added: New experimental method 'EXTEND'. - Constructor is now strict; it will croak if passed hash keys it doesn't recognise. - Removed: Dropped 'object_id' alias for 'OBJECT_ID'. 0.005 2012-10-08 - Added: New method 'CLONE'. - Added: New method 'FIELDS'. - Added: New method 'TO_HASH'. - Added: New method 'TO_STRING'. - Added: New method 'TYPE'. - Added: Overload a lot of operations on structs. - Added: Provide Point[$x,$y] style constructor. - Added: Special Data::Printer support. - The 'object_id' method is now called 'OBJECT_ID'. 0.004 2012-10-07 [ Bug Fixes ] - Workaround strange closure bug in Perl < 5.14. Fixes RT#80043. 0.003 2012-10-05 [ Bug Fixes ] - Broken and undocumented sigils feature is now working, documented and tested. [ Other ] - Added: New bang postfix sigil, indicating a required attribute. - The '-isa' feature for setting superclasses is now called '-extends'. 0.002 2012-10-05 [ Packaging ] - List dependencies. 0.001 2012-10-04 Initial release INSTALL000664001750001750 166513044133375 13525 0ustar00taitai000000000000MooX-Struct-0.014 Installing MooX-Struct should be straightforward. INSTALLATION WITH CPANMINUS If you have cpanm, you only need one line: % cpanm MooX::Struct If you are installing into a system-wide directory, you may need to pass the "-S" flag to cpanm, which uses sudo to install the module: % cpanm -S MooX::Struct INSTALLATION WITH THE CPAN SHELL Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan MooX::Struct MANUAL INSTALLATION As a last resort, you can manually install it. Download the tarball and unpack it. Consult the file META.json for a list of pre-requisites. Install these first. To build MooX-Struct: % perl Makefile.PL % make && make test Then install it: % make install If you are installing into a system-wide directory, you may need to run: % sudo make install LICENSE000664001750001750 4365513044133375 13526 0ustar00taitai000000000000MooX-Struct-0.014This software is copyright (c) 2017 by Toby Inkster. 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) 2017 by Toby Inkster. 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) 2017 by Toby Inkster. 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 MANIFEST000664001750001750 73213044133376 13600 0ustar00taitai000000000000MooX-Struct-0.014COPYRIGHT CREDITS Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL NEWS README SIGNATURE dist.ini doap.ttl examples/triangle.pl lib/MooX/Struct.pm lib/MooX/Struct/Util.pm t/01basic.t t/02basicusage.t t/03inherit.t t/04flag.t t/05methods.t t/06sigils.t t/07overloading.t t/08alt-constructor.t t/09roles.t t/10strict-constructor.t t/11extend.t t/12lexical.t t/13basestruct.t t/14trace.t t/96processor.t t/97dataprinter.t t/98baseclass.t t/99lazy.t t/readme.pod META.json000664001750001750 433313044133376 14111 0ustar00taitai000000000000MooX-Struct-0.014{ "abstract" : "make simple lightweight record-like structures that make sounds like cows", "author" : [ "Toby Inkster (TOBYINK) " ], "dynamic_config" : 0, "generated_by" : "Dist::Inkt::Profile::TOBYINK version 0.023, CPAN::Meta::Converter version 2.150005", "keywords" : [], "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "MooX-Struct", "no_index" : { "directory" : [ "eg", "examples", "inc", "t", "xt" ] }, "optional_features" : {}, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17" } }, "runtime" : { "requires" : { "B::Hooks::EndOfScope" : "0", "Data::OptList" : "0", "Moo" : "1.000000", "Object::ID" : "0", "Scalar::Does" : "0", "Sub::Install" : "0", "namespace::clean" : "0", "perl" : "5.008" } }, "test" : { "requires" : { "Test::More" : "0.61" } } }, "provides" : { "MooX::Struct" : { "file" : "lib/MooX/Struct.pm", "version" : "0.014" }, "MooX::Struct::Processor" : { "file" : "lib/MooX/Struct.pm", "version" : "0.014" }, "MooX::Struct::Util" : { "file" : "lib/MooX/Struct/Util.pm", "version" : "0.014" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "http://rt.cpan.org/Dist/Display.html?Queue=MooX-Struct" }, "homepage" : "https://metacpan.org/release/MooX-Struct", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/tobyink/p5-moox-struct.git", "web" : "https://github.com/tobyink/p5-moox-struct" }, "x_identifier" : "http://purl.org/NET/cpan-uri/dist/MooX-Struct/project" }, "version" : "0.014", "x_contributors" : [ "NOBODY" ], "x_serialization_backend" : "JSON::PP version 2.27300_01" } META.yml000664001750001750 255513044133376 13745 0ustar00taitai000000000000MooX-Struct-0.014--- abstract: 'make simple lightweight record-like structures that make sounds like cows' author: - 'Toby Inkster (TOBYINK) ' build_requires: Test::More: '0.61' configure_requires: ExtUtils::MakeMaker: '6.17' dynamic_config: 0 generated_by: 'Dist::Inkt::Profile::TOBYINK version 0.023, CPAN::Meta::Converter version 2.150005' keywords: [] license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: MooX-Struct no_index: directory: - eg - examples - inc - t - xt optional_features: {} provides: MooX::Struct: file: lib/MooX/Struct.pm version: '0.014' MooX::Struct::Processor: file: lib/MooX/Struct.pm version: '0.014' MooX::Struct::Util: file: lib/MooX/Struct/Util.pm version: '0.014' requires: B::Hooks::EndOfScope: '0' Data::OptList: '0' Moo: '1.000000' Object::ID: '0' Scalar::Does: '0' Sub::Install: '0' namespace::clean: '0' perl: '5.008' resources: Identifier: http://purl.org/NET/cpan-uri/dist/MooX-Struct/project bugtracker: http://rt.cpan.org/Dist/Display.html?Queue=MooX-Struct homepage: https://metacpan.org/release/MooX-Struct license: http://dev.perl.org/licenses/ repository: git://github.com/tobyink/p5-moox-struct.git version: '0.014' x_contributors: - NOBODY x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Makefile.PL000664001750001750 1245013044133376 14461 0ustar00taitai000000000000MooX-Struct-0.014use strict; use ExtUtils::MakeMaker 6.17; my $EUMM = eval( $ExtUtils::MakeMaker::VERSION ); my $meta = { "abstract" => "make simple lightweight record-like structures that make sounds like cows", "author" => ["Toby Inkster (TOBYINK) "], "dynamic_config" => 0, "generated_by" => "Dist::Inkt::Profile::TOBYINK version 0.023, CPAN::Meta::Converter version 2.150005", "keywords" => [], "license" => ["perl_5"], "meta-spec" => { url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec", version => 2, }, "name" => "MooX-Struct", "no_index" => { directory => ["eg", "examples", "inc", "t", "xt"] }, "prereqs" => { configure => { requires => { "ExtUtils::MakeMaker" => 6.17 } }, runtime => { requires => { "B::Hooks::EndOfScope" => 0, "Data::OptList" => 0, "Moo" => "1.000000", "namespace::clean" => 0, "Object::ID" => 0, "perl" => 5.008, "Scalar::Does" => 0, "Sub::Install" => 0, }, }, test => { requires => { "Test::More" => 0.61 } }, }, "provides" => { "MooX::Struct" => { file => "lib/MooX/Struct.pm", version => 0.014 }, "MooX::Struct::Processor" => { file => "lib/MooX/Struct.pm", version => 0.014 }, "MooX::Struct::Util" => { file => "lib/MooX/Struct/Util.pm", version => 0.014 }, }, "release_status" => "stable", "resources" => { bugtracker => { web => "http://rt.cpan.org/Dist/Display.html?Queue=MooX-Struct" }, homepage => "https://metacpan.org/release/MooX-Struct", license => ["http://dev.perl.org/licenses/"], repository => { type => "git", url => "git://github.com/tobyink/p5-moox-struct.git", web => "https://github.com/tobyink/p5-moox-struct", }, x_identifier => "http://purl.org/NET/cpan-uri/dist/MooX-Struct/project", }, "version" => 0.014, "x_contributors" => ["NOBODY"], }; my %dynamic_config; my %WriteMakefileArgs = ( ABSTRACT => $meta->{abstract}, AUTHOR => ($EUMM >= 6.5702 ? $meta->{author} : $meta->{author}[0]), DISTNAME => $meta->{name}, VERSION => $meta->{version}, EXE_FILES => [ map $_->{file}, values %{ $meta->{x_provides_scripts} || {} } ], NAME => do { my $n = $meta->{name}; $n =~ s/-/::/g; $n }, test => { TESTS => "t/*.t" }, %dynamic_config, ); $WriteMakefileArgs{LICENSE} = $meta->{license}[0] if $EUMM >= 6.3001; sub deps { my %r; for my $stage (@_) { for my $dep (keys %{$meta->{prereqs}{$stage}{requires}}) { next if $dep eq 'perl'; my $ver = $meta->{prereqs}{$stage}{requires}{$dep}; $r{$dep} = $ver if !exists($r{$dep}) || $ver >= $r{$dep}; } } \%r; } my ($build_requires, $configure_requires, $runtime_requires, $test_requires); if ($EUMM >= 6.6303) { $WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build'); $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{TEST_REQUIRES} ||= deps('test'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime'); } elsif ($EUMM >= 6.5503) { $WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build', 'test'); $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime'); } elsif ($EUMM >= 6.52) { $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime', 'build', 'test'); } else { $WriteMakefileArgs{PREREQ_PM} ||= deps('configure', 'build', 'test', 'runtime'); } { my ($minperl) = reverse sort( grep defined && /^[0-9]+(\.[0-9]+)?$/, map $meta->{prereqs}{$_}{requires}{perl}, qw( configure build runtime ) ); if (defined($minperl)) { die "Installing $meta->{name} requires Perl >= $minperl" unless $] >= $minperl; $WriteMakefileArgs{MIN_PERL_VERSION} ||= $minperl if $EUMM >= 6.48; } } sub FixMakefile { return unless -d 'inc'; my $file = shift; local *MAKEFILE; open MAKEFILE, "< $file" or die "FixMakefile: Couldn't open $file: $!; bailing out"; my $makefile = do { local $/; }; close MAKEFILE or die $!; $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; open MAKEFILE, "> $file" or die "FixMakefile: Couldn't open $file: $!; bailing out"; print MAKEFILE $makefile or die $!; close MAKEFILE or die $!; } my $mm = WriteMakefile(%WriteMakefileArgs); FixMakefile($mm->{FIRST_MAKEFILE} || 'Makefile'); exit(0); NEWS000664001750001750 41613044133375 13144 0ustar00taitai000000000000MooX-Struct-0.0140.014 - 2017-01-31 I'm still alive. :) 0.010 - 2012-12-21 100% coverage on Devel::Cover. 0.009 - 2012-12-18 Some incompatible changes... - traditional Moose/Moo-style constructor is no longer strict - attributes inherited from roles no longer appear in FIELDS README000664001750001750 2356713044133375 13401 0ustar00taitai000000000000MooX-Struct-0.014NAME MooX::Struct - make simple lightweight record-like structures that make sounds like cows SYNOPSIS use MooX::Struct Point => [ 'x', 'y' ], Point3D => [ -extends => ['Point'], 'z' ], ; my $origin = Point3D->new( x => 0, y => 0, z => 0 ); # or... my $origin = Point3D[ 0, 0, 0 ]; DESCRIPTION MooX::Struct allows you to create cheap struct-like classes for your data using Moo. While similar in spirit to MooseX::Struct and Class::Struct, MooX::Struct has a somewhat different usage pattern. Rather than providing you with a `struct` keyword which can be used to define structs, you define all the structs as part of the `use` statement. This means they happen at compile time. A struct is just an "anonymous" Moo class. MooX::Struct creates this class for you, and installs a lexical alias for it in your namespace. Thus your module can create a "Point3D" struct, and some other module can too, and they won't interfere with each other. All struct classes inherit from MooX::Struct. Arguments for MooX::Struct are key-value pairs, where keys are the struct names, and values are arrayrefs. use MooX::Struct Person => [qw/ name address /], Company => [qw/ name address registration_number /]; The elements in the array are the attributes for the struct (which will be created as read-only attributes), however certain array elements are treated specially. * As per the example in the "SYNOPSIS", `-extends` introduces a list of parent classes for the struct. If not specified, then classes inherit from MooX::Struct itself. Structs can inherit from other structs, or from normal classes. If inheriting from another struct, then you *must* define both in the same `use` statement. Inheriting from a non-struct class is discouraged. # Not like this. use MooX::Struct Point => [ 'x', 'y' ]; use MooX::Struct Point3D => [ -extends => ['Point'], 'z' ]; # Like this. use MooX::Struct Point => [ 'x', 'y' ], Point3D => [ -extends => ['Point'], 'z' ], ; * Similarly `-with` consumes a list of roles. * If an attribute name is followed by a coderef, this is installed as a method instead. use MooX::Struct Person => [ qw( name age sex ), greet => sub { my $self = shift; CORE::say "Hello ", $self->name; }, ]; But if you're defining methods for your structs, then you've possibly missed the point of them. * If an attribute name is followed by an arrayref, these are used to set the options for the attribute. For example: use MooX::Struct Person => [ name => [ is => 'ro', required => 1 ] ]; Using the `init_arg` option would probably break stuff. Don't do that. * Attribute names may be "decorated" with prefix and postfix "sigils". The prefix sigils of `@` and `%` specify that the attribute isa arrayref or hashref respectively. (Blessed arrayrefs and hashrefs are accepted; as are objects which overload `@{}` and `%{}`.) The prefix sigil `$` specifies that the attribute value must not be an unblessed arrayref or hashref. The prefix sigil `+` indicates the attribute is a number, and provides a default value of 0, unless the attribute is required. The postfix sigil `!` specifies that the attribute is required. use MooX::Struct Person => [qw( $name! @children )]; Person->new(); # dies, name is required Person->new( # dies, children should be arrayref name => 'Bob', children => 2, ); Prior to the key-value list, some additional flags can be given. These begin with hyphens. The flag `-rw` indicates that attributes should be read-write rather than read-only. use MooX::Struct -rw, Person => [ qw( name age sex ), greet => sub { my $self = shift; CORE::say "Hello ", $self->name; }, ]; The `-retain` flag can be used to indicate that MooX::Struct should not use namespace::clean to enforce lexicalness on your struct class aliases. Flags `-trace` and `-deparse` may be of use debugging. Instantiating Structs There are two supported methods of instatiating structs. You can use a traditional class-like constructor with named parameters: my $point = Point->new( x => 1, y => 2 ); Or you can use the abbreviated syntax with positional parameters: my $point = Point[ 1, 2 ]; If you know about Moo and peek around in the source code for this module, then I'm sure you can figure out additional ways to instantiate them, but the above are the only supported two. When inheritance or roles have been used, it might not always be clear what order the positional parameters come in (though see the documentation for the `FIELDS` below), so the traditional class-like style may be preferred. Methods Structs are objects and thus have methods. You can define your own methods as described above. MooX::Struct's built-in methods will always obey the convention of being in ALL CAPS (except in the case of `_data_printer`). By using lower-case letters to name your own methods, you can avoid naming collisions. The following methods are currently defined. Additionally all the standard Perl (`isa`, `can`, etc) and Moo (`new`, `does`, etc) methods are available. `OBJECT_ID` Returns a unique identifier for the object. `FIELDS` Returns a list of fields associated with the object. For the `Point3D` struct in the SYNPOSIS, this would be 'x', 'y', 'z'. The order the fields are returned in is equal to the order they must be supplied for the positional constructor. Attributes inherited from roles, or from non-struct base classes are not included in `FIELDS`, and thus cannot be used in the positional constructor. `TYPE` Returns the type name of the struct, e.g. 'Point3D'. `TO_HASH` Returns a reference to an unblessed hash where the object's fields are the keys and the object's values are the hash values. `TO_ARRAY` Returns a reference to an unblessed array where the object's values are the array items, in the same order as listed by `FIELDS`. `TO_STRING` Joins `TO_ARRAY` with whitespace. This is not necessarily a brilliant stringification, but easy enough to overload: use MooX::Struct Point => [ qw( x y ), TO_STRING => sub { sprintf "(%d, %d)"), $_[0]->x, $_[0]->y; }, ] ; `CLONE` Creates a shallow clone of the object. `EXTEND` An exverimental feature. Extend a class or object with additional attributes, methods, etc. This method takes almost all the same arguments as `use MooX::Struct`, albeit with some slight differences. use MooX::Struct Point => [qw/ +x +y /]; my $point = Point[2, 3]; $point->EXTEND(-rw, q/+z/); # extend an object $point->can('z'); # true my $new_class = Point->EXTEND('+z'); # extend a class my $point_3d = $new_class->new( x => 1, y => 2, z => 3 ); $point_3d->TYPE; # Point ! my $point_4d = $new_class->EXTEND(\"Point4D", '+t'); $point_4d->TYPE; # Point4D my $origin = Point[]->EXTEND(-with => [qw/ Math::Role::Origin /]); This feature has been included mostly because it's easy to implement on top of the existing code for processing `use MooX::Struct`. Some subsets of this functionality are sane, such as the ability to add traits to an object. Others (like the ability to add a new uninitialized, read-only attribute to an existing object) are less sensible. `BUILDARGS` Moo internal fu. `_data_printer` Automatic pretty printing with Data::Printer. use Data::Printer; use MooX::Struct Point => [qw/ +x +y /]; my $origin = Point[]; p $origin; Use Data::Printer 0.36 or above please. With the exception of `FIELDS` and `TYPE`, any of these can be overridden using the standard way of specifying methods for structs. Overloading MooX::Struct overloads stringification and array dereferencing. Objects always evaluate to true in a boolean context. (Even if they stringify to the empty string.) CAVEATS Because you only get an alias for the struct class, you need to be careful with some idioms: my $point = Point3D->new(x => 1, y => 2, z => 3); $point->isa("Point3D"); # false! $point->isa( Point3D ); # true my %args = (...); my $class = exists $args{z} ? "Point3D" : "Point"; # wrong! $class->new(%args); my $class = exists $args{z} ? Point3D : Point ; # right $class->new(%args); BUGS Please report any bugs to . SEE ALSO Moo, MooX::Struct::Util, MooseX::Struct, Class::Struct. AUTHOR Toby Inkster . COPYRIGHT AND LICENCE This software is copyright (c) 2012-2013, 2017 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. DISCLAIMER OF WARRANTIES 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. SIGNATURE000664001750001750 534513044133376 13760 0ustar00taitai000000000000MooX-Struct-0.014This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.81. 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 c62984ac61816e4a9fdffcc1f21c84795ef402f8 COPYRIGHT SHA1 2fa6faff15bd658c9451c2bd3b4e4aa2564adcc1 CREDITS SHA1 d199ebb73cc13d1e58f00907619a0a89ce391346 Changes SHA1 a6d167b6b05e6ccf711497d63a867605bfe892b7 INSTALL SHA1 c4c1e6c578edcfd14d13eadebc8f56dd9ca46821 LICENSE SHA1 5c24e63148f277e61a0d198846b41e9ab455d2c2 MANIFEST SHA1 0e1109b1d4bf1e173ae617a37ee45995a0f5ea67 META.json SHA1 5d904bb7520f561542c6366cfa59cfd0d15b233a META.yml SHA1 9716844403d335d93015a9be8fa4a1cde12d684c Makefile.PL SHA1 33a727fab3c1c28ac69bcf5af2f229d5891a0344 NEWS SHA1 5090a3ae28ada257101da09e0dbfbe14026da6f9 README SHA1 31620717d6a86130ce847f10f865bcafb99aef79 dist.ini SHA1 b9ee9d5a5e234348c4013747d21acd1e36e99f52 doap.ttl SHA1 632ae6adc26897342739b02418ed3ef997ac072e examples/triangle.pl SHA1 209a92e30071f92d78dd9bba4879becf6566e3a5 lib/MooX/Struct.pm SHA1 392cd02a897b5d52fb738c88ddc08ae142f5d643 lib/MooX/Struct/Util.pm SHA1 d26efcaebce8e74b5b9ce441b6d5ff229b1d7cde t/01basic.t SHA1 2d605dd7f1b1abb5a935416f814026fb29f11817 t/02basicusage.t SHA1 580e1e120c0c032a4788e44070e0c304fefc0b7c t/03inherit.t SHA1 cbe7476e8bdb983f6860d02b79312246bc57c9df t/04flag.t SHA1 c44ce05cbe2290ff8f8ee707bac73c1b6abb717a t/05methods.t SHA1 1f850f2f737702baeb64cb160008cd689825c65e t/06sigils.t SHA1 c86a5c14e7f73246721cf406319fda4d25b19970 t/07overloading.t SHA1 c840db65cfe3371c012ba14672d5e93b7ae9e85a t/08alt-constructor.t SHA1 e3b421daa199428b70bee7a1f0f4ebe305f0b102 t/09roles.t SHA1 042fc931861d6003b10623eea4937abc8006648a t/10strict-constructor.t SHA1 a3ac7ec30d564fd68e66940424ab791803f1e2c4 t/11extend.t SHA1 923b254963531385ba70fbba732ec58b042504b3 t/12lexical.t SHA1 226b6e5dd2bd5762283e2833ee4523d10012c506 t/13basestruct.t SHA1 69c8d781dd2b397dd7019e20254ee45376116f1e t/14trace.t SHA1 2ea288303c380732ec8cb667b2234a91d0030d33 t/96processor.t SHA1 43584a989c29b1f9931540609a4bda24d87498bd t/97dataprinter.t SHA1 34532bdfdf4739460b6890098c3a0cc155393d86 t/98baseclass.t SHA1 9ab4c3ee1177da1337a6913200302816f562005b t/99lazy.t SHA1 d610ccf6c138bd58c79ebf6a58cab019ae98aa8c t/readme.pod -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAliQtv4ACgkQzr+BKGoqfTmsFgCfZvmNsrRHbZweIrPo9xl7CEyH vwkAn3ax6/aWiUFsmDYqsq7KNBpvE3gi =E0hP -----END PGP SIGNATURE----- dist.ini000664001750001750 7413044133375 14071 0ustar00taitai000000000000MooX-Struct-0.014;;class='Dist::Inkt::Profile::TOBYINK' ;;name='MooX-Struct' doap.ttl000664001750001750 3451713044133376 14167 0ustar00taitai000000000000MooX-Struct-0.014@prefix dc: . @prefix doap: . @prefix doap-bugs: . @prefix doap-changeset: . @prefix doap-deps: . @prefix foaf: . @prefix rdfs: . @prefix xsd: . dc:title "the same terms as the perl 5 programming language system itself". a doap:Project; dc:contributor ; doap-bugs:issue ; doap-deps:runtime-requirement [ doap-deps:on "perl 5.008"^^doap-deps:CpanId ], [ doap-deps:on "B::Hooks::EndOfScope"^^doap-deps:CpanId; ], [ doap-deps:on "Data::OptList"^^doap-deps:CpanId ], [ doap-deps:on "Moo 1.000000"^^doap-deps:CpanId ], [ doap-deps:on "namespace::clean"^^doap-deps:CpanId ], [ doap-deps:on "Object::ID"^^doap-deps:CpanId ], [ doap-deps:on "Scalar::Does"^^doap-deps:CpanId ], [ doap-deps:on "Sub::Install"^^doap-deps:CpanId ]; doap-deps:test-requirement [ doap-deps:on "Test::More 0.61"^^doap-deps:CpanId ]; doap:bug-database ; doap:created "2012-10-04"^^xsd:date; doap:developer ; doap:download-page ; doap:homepage ; doap:license ; doap:maintainer ; doap:name "MooX-Struct"; doap:programming-language "Perl"; doap:release , , , , , , , , , , , , , ; doap:repository [ a doap:GitRepository; doap:browse ; ]; doap:shortdesc "make simple lightweight record-like structures that make sounds like cows". a doap:Version; rdfs:label "Initial release"; dc:identifier "MooX-Struct-0.001"^^xsd:string; dc:issued "2012-10-04"^^xsd:date; doap-changeset:released-by ; doap:file-release ; doap:revision "0.001"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.002"^^xsd:string; dc:issued "2012-10-05"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Packaging; rdfs:label "List dependencies."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.002"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.003"^^xsd:string; dc:issued "2012-10-05"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "The '-isa' feature for setting superclasses is now called '-extends'."; ], [ a doap-changeset:Bugfix; rdfs:label "Broken and undocumented sigils feature is now working, documented and tested."; ], [ a doap-changeset:Addition; rdfs:label "New bang postfix sigil, indicating a required attribute."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.003"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.004"^^xsd:string; dc:issued "2012-10-07"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Workaround strange closure bug in Perl < 5.14."@en; doap-changeset:fixes ; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.004"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.005"^^xsd:string; dc:issued "2012-10-08"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "Provide Point[$x,$y] style constructor."; ], [ a doap-changeset:Addition; rdfs:label "Overload a lot of operations on structs."; ], [ a doap-changeset:Addition; rdfs:label "Special Data::Printer support."; ], [ a doap-changeset:Change; rdfs:label "The 'object_id' method is now called 'OBJECT_ID'."; ], [ a doap-changeset:Addition; rdfs:label "New method 'TO_STRING'."; ], [ a doap-changeset:Addition; rdfs:label "New method 'TO_HASH'."; ], [ a doap-changeset:Addition; rdfs:label "New method 'FIELDS'."; ], [ a doap-changeset:Addition; rdfs:label "New method 'TYPE'."; ], [ a doap-changeset:Addition; rdfs:label "New method 'CLONE'."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.005"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.006"^^xsd:string; dc:issued "2012-10-09"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Fix minor pod syntax error."; ], [ a doap-changeset:Addition; rdfs:label "Bundle MooX::Struct::Util."; ], [ a doap-changeset:Addition; rdfs:label "Allow structs to consume roles using '-with' option."; ], [ a doap-changeset:Change; rdfs:label "Constructor is now strict; it will croak if passed hash keys it doesn't recognise."; ], [ a doap-changeset:Addition; rdfs:label "New experimental method 'EXTEND'."; ], [ a doap-changeset:Removal; rdfs:label "Dropped 'object_id' alias for 'OBJECT_ID'."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.006"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.007"^^xsd:string; dc:issued "2012-10-28"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "Allow namespace::clean behaviour to be avoided via a '-retain' flag."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.007"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.008"^^xsd:string; dc:issued "2012-12-17"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "Provide '-class' feature (currently tested for but not documented)."; ], [ a doap-changeset:Documentation; rdfs:label "Add pod to test suite."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.008"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.009"^^xsd:string; dc:issued "2012-12-18"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Fix an internal issue in MooX::Struct::Processor, whereby it would ignore attributes inherited from the default base class when building the FIELDS method."; ], [ a doap-changeset:Packaging; rdfs:label "Moar test cases."; ], [ a doap-changeset:Change; rdfs:label "Moo-style constructor is no longer strict. (This may change back!)"; ], [ a doap-changeset:Change; rdfs:label "Attributes inherited from roles are no longer included in FIELDS."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.009"^^xsd:string. a doap:Version; rdfs:label "100% Devel::Cover coverage!"; dc:identifier "MooX-Struct-0.010"^^xsd:string; dc:issued "2012-12-21"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Processing flags in EXTEND method could cause infinite loop."; ], [ a doap-changeset:Bugfix; rdfs:label "Passing objects overloading hash dereference to the constructor was supposed to be supported; now it actually works."; ], [ a doap-changeset:Bugfix; rdfs:label "Usage with Data::Printer was causing an exception related to prototypes."; ], [ a doap-changeset:Addition; rdfs:label "Many new test cases."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.010"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.011"^^xsd:string; dc:issued "2013-05-12"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Documentation; rdfs:label "Add CAVEATS section to documentation."; doap-changeset:thanks ; rdfs:seeAlso ; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.011"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.012"^^xsd:string; dc:issued "2013-05-18"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Stop relying on hash order to pass t/14trace.t."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.012"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.013"^^xsd:string; dc:issued "2014-09-10"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Packaging; rdfs:label "Switch to Dist::Inkt."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.013"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.014"^^xsd:string; dc:issued "2017-01-31"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix, doap-changeset:Update; rdfs:label "Work with Data::Printer 0.36."; doap-changeset:thanks ; rdfs:seeAlso , ; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.014"^^xsd:string. a foaf:Person; foaf:name "Graham Knop"; foaf:nick "HAARG"; foaf:page . a foaf:Person; foaf:name "Chris Prather"; foaf:nick "PERIGRIN"; foaf:page . a foaf:Person; foaf:mbox ; foaf:name "Toby Inkster"; foaf:nick "TOBYINK"; foaf:page . a doap-bugs:Issue; rdfs:label "Hmmm... not working in Perl < 5.14."; dc:created "2012-10-06T21:54:22"^^xsd:dateTime; dc:modified "2012-10-06T21:54:23"^^xsd:dateTime; doap-bugs:assignee [ a foaf:Agent; foaf:nick "Nobody" ]; doap-bugs:id "80043"^^xsd:string; doap-bugs:page ; doap-bugs:reporter [ a foaf:Agent; foaf:mbox ; ]; doap-bugs:status . triangle.pl000664001750001750 57613044133375 16434 0ustar00taitai000000000000MooX-Struct-0.014/examplesuse strict; use Data::Printer; use MooX::Struct Triangle => [qw/ $a! $b! $c! /], Quad => [qw/ $a! $b! $c! $d! /], Point => [qw/ +x +y /], ; my $triangle = Triangle[ Point[0, 0], Point[1, 1], Point[1, 0], ]; my $square = Quad[ Point[0, 0], Point[0, 1], Point[1, 1], Point[1, 0], ]; my %shapes = ( three_sided => [$triangle] , four_sided => [$square] ); p %shapes;01basic.t000664001750001750 104713044133375 14340 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Checks MooX::Struct compiles. Prints out some key software versions. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use Test::More tests => 1; BEGIN { use_ok('MooX::Struct') }; diag ''; diag sprintf("%-12s %s", q(Perl), $]); diag sprintf("%-12s %s", $_, $_->VERSION) for qw( MooX::Struct Moo ); 02basicusage.t000664001750001750 261113044133375 15364 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Basic MooX::Struct usage. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use Test::More tests => 12; use MooX::Struct Organisation => [qw/ name employees /, company_number => [is => 'rw']], Person => [qw/ name /]; my $alice = Person->new(name => 'Alice'); my $bob = Person->new(name => 'Bob'); my $acme = Organisation->new(name => 'ACME', employees => [$alice, $bob]); note sprintf("Person class: %s", Person); note sprintf("Organisation class: %s", Organisation); is( ref($alice), ref($bob), 'Alice and Bob are in the same class', ); isnt( ref($alice), ref($acme), 'Alice and ACME are not in the same class', ); isa_ok($_, 'MooX::Struct', '$'.lc($_->name)) for ($alice, $bob, $acme); is($alice->name, 'Alice', '$alice is called Alice'); is($bob->name, 'Bob', '$bob is called Bob'); is($acme->name, 'ACME', '$acme is called ACME'); ok !eval { $acme->name('Acme Inc'); 1 }, 'accessors are read-only by default'; $acme->company_number(12345); is($acme->company_number, 12345, 'accessors can be made read-write'); can_ok $alice => 'OBJECT_ID'; isnt($alice->OBJECT_ID, $bob->OBJECT_ID, 'OBJECT_ID is unique identifier'); 03inherit.t000664001750001750 417413044133375 14727 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Check that different structs can inherit from each other. Check that the "-class" option works. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use Test::More; use MooX::Struct Agent => [ name => undef, -class => \'Local::Test::Class1' ], Organisation => [ -extends => ['Agent'], employees => undef, company_number => [is => 'rw']], Person => [ -extends => ['Agent'], -class => [qw/Local Test Class2/] ]; my $alice = Person->new(name => 'Alice'); my $bob = Person->new(name => 'Bob'); my $acme = Organisation->new(name => 'ACME', employees => [$alice, $bob]); note sprintf("Agent class: %s", Agent); note sprintf("Person class: %s", Person); note sprintf("Organisation class: %s", Organisation); is(Agent, 'Local::Test::Class1'); is(Person, 'Local::Test::Class2'); isa_ok($alice, 'Local::Test::Class1'); isa_ok($alice, 'Local::Test::Class2'); is( ref($alice), ref($bob), 'Alice and Bob are in the same class', ); isnt( ref($alice), ref($acme), 'Alice and ACME are not in the same class', ); isa_ok($_, 'MooX::Struct', '$'.lc($_->name)) for ($alice, $bob, $acme); isa_ok($alice, Agent); isa_ok($bob, Agent); isa_ok($acme, Agent); isa_ok($alice, Person); isa_ok($bob, Person); isa_ok($acme, Organisation); isa_ok(Organisation, Agent); isa_ok(Person, Agent); is($alice->name, 'Alice', '$alice is called Alice'); is($bob->name, 'Bob', '$bob is called Bob'); is($acme->name, 'ACME', '$acme is called ACME'); ok !eval { $acme->name('Acme Inc'); 1 }, 'accessors are read-only by default'; $acme->company_number(12345); is($acme->company_number, 12345, 'accessors can be made read-write'); can_ok $alice => 'OBJECT_ID'; isnt($alice->OBJECT_ID, $bob->OBJECT_ID, 'OBJECT_ID is unique identifier'); use MooX::Struct XXX1 => [ qw< $foo > ]; use MooX::Struct XXX2 => [ -extends => [ XXX1 ], qw< $bar > ]; is_deeply([XXX2->FIELDS], [qw< foo bar >]); done_testing; 04flag.t000664001750001750 122113044133375 14165 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Check that the "-rw" flag works. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use Test::More tests => 1; use MooX::Struct -rw, Agent => [qw( name )], Person => [ -extends => ['Agent'] ]; my $bob = Person->new(name => 'Bob'); note sprintf("Agent class: %s", Agent); note sprintf("Person class: %s", Person); $bob->name('Robert'); is($bob->name, 'Robert'); 05methods.t000664001750001750 104313044133375 14722 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Check that methods can be added to structs. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use Test::More tests => 1; use MooX::Struct Person => [ qw( name age sex ), uc_name => sub { my $self = shift; return uc $self->name; }, ]; is(Person->new(name => 'Bob')->uc_name, 'BOB'); 06sigils.t000664001750001750 526113044133375 14560 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Check that the required (C<< ! >>) postfix sigil works, and that the scalar ((C<< $ >>), array (C<< @ >>) and hash (C<< % >>) prefix sigils work. Check that the C<< + >> postfix sigil works, that numbers can default to values other than zero, and that an explicit C works. Make sure that sigils are just hints, and can be overridden by an explicit attribute spec. Checks that attribute specs can be hashrefs or arrayrefs. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use Test::More; use Scalar::Does qw( does looks_like_number ); use MooX::Struct Structure => [ qw( $value %dict @list ), '@value2' => { isa => sub { die if ref $_[0] } }, '%list2' => [ isa => sub { die unless does $_[0], 'ARRAY' } ], '$dict2' => [ isa => sub { die unless does $_[0], 'HASH' } ], ], OtherStructure => [qw( id! ego )], Point => ['+x', '+y' => [default => sub { 101 }]], Point3D => [-extends => ['Point'], '+z' => [isa => sub { die unless looks_like_number($_[0]) || !defined $_[0] }]], PointReq => ['+x!', '+y!'], ; ok eval { Structure->new( value => Structure->new ) }; ok eval { Structure->new( value => 42 ) }; ok eval { Structure->new( list => [] ) }; ok eval { Structure->new( dict => +{} ) }; ok eval { Structure->new( value2 => "Hello World" ); }; ok eval { Structure->new( list2 => [] ); }; ok eval { Structure->new( dict2 => {foo => 42} ); }; ok !eval { Structure->new( value => [] ) }; ok !eval { Structure->new( value => +{} ) }; ok !eval { Structure->new( list => 42 ) }; ok !eval { Structure->new( dict => 42 ) }; ok !eval { Structure->new( value2 => [] ); }; ok !eval { Structure->new( list2 => +{} ); }; ok !eval { Structure->new( dict2 => 42 ); }; ok eval { OtherStructure->new(id => undef); }; ok !eval { OtherStructure->new(ego => undef); }; my $point = Point->new; ok defined $point->x; ok defined $point->y; is($point->x, 0); is($point->y, 101); ok eval { Point[ 42, 42 ]; Point[ 42.1, 42.2 ]; Point[ "99", "999" ]; Point[ "+Inf", "-Inf" ]; }; ok not eval { Point[ "Hello", "World" ]; }; ok not eval { Point[ "", "" ]; }; ok not eval { Point[ "Hello", "99" ]; }; ok eval { Point3D[ 1, 2 ]; Point3D[ 1, 2, 3 ]; Point3D[ 1, 2, undef ]; }; is_deeply( Point3D->new->TO_ARRAY, [ 0, 101, 0 ], ); ok not eval { Point3D[ 1, 2, "Hello" ]; }; ok eval { PointReq[ 1, 2 ]; PointReq[ 0, '-Inf' ]; PointReq[ 0, 0 ]; }; ok not eval { PointReq[ ]; }; ok not eval { PointReq[ "abc", 0 ]; }; done_testing(); 07overloading.t000664001750001750 153713044133375 15602 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Check that overloading to string and to arrayref work. Also checks the C method. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use Test::More; use MooX::Struct Point => [ qw(x y) ], Point3D => [ -extends => [qw(Point)], qw(z) ], ; my $point = Point->new(x => 3, y => 4); is("$point", "3 4", "Point stringifies correctly"); my $point2 = Point3D->new(x => 3, y => 4, z => 5); is("$point2", "3 4 5", "Point3D stringifies correctly"); is_deeply( [ @$point2 ], [qw(3 4 5)], "Point3D casts to array properly" ); my $clone = CLONE $point2; is("$clone", "3 4 5", "cloning is awesome"); done_testing; 08alt-constructor.t000664001750001750 254613044133375 16436 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Check square-bracket-style constructor. Also checks constructor called with a hashref (works, but not officially supported). Tests that objects overloading both hash and array are considered to be hashrefs by the constructor, not arrayrefs. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use Test::More; use MooX::Struct Point => [ qw( +x +y ) ], Point3D => [ -extends => [qw(Point)], qw( +z ) ], ; my $point1 = Point[3, 4]; my $point2 = Point3D[3, 4, 5]; my $point3 = Point3D[3, 4]; is("$point1", "3 4"); is("$point2", "3 4 5"); is("$point3", "3 4 0"); is( Point3D->new([3, 4, 5])->TO_STRING, "3 4 5", ); is( Point3D->new({ z=>1, y=>2, x=>3, y=>4, z=>5 })->TO_STRING, "3 4 5", ); ok not eval { Point3D->new( \*STDERR ) }; ok not eval { Point3D[1, 2, 3, 4] }; { package Local::WeirdHash; use overload '@{}' => 'TO_ARRAY'; sub TO_ARRAY { my $self = shift; [ sort keys %$self ]; } } my $weird = bless { z=>1, y=>2, x=>3, y=>4, z=>5 }, 'Local::WeirdHash'; is( Point3D->new($weird)->TO_STRING, "3 4 5", 'if constructed with an object that "does" array and hash, hash is preferred', ); done_testing(); 09roles.t000664001750001750 171013044133375 14410 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Check that structs can consume Moo roles. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use Test::More; BEGIN { package Local::Role1; use Moo::Role; has attr1 => (is => 'ro'); } BEGIN { package Local::Role2; use Moo::Role; has attr2 => (is => 'ro'); } use MooX::Struct Thingy => [ -with => [qw( Local::Role2 Local::Role1 )], qw/ $attr3 $attr4 /, ], ; is_deeply( [ Thingy->FIELDS ], [ qw/ attr3 attr4 / ], ); my $thingy = Thingy[qw/ 3 4 /]; #is($thingy->attr1, 1); #is($thingy->attr2, 2); is($thingy->attr3, 3); is($thingy->attr4, 4); $thingy = Thingy->new(map { ; "attr$_", $_ } 1..4); is($thingy->attr1, 1); is($thingy->attr2, 2); is($thingy->attr3, 3); is($thingy->attr4, 4); done_testing; 10strict-constructor.t000664001750001750 112413044133375 17146 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Check that the constructor is strict (throws an error if it sees unknown attributes). This test is currently disabled, as the constructor is no longer strict. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use Test::More skip_all => 'no longer valid'; use MooX::Struct Thingy => [qw/ $x /]; ok not eval { my $thingy = Thingy->new(y => 1) }; 11extend.t000664001750001750 362113044133375 14547 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Check the experimental C method. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use Test::More; use MooX::Struct Point => [qw( +x +y )]; my $point = Point[]; my $old_id = $point->OBJECT_ID; is($point->TYPE, 'Point'); is_deeply([$point->FIELDS], ['x', 'y']); ok( $point->can('x')); ok( $point->can('y')); ok(!$point->can('z')); $point->EXTEND(\"Point3D", '+z'); is($point->TYPE, 'Point3D'); is_deeply([$point->FIELDS], ['x', 'y', 'z']); ok( $point->can('x')); ok( $point->can('y')); ok( $point->can('z')); is($point->OBJECT_ID, $old_id, 'OBJECT_ID does not change during EXTEND'); my $new = $point->CLONE(z => 0)->EXTEND(\"Point4D", '+w'); is_deeply([$point->FIELDS], ['x', 'y', 'z']); is_deeply([$new->FIELDS], ['x', 'y', 'z', 'w']); isnt($new->OBJECT_ID, $old_id, 'OBJECT_ID does change during CLONE+EXTEND'); use MooX::Struct Person => ['$name']; my $Employee = Person->EXTEND(\"Employee", '$title'); isa_ok($Employee, Person); my $bob = $Employee->new(['Robert', 'Staff']); isa_ok($bob, $Employee); isa_ok($bob, Person); is($bob->TYPE, 'Employee'); is_deeply([$bob->FIELDS], [qw/ name title /]); is($bob->name, 'Robert'); is($bob->title, 'Staff'); ok !eval { $bob->title('Manager') }; # read-only my $PromotableEmployee = Person->EXTEND(-rw, \"PromotableEmployee", '$title'); isa_ok($PromotableEmployee, Person); my $alice = $PromotableEmployee->new(['Alice', 'Staff']); isa_ok($alice, $PromotableEmployee); isa_ok($alice, Person); is($alice->TYPE, 'PromotableEmployee'); is_deeply([$alice->FIELDS], [qw/ name title /]); is($alice->name, 'Alice'); is($alice->title, 'Staff'); $alice->title('Manager'); # read-write is($alice->title, 'Manager'); done_testing; 12lexical.t000664001750001750 172313044133375 14703 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Check that struct aliases are lexical, but can be made permanent using the C<< -retain >> flag. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use Test::More; { package Local::Foo1; use MooX::Struct Bar => [qw($name)], ; ::ok( Bar->can('name'), 'Bar class available inside Local::Foo1', ); } { package Local::Foo2; use MooX::Struct -retain, Bar => [qw($name)], ; ::ok( Bar->can('name'), 'Bar class available inside Local::Foo2', ); } ::ok( !'Local::Foo1'->can('Bar'), "Bar class unavailable outside Local::Foo1", ); ::ok( 'Local::Foo2'->can('Bar'), "Bar class available outside Local::Foo2", ); ::ok( Local::Foo2::Bar->can('name'), "Bar class works outside Local::Foo2", ); done_testing; 13basestruct.t000664001750001750 102713044133375 15437 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Checks that MooX::Struct itself can be instantiated and works as expected. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use warnings; use Test::More; use MooX::Struct; my $obj = MooX::Struct->new; is($obj->TYPE, undef); is_deeply([$obj->FIELDS], []); done_testing; 14trace.t000664001750001750 345613044133375 14367 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Tests the output of the "-trace" feature. Checks that the C environment variable is honoured. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use warnings; use if ($] < 5.010), 'Test::More', skip_all => 'need Perl 5.10'; use Test::More; use 5.010; use MooX::Struct (); use IO::Handle; my $default = "MooX::Struct::Processor"->new(trace => 1); is($default->trace_handle, \*STDERR); my $output; open my $handle, '>', \$output; my $proc = "MooX::Struct::Processor"->new(trace => 1, trace_handle => $handle); $proc->process( __PACKAGE__, Something => ['$foo', announce_foo => sub { say shift->foo } ], ); my $obj = new_ok Something(), [[1]]; is($output, <<"EXPECTED"); package @{[ Something() ]}; use Moo; has foo => ('is' => 'ro','isa' => sub { "DUMMY" }); sub announce_foo { ... } sub FIELDS { ... } sub TYPE { ... } EXPECTED $output = ''; BEGIN { package Local::Role; use Moo::Role; requires 'foo'; }; $proc->flags->{deparse} = 1; $proc->process( __PACKAGE__, SomethingElse => [ -class => \'Something::Else', -isa => [Something()], -with => ['Local::Role'], announce_foo => sub { my $self = shift; print $self->foo, "\n" }, '+number', 'random', ], ); $obj = new_ok SomethingElse(), [[1]]; like($output, qr{package Something::Else}); like($output, qr{with qw.Local::Role.}); like($output, qr{print \$self->foo}); like($output, qr{looks_like_number}); { local $ENV{PERL_MOOX_STRUCT_TRACE} = 1; ok "MooX::Struct::Processor"->new->trace; } ok not "MooX::Struct::Processor"->new->trace; done_testing; 96processor.t000664001750001750 134513044133375 15315 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Checks some places where MooX::Struct::Processor is expected to fail. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use warnings; use Test::More; use MooX::Struct (); ok not eval { "MooX::Struct::Processor"->new(flags => 1); }; ok not eval { "MooX::Struct::Processor"->new(class_map => 1); }; ok not eval { "MooX::Struct::Processor"->new->process( __PACKAGE__, Foo => [ -monkey => ['Albert'] ], ); Foo(); }; like($@, qr{option '-monkey' unknown}); done_testing; 97dataprinter.t000664001750001750 212213044133375 15606 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Test Data::Printer support for structs. Skipped if Data::Printer is not installed. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use warnings; use if !eval{ require Data::Printer; $Data::Printer::VERSION >= 0.36 }, 'Test::More', skip_all => 'need Data::Printer'; use Test::More; use Data::Printer colored => 0, return_value => 'dump'; use MooX::Struct Something => [qw( $foo bar )]; my $obj = Something->new(foo => 1, bar => 2); my $str = p $obj; is($str, 'Something[ 1, 2 ]'); my $ob2 = Something->new(foo => "Hello\nWorld", bar => ["A","B\nC","D"]); my $st2 = p $ob2; like("$st2\n", qr{^Something\[\n}s, 'dump including line breaks'); my $ext = Something->EXTEND('$baz')->new([1, 2, 3]); my $pxt = p $ext; is($pxt, 'Something[ 1, 2, 3 ]'); my $bas = MooX::Struct->new; my $pas = p $bas; is($pas, 'struct[ ]'); done_testing; 98baseclass.t000664001750001750 352013044133375 15235 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Tests that a MooX::Struct::Processor, configured with a base class that has some attributes, will generate structs that are aware of those attributes (shows them in C). =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use warnings; use Test::More; use MooX::Struct Foo => ['$foo']; BEGIN { "MooX::Struct::Processor" -> new( base => Foo, flags => { retain => 1 }, ) -> process( main => ( Bar => ['$bar'], Baz => ['$baz', -class => \'Baz'], ), ) ; }; is_deeply( [ Foo->FIELDS ], [ qw( foo ) ], ); isa_ok(Bar, Foo); is_deeply( [ Bar->FIELDS ], [ qw( foo bar ) ], ); isa_ok(Baz, Foo); is_deeply( [ Baz->FIELDS ], [ qw( foo baz ) ], ); my $bar = Bar[1, 2]; is($bar->foo, 1); is($bar->bar, 2); # The "interesting" thing about this package is that it provides # no FIELDS method. BEGIN { package Quux; use Moo; has bumf => (is => 'rw'); }; BEGIN { "MooX::Struct::Processor" -> new( base => 'Quux', flags => { retain => 1 }, ) -> process( main => ( Quuux => ['$xyzzy'], Quuuux => (), ), ) ; }; my $quuux = Quuux->new(xyzzy => 4, bumf => 2); is_deeply([$quuux->FIELDS], ['xyzzy']); is($quuux->xyzzy, 4); is($quuux->bumf, 2); like(ref $quuux, qr{^Quux::__ANON__::}); my $quuuux = Quuuux->new(bumf => 2); is_deeply([$quuuux->FIELDS], []); is($quuuux->bumf, 2); like(ref $quuuux, qr{^Quux::__ANON__::}); BEGIN { "MooX::Struct::Processor" -> new( flags => { retain => 1 }, ) -> process( main => ( Quux2 => [ -extends=>['Quux'], '$xyzzy' ], ), ) ; }; is_deeply([Quux2->FIELDS], ['xyzzy']); done_testing; 99lazy.t000664001750001750 114713044133375 14260 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 PURPOSE Check C from C. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use Test::More; use MooX::Struct::Util qw/ lazy_default /; use MooX::Struct Point => [ '+x', '+y' ]; use MooX::Struct Line => [ '$start' => lazy_default { Point[] }, '$end' ]; my $line = Line->new( end => Point[ 2, 3 ] ); is("$line", "0 0 2 3"); done_testing();readme.pod000664001750001750 22013044133375 14642 0ustar00taitai000000000000MooX-Struct-0.014/t=head1 TEST COVERAGE As of 0.010, according to L the test coverage for L and L is 100%. =cut Struct.pm000664001750001750 4510413044133375 15762 0ustar00taitai000000000000MooX-Struct-0.014/lib/MooXpackage MooX::Struct; use 5.008; use strict; use warnings; use utf8; BEGIN { $MooX::Struct::AUTHORITY = 'cpan:TOBYINK'; $MooX::Struct::VERSION = '0.014'; } use Moo 1.000000; use Object::ID 0 qw( ); use Scalar::Does 0 qw( does ); use overload q[""] => 'TO_STRING', q[bool] => sub { 1 }, q[@{}] => 'TO_ARRAY', q[=] => 'CLONE', fallback => 1; METHODS: { no warnings; sub OBJECT_ID { goto \&Object::ID::object_id }; sub FIELDS { qw() }; sub TYPE { +undef }; sub TO_ARRAY { [ map {; $_[0]->$_ } $_[0]->FIELDS ] }; sub TO_HASH { +{ map {; $_ => $_[0]->$_ } $_[0]->FIELDS } }; sub TO_STRING { join q[ ], @{ $_[0]->TO_ARRAY } }; sub CLONE { my $s = shift; ref($s)->new(%{$s->TO_HASH}, @_) }; }; sub BUILDARGS { my $class = shift; my @fields = $class->FIELDS; if ( @_ == 1 and does($_[0], 'ARRAY') and not does($_[0], 'HASH') ) { my @values = @{ $_[0] }; Carp::confess("too many values passed to constructor (expected @fields); stopped") unless @fields >= @values; no warnings; return +{ map { $fields[$_] => $values[$_]; } 0 .. $#values } } elsif (@_ == 1 and does($_[0], 'HASH') and not ref($_[0]) eq 'HASH') { # help Moo::Object! @_ = +{ %{$_[0]} }; } my $hashref = $class->SUPER::BUILDARGS(@_); # my %tmp = map { $_ => 1 } keys %$hashref; # delete $tmp{$_} for @fields; # if (my @unknown = sort keys %tmp) # { # Carp::confess("unknown keys passed to constructor (@unknown); stopped"); # } return $hashref; } sub EXTEND { my ($invocant, @args) = @_; my $base = $invocant; $base = ref $invocant if ref $invocant; my $processor = 'MooX::Struct::Processor'->new; while (@args) { last unless $args[0] =~ /^-(.+)$/; $processor->flags->{ lc($1) } = !!shift @args; } my $subname = undef; $subname = ${ shift @args } if ref($args[0]) eq 'SCALAR'; my $new_class = $processor->make_sub( $subname, [ -extends => [$base], @args ], )->(); return $new_class unless ref $invocant; bless $invocant => $new_class; } # This could do with some improvement from a Data::Printer expert. # my $done = 0; sub _data_printer { require Data::Printer::Filter; require Term::ANSIColor; my $self = shift; my @values = map { scalar &Data::Printer::p(\$_, return_value => 'dump') } @$self; my $label = Term::ANSIColor::colored($self->TYPE||'struct', 'bright_yellow'); if (grep /\n/, @values) { return sprintf( "%s[\n\t%s,\n]", $label, join(qq[,\n\t], map { s/\n/\n\t/gm; $_ } @values), ); } sprintf('%s[ %s ]', $label, join q[, ], @values); } BEGIN { package MooX::Struct::Processor; { no warnings; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.014'; } sub _uniq { my %seen; grep { not $seen{$_}++ } @_ }; use Moo 1.000000; use Carp 0 qw( confess ); use Data::OptList 0 qw( ); use Sub::Install 0 qw( install_sub ); use Scalar::Does 0 qw( does blessed looks_like_number ); use namespace::clean qw( ); use B::Hooks::EndOfScope qw( on_scope_end ); has flags => ( is => 'ro', isa => sub { die "flags must be HASH" unless does $_[0], 'HASH' }, default => sub { +{} }, ); has class_map => ( is => 'ro', isa => sub { die "class_map must be HASH" unless does $_[0], 'HASH' }, default => sub { +{} }, ); has base => ( is => 'ro', default => sub { 'MooX::Struct' }, ); has trace => ( is => 'lazy', ); sub _build_trace { $ENV{PERL_MOOX_STRUCT_TRACE} or shift->flags->{trace}; } has trace_handle => ( is => 'lazy', ); sub _build_trace_handle { require IO::Handle; \*STDERR; } my $counter = 0; sub create_class { my ($self, $opts) = @_; my $klass; for my $o (@$opts) { next unless $o->[0] eq '-class'; $klass = ref($o->[1]) eq 'ARRAY' ? join('::', @{$o->[1]}) : ${$o->[1]}; last; } $klass = sprintf('%s::__ANON__::%04d', $self->base, ++$counter) unless defined $klass; "Moo"->_set_superclasses($klass, $self->base); "Moo"->_maybe_reset_handlemoose($klass); if ($self->trace) { $self->trace_handle->printf( "package %s;\nuse Moo;\n", $klass, ); } return $klass; } sub process_meta { my ($self, $klass, $name, $val) = @_; if ($name eq '-extends' or $name eq '-isa') { my @parents = map { exists $self->class_map->{$_} ? $self->class_map->{$_}->() : $_ } @$val; "Moo"->_set_superclasses($klass, @parents); "Moo"->_maybe_reset_handlemoose($klass); if ($self->trace) { $self->trace_handle->printf( "extends qw(%s)\n", join(q[ ] => @parents), ); } return map { $_->can('FIELDS') ? $_->FIELDS : () } @parents; } elsif ($name eq '-with') { require Moo::Role; "Moo::Role"->apply_roles_to_package($klass, @$val); "Moo"->_maybe_reset_handlemoose($klass); if ($self->trace) { $self->trace_handle->printf( "with qw(%s)\n", join(q[ ] => @$val), ); } return # map { my $role = $_; grep { not ref $_ } @{ $Moo::Role::INFO{$role}{attributes} } } # @$val; } elsif ($name eq '-class') { # skip; already handled by 'create_class' method (hopefully) } else { confess("option '$name' unknown"); } return; } sub process_method { my ($self, $klass, $name, $coderef) = @_; install_sub { into => $klass, as => $name, code => $coderef, }; if ($self->trace) { $self->trace_handle->printf( "sub %s { ... }\n", $name, ); if ($self->flags->{deparse}) { require B::Deparse; my $code = "B::Deparse"->new(qw(-q -si8T))->coderef2text($coderef); $code =~ s/^/# /mig; $self->trace_handle->printf("$code\n"); } } return; } sub process_spec { my ($self, $klass, $name, $val) = @_; my %spec = ( is => ($self->flags->{rw} ? 'rw' : 'ro'), ( does($val, 'ARRAY') ? @$val : ( does($val,'HASH') ? %$val : () ) ), ); if ($name =~ /^(.+)\!$/) { $name = $1; $spec{required} = 1; } if ($name =~ /^\@(.+)/) { $name = $1; $spec{isa} ||= sub { die "wrong type for '$name' (not arrayref)" unless does($_[0], 'ARRAY'); }; } elsif ($name =~ /^\%(.+)/) { $name = $1; $spec{isa} ||= sub { die "wrong type for '$name' (not hashref)" unless does($_[0], 'HASH'); }; } elsif ($name =~ /^\+(.+)/) { $name = $1; $spec{isa} ||= sub { die "wrong type for '$name' (not number)" unless looks_like_number($_[0]); }; $spec{default} ||= sub { 0 } unless $spec{required}; } elsif ($name =~ /^\$(.+)/) { $name = $1; $spec{isa} ||= sub { my $ref = ref($_[0]); die "wrong type for '$name' (should not be arrayref or hashref)" if $ref eq 'ARRAY' || $ref eq 'HASH'; }; } return ($name, \%spec); } sub process_attribute { my ($self, $klass, $name, $val) = @_; my $spec; ($name, $spec) = $self->process_spec($klass, $name, $val); if ($self->trace) { require Data::Dumper; my $spec_str = "Data::Dumper"->new([$spec])->Terse(1)->Indent(0)->Sortkeys(1)->Dump; $spec_str =~ s/(^\{)|(\}$)//g; $self->trace_handle->printf( "has %s => (%s);\n", $name, $spec_str, ); if ($self->flags->{deparse} and $spec->{isa}) { require B::Deparse; my $code = "B::Deparse"->new(qw(-q -si8T))->coderef2text($spec->{isa}); $code =~ s/^/# /mig; $self->trace_handle->printf("$code\n"); } } "Moo" ->_constructor_maker_for($klass) ->register_attribute_specs($name, $spec); "Moo" ->_accessor_maker_for($klass) ->generate_method($klass, $name, $spec); "Moo" ->_maybe_reset_handlemoose($klass); return $name; } # returns a list of "fields" resulting from the argument sub process_argument { my $self = shift; my ($klass, $name, $val) = @_; return $self->process_meta(@_) if $name =~ /^-/; return $self->process_method(@_) if does($val, 'CODE'); return $self->process_attribute(@_); } sub make_sub { my ($self, $subname, $proto) = @_; return sub (;$) { 1; # bizarre, but necessary if $] < 5.014 if (ref $proto) # inflate! { my $opts = Data::OptList::mkopt($proto); my $klass = $self->create_class($opts); my $seen_extends; my @fields = _uniq map { ++$seen_extends if $_->[0] eq '-extends'; $self->process_argument($klass, @$_); } @$opts; unshift @fields, $self->base->FIELDS if !$seen_extends && $self->base->can('FIELDS'); $self->process_method($klass, FIELDS => sub { @fields }); $self->process_method($klass, TYPE => sub { $subname }) if defined $subname; $proto = $klass; } return $proto->new(@_) if @_; return $proto; } } sub process { my $self = shift; my $caller = shift; while (@_ and $_[0] =~ /^-(.+)$/) { $self->flags->{ lc($1) } = !!shift; } foreach my $arg (@{ Data::OptList::mkopt(\@_) }) { my ($subname, $details) = @$arg; $details = [] unless defined $details; $self->class_map->{ $subname } = $self->make_sub($subname, $details); install_sub { into => $caller, as => $subname, code => $self->class_map->{ $subname }, }; } on_scope_end { namespace::clean->clean_subroutines( $caller, keys %{ $self->class_map }, ); } unless $self->flags->{ retain }; } }; sub import { my $caller = caller; my $class = shift; "$class\::Processor"->new->process($caller, @_); } no Moo; 1; __END__ =head1 NAME MooX::Struct - make simple lightweight record-like structures that make sounds like cows =head1 SYNOPSIS use MooX::Struct Point => [ 'x', 'y' ], Point3D => [ -extends => ['Point'], 'z' ], ; my $origin = Point3D->new( x => 0, y => 0, z => 0 ); # or... my $origin = Point3D[ 0, 0, 0 ]; =head1 DESCRIPTION MooX::Struct allows you to create cheap struct-like classes for your data using L. While similar in spirit to L and L, MooX::Struct has a somewhat different usage pattern. Rather than providing you with a C keyword which can be used to define structs, you define all the structs as part of the C statement. This means they happen at compile time. A struct is just an "anonymous" Moo class. MooX::Struct creates this class for you, and installs a lexical alias for it in your namespace. Thus your module can create a "Point3D" struct, and some other module can too, and they won't interfere with each other. All struct classes inherit from MooX::Struct. Arguments for MooX::Struct are key-value pairs, where keys are the struct names, and values are arrayrefs. use MooX::Struct Person => [qw/ name address /], Company => [qw/ name address registration_number /]; The elements in the array are the attributes for the struct (which will be created as read-only attributes), however certain array elements are treated specially. =over =item * As per the example in the L, C<< -extends >> introduces a list of parent classes for the struct. If not specified, then classes inherit from MooX::Struct itself. Structs can inherit from other structs, or from normal classes. If inheriting from another struct, then you I define both in the same C statement. Inheriting from a non-struct class is discouraged. # Not like this. use MooX::Struct Point => [ 'x', 'y' ]; use MooX::Struct Point3D => [ -extends => ['Point'], 'z' ]; # Like this. use MooX::Struct Point => [ 'x', 'y' ], Point3D => [ -extends => ['Point'], 'z' ], ; =item * Similarly C<< -with >> consumes a list of roles. =item * If an attribute name is followed by a coderef, this is installed as a method instead. use MooX::Struct Person => [ qw( name age sex ), greet => sub { my $self = shift; CORE::say "Hello ", $self->name; }, ]; But if you're defining methods for your structs, then you've possibly missed the point of them. =item * If an attribute name is followed by an arrayref, these are used to set the options for the attribute. For example: use MooX::Struct Person => [ name => [ is => 'ro', required => 1 ] ]; Using the C option would probably break stuff. Don't do that. =item * Attribute names may be "decorated" with prefix and postfix "sigils". The prefix sigils of C<< @ >> and C<< % >> specify that the attribute isa arrayref or hashref respectively. (Blessed arrayrefs and hashrefs are accepted; as are objects which overload C<< @{} >> and C<< %{} >>.) The prefix sigil C<< $ >> specifies that the attribute value must not be an unblessed arrayref or hashref. The prefix sigil C<< + >> indicates the attribute is a number, and provides a default value of 0, unless the attribute is required. The postfix sigil C<< ! >> specifies that the attribute is required. use MooX::Struct Person => [qw( $name! @children )]; Person->new(); # dies, name is required Person->new( # dies, children should be arrayref name => 'Bob', children => 2, ); =back Prior to the key-value list, some additional flags can be given. These begin with hyphens. The flag C<< -rw >> indicates that attributes should be read-write rather than read-only. use MooX::Struct -rw, Person => [ qw( name age sex ), greet => sub { my $self = shift; CORE::say "Hello ", $self->name; }, ]; The C<< -retain >> flag can be used to indicate that MooX::Struct should B use namespace::clean to enforce lexicalness on your struct class aliases. Flags C<< -trace >> and C<< -deparse >> may be of use debugging. =head2 Instantiating Structs There are two supported methods of instatiating structs. You can use a traditional class-like constructor with named parameters: my $point = Point->new( x => 1, y => 2 ); Or you can use the abbreviated syntax with positional parameters: my $point = Point[ 1, 2 ]; If you know about Moo and peek around in the source code for this module, then I'm sure you can figure out additional ways to instantiate them, but the above are the only supported two. When inheritance or roles have been used, it might not always be clear what order the positional parameters come in (though see the documentation for the C below), so the traditional class-like style may be preferred. =head2 Methods Structs are objects and thus have methods. You can define your own methods as described above. MooX::Struct's built-in methods will always obey the convention of being in ALL CAPS (except in the case of C<_data_printer>). By using lower-case letters to name your own methods, you can avoid naming collisions. The following methods are currently defined. Additionally all the standard Perl (C, C, etc) and Moo (C, C, etc) methods are available. =over =item C Returns a unique identifier for the object. =item C Returns a list of fields associated with the object. For the C struct in the SYNPOSIS, this would be C<< 'x', 'y', 'z' >>. The order the fields are returned in is equal to the order they must be supplied for the positional constructor. Attributes inherited from roles, or from non-struct base classes are not included in C, and thus cannot be used in the positional constructor. =item C Returns the type name of the struct, e.g. C<< 'Point3D' >>. =item C Returns a reference to an unblessed hash where the object's fields are the keys and the object's values are the hash values. =item C Returns a reference to an unblessed array where the object's values are the array items, in the same order as listed by C. =item C Joins C with whitespace. This is not necessarily a brilliant stringification, but easy enough to overload: use MooX::Struct Point => [ qw( x y ), TO_STRING => sub { sprintf "(%d, %d)"), $_[0]->x, $_[0]->y; }, ] ; =item C Creates a shallow clone of the object. =item C An exverimental feature. Extend a class or object with additional attributes, methods, etc. This method takes almost all the same arguments as C, albeit with some slight differences. use MooX::Struct Point => [qw/ +x +y /]; my $point = Point[2, 3]; $point->EXTEND(-rw, q/+z/); # extend an object $point->can('z'); # true my $new_class = Point->EXTEND('+z'); # extend a class my $point_3d = $new_class->new( x => 1, y => 2, z => 3 ); $point_3d->TYPE; # Point ! my $point_4d = $new_class->EXTEND(\"Point4D", '+t'); $point_4d->TYPE; # Point4D my $origin = Point[]->EXTEND(-with => [qw/ Math::Role::Origin /]); This feature has been included mostly because it's easy to implement on top of the existing code for processing C. Some subsets of this functionality are sane, such as the ability to add traits to an object. Others (like the ability to add a new uninitialized, read-only attribute to an existing object) are less sensible. =item C Moo internal fu. =item C<_data_printer> Automatic pretty printing with L. use Data::Printer; use MooX::Struct Point => [qw/ +x +y /]; my $origin = Point[]; p $origin; Use Data::Printer 0.36 or above please. =back With the exception of C and C, any of these can be overridden using the standard way of specifying methods for structs. =head2 Overloading MooX::Struct overloads stringification and array dereferencing. Objects always evaluate to true in a boolean context. (Even if they stringify to the empty string.) =head1 CAVEATS Because you only get an alias for the struct class, you need to be careful with some idioms: my $point = Point3D->new(x => 1, y => 2, z => 3); $point->isa("Point3D"); # false! $point->isa( Point3D ); # true my %args = (...); my $class = exists $args{z} ? "Point3D" : "Point"; # wrong! $class->new(%args); my $class = exists $args{z} ? Point3D : Point ; # right $class->new(%args); =head1 BUGS Please report any bugs to L. =head1 SEE ALSO L, L, L, L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2013, 2017 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 DISCLAIMER OF WARRANTIES 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. Util.pm000664001750001750 303113044133375 16650 0ustar00taitai000000000000MooX-Struct-0.014/lib/MooX/Structpackage MooX::Struct::Util; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.014'; use strict; use warnings; use Sub::Install qw(install_sub); sub import { my $class = shift; my $caller = caller; install_sub { code => $_, from => $class, into => $caller } for @_; } sub lazy_default (&) { my $sub = shift; return [ lazy => 1, default => $sub, ]; } 1; __END__ =head1 NAME MooX::Struct::Util - extensions for MooX::Struct that would have been overkill to include =head1 LAZY DEFAULTS =begin trustme =item lazy_default =end trustme Sugar for lazily defaulted attributes. The following two are effectively the same. use MooX::Struct WebPage1 => [ user_agent => [ lazy => 1, default => sub { LWP::UserAgent->new }, ], ]; use MooX::Struct::Util qw(lazy_default); use MooX::Struct WebPage2 => [ user_agent => lazy_default { LWP::UserAgent->new }, ]; =head1 BUGS Please report any bugs to L. =head1 SEE ALSO L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2013, 2017 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 DISCLAIMER OF WARRANTIES 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.