COPYRIGHT000644001750001750 311713625500410 13745 0ustar00taitai000000000000MooX-Struct-0.020Format: 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 2020 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: README lib/MooX/Struct.pm lib/MooX/Struct/Util.pm Copyright: This software is copyright (c) 2012-2013, 2017-2018 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: COPYRIGHT CREDITS SIGNATURE Copyright: None License: public-domain Files: dist.ini Copyright: Copyright 2014 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 License: Artistic-1.0 This software is Copyright (c) 2020 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) 2020 by the copyright holder(s). This is free software, licensed under: The GNU General Public License, Version 1, February 1989 CREDITS000644001750001750 31213625500407 13452 0ustar00taitai000000000000MooX-Struct-0.020Maintainer: - Toby Inkster (TOBYINK) Contributor: - NOBODY Thanks: - - Chris Prather (PERIGRIN) - Graham Knop (HAARG) Changes000644001750001750 741213625500407 13755 0ustar00taitai000000000000MooX-Struct-0.020MooX-Struct =========== Created: 2012-10-04 Home page: Bug tracker: Maintainer: Toby Inkster (TOBYINK) 0.020 2020-20-26 [ Packaging ] - Require newer namespace::autoclean. 0.019 2020-20-25 - The TYPE_TINY method now returns a type constraint with a coercion from ArrayRef|HashRef. - Tidy up MooX::Struct namespace using namespace::autoclean. 0.018 2020-20-25 - Updated: Support for Data::Printer 0.99 trial versions. 0.017 2018-06-09 [ Documentation ] - Better method documentation. [ Other ] - Added: CLASSNAME method. - Added: TYPE_TINY method. 0.016 2017-05-23 [ Test Suite ] - Remove stray usage of Scalar::Does in test suite. 0.015 2017-05-11 - Updated: Eliminate dependency on Data::OptList. - Updated: Eliminate dependency on Scalar::Does. (Use Type::Tiny instead, which Scalar::Does depended on anyway.) - Updated: Eliminate dependency on Sub::Install. (Use Exporter::Tiny instead, which Scalar::Does depended on anyway.) 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 INSTALL000644001750001750 166513625500407 13517 0ustar00taitai000000000000MooX-Struct-0.020 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 LICENSE000644001750001750 4365513625500407 13520 0ustar00taitai000000000000MooX-Struct-0.020This software is copyright (c) 2020 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) 2020 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) 2020 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 MANIFEST000644001750001750 73213625500410 13563 0ustar00taitai000000000000MooX-Struct-0.020COPYRIGHT 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.json000644001750001750 440513625500410 14074 0ustar00taitai000000000000MooX-Struct-0.020{ "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.024, CPAN::Meta::Converter version 2.150010", "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", "Exporter::Tiny" : "0.044", "Moo" : "1.000000", "Object::ID" : "0", "Type::Tiny" : "1.000000", "namespace::autoclean" : "0.19", "perl" : "5.008" } }, "test" : { "requires" : { "Moo" : "1.006000", "Test::More" : "0.61" } } }, "provides" : { "MooX::Struct" : { "file" : "lib/MooX/Struct.pm", "version" : "0.020" }, "MooX::Struct::Processor" : { "file" : "lib/MooX/Struct.pm", "version" : "0.020" }, "MooX::Struct::Util" : { "file" : "lib/MooX/Struct/Util.pm", "version" : "0.020" } }, "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.020", "x_contributors" : [ "NOBODY" ], "x_serialization_backend" : "JSON::PP version 2.27400_02", "x_static_install" : 1 } META.yml000644001750001750 262013625500410 13721 0ustar00taitai000000000000MooX-Struct-0.020--- abstract: 'make simple lightweight record-like structures that make sounds like cows' author: - 'Toby Inkster (TOBYINK) ' build_requires: Moo: '1.006000' Test::More: '0.61' configure_requires: ExtUtils::MakeMaker: '6.17' dynamic_config: 0 generated_by: 'Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150010' 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.020' MooX::Struct::Processor: file: lib/MooX/Struct.pm version: '0.020' MooX::Struct::Util: file: lib/MooX/Struct/Util.pm version: '0.020' requires: B::Hooks::EndOfScope: '0' Exporter::Tiny: '0.044' Moo: '1.000000' Object::ID: '0' Type::Tiny: '1.000000' namespace::autoclean: '0.19' 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.020' x_contributors: - NOBODY x_serialization_backend: 'CPAN::Meta::YAML version 0.018' x_static_install: 1 Makefile.PL000644001750001750 1263613625500410 14452 0ustar00taitai000000000000MooX-Struct-0.020use 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.024, CPAN::Meta::Converter version 2.150010", "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, "Exporter::Tiny" => 0.044, "Moo" => "1.000000", "namespace::autoclean" => 0.19, "Object::ID" => 0, "perl" => 5.008, "Type::Tiny" => "1.000000", }, }, test => { requires => { "Moo" => "1.006000", "Test::More" => 0.61 } }, }, "provides" => { "MooX::Struct" => { file => "lib/MooX/Struct.pm", version => "0.020" }, "MooX::Struct::Processor" => { file => "lib/MooX/Struct.pm", version => "0.020" }, "MooX::Struct::Util" => { file => "lib/MooX/Struct/Util.pm", version => "0.020" }, }, "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.020", "x_contributors" => ["NOBODY"], "x_static_install" => 1, }; 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); NEWS000644001750001750 41613625500407 13136 0ustar00taitai000000000000MooX-Struct-0.0200.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 README000644001750001750 2572413625500407 13370 0ustar00taitai000000000000MooX-Struct-0.020NAME 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. May only be called as an instance method. `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. May be called as an instance or class method. `TYPE` Returns the type name of the struct, e.g. 'Point3D'. May be called as an instance or class method. `CLASSNAME` Returns the internally used package name for the struct, e.g. 'MooX::Struct::__ANON__::0007'. Pretty rare you'd want to see this. May be called as an instance or class method. `TYPE_TINY` Returns a Type::Tiny type constraint corresponding to the CLASSNAME, suitable for a Moose/Moo `isa`. package Foo { use Moo; use MooX::Struct Bar => [qw( $name )]; has left_bar => (is => 'rw', isa => Bar->TYPE_TINY, coerce => 1); has right_bar => (is => 'rw', isa => Bar->TYPE_TINY, coerce => 1); ...; } May be called as an instance or class method. `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. May only be called as an instance method. `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`. May only be called as an instance method. `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; }, ] ; May only be called as an instance method. `CLONE` Creates a shallow clone of the object. May only be called as an instance method. `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. May be called as an instance or class method. `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-2018 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. SIGNATURE000644001750001750 720113625500410 13734 0ustar00taitai000000000000MooX-Struct-0.020This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.83. 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 SHA256 b6cd73325f4daa08eabf8bf889c1ba1e98faee88e673e5d4a25d396075e57f0f COPYRIGHT SHA256 fd267590fa4691dd3067674c0391f1c5cd8785012624a49c8b916012707b2851 CREDITS SHA256 490f930a730370f3b90e19a100a3d8e9a9437ba9f910b5325e33e45371d24f31 Changes SHA256 6008aace15382a000280dce7ffc053858c0fc3e421c0a4396f09148e2f9048c1 INSTALL SHA256 1fb7395e76eabf94c421912d7d0a4f7fa745d49e1acb76b222c21d605b66bd25 LICENSE SHA256 456bc6c99ee29825a71bb8fde53c3efcebe428130392532d8bd53b188bbb9be7 MANIFEST SHA256 ddac35ebb1a69a2835fcaaa792f2e278d8630f60061b132b17bb00e5a36cc05f META.json SHA256 a2c25cb64eb14c79a34bd35d37d0019f96b876d12bab446c230964de9f357d0c META.yml SHA256 53da48a714570a018b7cb7e4ca8c46edf48a3fc8c2bd7be60910d8a50770f14f Makefile.PL SHA256 cef260ae9854c902cf2be31b70e698ad04cbea2f7e3f2265d53f61e8ae5f68ac NEWS SHA256 897d53267bc4ff824853fe2deb924f60c5732a941ff28be29375bc06e055e55d README SHA256 b0a621dcee8da656447d7babf5d176a35cb922aa295c3e405be725c8391086ef dist.ini SHA256 e6641a12b4ee1aef14ca6adbf97e2ba2241402a8b728ce0b514e92db55a2cbeb doap.ttl SHA256 ee6afc0a675dff1b5e9e206c805caf047d987292ede096e5b74a88ee60c9a83b examples/triangle.pl SHA256 bda7f72ca1f560eb1e7bc3aa6336df6e9f749d3e862554d3a49080044c1d6087 lib/MooX/Struct.pm SHA256 9097ad8d71cb660645e1055e02c56a7d88d701e4f0fb7d81fca3569e4c34bfd3 lib/MooX/Struct/Util.pm SHA256 9e8c12d124c0ccbdfae17807bbbfb7d0a69f6c891f1cd43f25f851bbeef1236c t/01basic.t SHA256 e8c216f3abda4e95c6dbd8c5ada2d9c579e4b36352ee40c8a1f83d0a393c46c4 t/02basicusage.t SHA256 d6cd5b3bcb674e6cc3aa304263710b2af3bc9f9405779a8fb26705d3dca8ef40 t/03inherit.t SHA256 e85ad6bbc3d4a4c0bc1d673a54af7a96629f4d826f4f3f395f851d8a4e2f72ae t/04flag.t SHA256 9b924eff631cbaa732a764192eb7b416b017c47b0109366f4f0aeaf1b5b8828d t/05methods.t SHA256 19661967014143485a2d9b943f2a0db5cf3ce6aeb21a9742833342d46f676b64 t/06sigils.t SHA256 fe85cf9081474b209be9c71c31a4d1f2f2a026e3dc17421b09902ec399827439 t/07overloading.t SHA256 f0b8994472e64040afdb49ea17de3925786f1053a03995c2506a372f154f1bab t/08alt-constructor.t SHA256 b93583152f5bdfd699c5a24235bb222cabc9823383451a34e8d0b433ed449942 t/09roles.t SHA256 1a307a221ea12208490fd0c404ea61ee8f16bdf50e74068a8227685f43598ea6 t/10strict-constructor.t SHA256 ef811ad17b529aaac9f4e772d36d4a64ced3b367a3688bb4cddffef5ca82ac21 t/11extend.t SHA256 3c5137e2b5de867dd1198fdd2943ebf1b6da2066370f45b0bf63fa0e49605c71 t/12lexical.t SHA256 cc52f08e0f2306f3d5288be88f4f2d47afa30163d0d83951e9ed40732086c37a t/13basestruct.t SHA256 68f19544c8d5ae5e85588a4c3e1bd589d9c1e1054865d39a7ea5e8ec2f471084 t/14trace.t SHA256 994fcf15fb12cc05c0c3ed33400aa0ca67cc884766aaac0fdf47c16ee5799911 t/96processor.t SHA256 46808ebcdd82771184a9219bba329df0db092764913e68409fd8d8d4be128874 t/97dataprinter.t SHA256 d09617ac643f690ff497f92686358cdf8019a4d1ed235d93e95773c1c2fd6d14 t/98baseclass.t SHA256 cf2af3b230abfa5e5344d850940d3e6b6e69421fbf131e921b52bc40b757a226 t/99lazy.t SHA256 edc6fdf420093a87958fa4ea1f262be13af1991d84050234debb562425a253d7 t/readme.pod -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQRVJKj/4+s6z4WzNujOv4Eoaip9OQUCXlaBCAAKCRDOv4Eoaip9 OaJOAKCH+q6r6G0aAr8mHRH8V5wI4h/SqACdFZqJeHHg4dwLmmhqliZd71fcrR8= =syeb -----END PGP SIGNATURE----- dist.ini000644001750001750 7413625500407 14063 0ustar00taitai000000000000MooX-Struct-0.020;;class='Dist::Inkt::Profile::TOBYINK' ;;name='MooX-Struct' doap.ttl000644001750001750 4510513625500410 14145 0ustar00taitai000000000000MooX-Struct-0.020@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 "Moo 1.000000"^^doap-deps:CpanId ], [ doap-deps:on "namespace::autoclean 0.19"^^doap-deps:CpanId; ], [ doap-deps:on "Object::ID"^^doap-deps:CpanId ], [ doap-deps:on "Type::Tiny 1.000000"^^doap-deps:CpanId; ], [ doap-deps:on "Exporter::Tiny 0.044"^^doap-deps:CpanId; ]; doap-deps:test-requirement [ doap-deps:on "Moo 1.006000"^^doap-deps:CpanId ], [ 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 doap:Version; dc:identifier "MooX-Struct-0.015"^^xsd:string; dc:issued "2017-05-11"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Update; rdfs:label "Eliminate dependency on Scalar::Does. (Use Type::Tiny instead, which Scalar::Does depended on anyway.)"; ], [ a doap-changeset:Update; rdfs:label "Eliminate dependency on Sub::Install. (Use Exporter::Tiny instead, which Scalar::Does depended on anyway.)"; ], [ a doap-changeset:Update; rdfs:label "Eliminate dependency on Data::OptList."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.015"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.016"^^xsd:string; dc:issued "2017-05-23"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Tests; rdfs:label "Remove stray usage of Scalar::Does in test suite."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.016"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.017"^^xsd:string; dc:issued "2018-06-09"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Documentation; rdfs:label "Better method documentation."; ], [ a doap-changeset:Addition; rdfs:label "CLASSNAME method."; ], [ a doap-changeset:Addition; rdfs:label "TYPE_TINY method."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.017"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.018"^^xsd:string; dc:issued "2020-20-25"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Update; rdfs:label "Support for Data::Printer 0.99 trial versions."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.018"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.019"^^xsd:string; dc:issued "2020-20-25"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "Tidy up MooX::Struct namespace using namespace::autoclean."; ], [ a doap-changeset:Change; rdfs:label "The TYPE_TINY method now returns a type constraint with a coercion from ArrayRef|HashRef."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.019"^^xsd:string. a doap:Version; dc:identifier "MooX-Struct-0.020"^^xsd:string; dc:issued "2020-20-26"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Packaging; rdfs:label "Require newer namespace::autoclean."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.020"^^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.pl000644001750001750 57613625500407 16426 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 104713625500407 14332 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 350013625500407 15354 0ustar00taitai000000000000MooX-Struct-0.020/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 => 20; 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'); isa_ok($_->TYPE_TINY, 'Type::Tiny', '$'.lc($_->name).'->TYPE_TINY') for ($alice, $bob, $acme); ok($_->TYPE_TINY->check($_), '$'.lc($_->name).'->TYPE_TINY->check') for ($alice, $bob, $acme); { package Bleh; use Moo; has person => ( is => 'rw', isa => ::Person->TYPE_TINY, coerce => 1 ); } my $bleh = Bleh->new( person => ['Alice'] ); is($bleh->person->name, 'Alice'); $bleh->person({name => 'Bob'}); is($bleh->person->name, 'Bob'); 03inherit.t000644001750001750 417413625500407 14721 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 122113625500407 14157 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 104313625500407 14714 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 525613625500407 14556 0ustar00taitai000000000000MooX-Struct-0.020/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::Util qw( looks_like_number ); use MooX::Struct Structure => [ qw( $value %dict @list ), '@value2' => { isa => sub { die if ref $_[0] } }, '%list2' => [ isa => sub { die unless ref $_[0] eq 'ARRAY' } ], '$dict2' => [ isa => sub { die unless ref $_[0] eq '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.t000644001750001750 153713625500407 15574 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 254613625500407 16430 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 171013625500407 14402 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 112413625500407 17140 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 362113625500407 14541 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 172313625500407 14675 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 102713625500407 15431 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 345413625500407 14357 0ustar00taitai000000000000MooX-Struct-0.020/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' => 'ScalarLike'); 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.t000644001750001750 134513625500407 15307 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 212413625500407 15602 0ustar00taitai000000000000MooX-Struct-0.020/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 ge '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.t000644001750001750 352013625500407 15227 0ustar00taitai000000000000MooX-Struct-0.020/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.t000644001750001750 114713625500407 14252 0ustar00taitai000000000000MooX-Struct-0.020/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.pod000644001750001750 22013625500407 14634 0ustar00taitai000000000000MooX-Struct-0.020/t=head1 TEST COVERAGE As of 0.010, according to L the test coverage for L and L is 100%. =cut Struct.pm000644001750001750 4761013625500407 15760 0ustar00taitai000000000000MooX-Struct-0.020/lib/MooXpackage MooX::Struct; use 5.008; use strict; use warnings; use utf8; BEGIN { $MooX::Struct::AUTHORITY = 'cpan:TOBYINK'; $MooX::Struct::VERSION = '0.020'; } use Moo 1.000; use Types::TypeTiny 1.000 qw( HashLike ArrayLike ); use Types::Standard 1.000 qw( HashRef ArrayRef Num Ref InstanceOf ); use namespace::autoclean; my $HashLike = HashLike | Ref['HASH']; my $ArrayLike = ArrayLike | Ref['ARRAY']; use overload q[""] => 'TO_STRING', q[bool] => sub { 1 }, q[@{}] => 'TO_ARRAY', q[=] => 'CLONE', fallback => 1; METHODS: { no warnings; sub OBJECT_ID { require 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 CLASSNAME { ref($_[0]) or $_[0] }; my %_cache; sub TYPE_TINY { my $class = shift->CLASSNAME; $_cache{$class} ||= (InstanceOf[$class])->plus_constructors(HashRef|ArrayRef, 'new'); } }; sub BUILDARGS { my $class = shift; my @fields = $class->FIELDS; if ( (@_==1 and ref $_[0] eq 'ARRAY') or # optimized usual case (@_==1 and ArrayLike->check($_[0]) and not $HashLike->check($_[0])) ) { 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 ref $_[0] ne 'HASH' and $HashLike->check($_[0])) { # 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; } my $done = 0; sub _data_printer { my ($self, $ddp) = @_; my @values; my $label; if ($Data::Printer::VERSION lt '0.90') { require Data::Printer::Filter; require Term::ANSIColor; @values = map scalar(&Data::Printer::p(\$_, return_value => 'dump')), @$self; $label = Term::ANSIColor::colored($self->TYPE||'struct', 'bright_yellow'); } else { @values = map $ddp->parse(\$_), @$self; $label = $ddp->maybe_colorize($self->TYPE||'struct', 'MooX::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.020'; } sub _uniq { my %seen; grep { not $seen{$_}++ } @_ }; use Moo 1.000; use Exporter::Tiny qw(); use Types::TypeTiny 1.000 qw( TypeTiny CodeLike HashLike ArrayLike ); use Types::Standard 1.000 qw( HashRef ArrayRef CodeRef Num ); use Carp qw(confess); use Scalar::Util qw(blessed); use namespace::clean qw(); use B::Hooks::EndOfScope qw(on_scope_end); sub __install_sub__ ($) { my $args = shift; my ($pkg, $name, $code) = @$args{qw(into as code)}; no strict 'refs'; *{"$pkg\::$name"} = $code; } has flags => ( is => 'ro', isa => HashLike, default => sub { +{} }, ); has class_map => ( is => 'ro', isa => HashLike, 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 = ArrayRef->check($o->[1]) ? 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; } my $ScalarLike; sub process_spec { my ($self, $klass, $name, $val) = @_; my %spec = ( is => ($self->flags->{rw} ? 'rw' : 'ro'), ( ArrayLike->check($val) ? @$val : ( HashLike->check($val) ? %$val : () ) ), ); if ($name =~ /^(.+)\!$/) { $name = $1; $spec{required} = 1; } if ($name =~ /^\@(.+)/) { $name = $1; $spec{isa} ||= ArrayLike; } elsif ($name =~ /^\%(.+)/) { $name = $1; $spec{isa} ||= HashLike; } elsif ($name =~ /^\+(.+)/) { $name = $1; $spec{isa} ||= Num; $spec{default} ||= sub { 0 } unless $spec{required}; } elsif ($name =~ /^\$(.+)/) { $ScalarLike ||= (~(ArrayRef|HashRef))->create_child_type(name => 'ScalarLike'); $name = $1; $spec{isa} ||= $ScalarLike; } 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 %sanespec = %$spec; if (TypeTiny->check($sanespec{isa})) { $sanespec{isa} = $sanespec{isa}->display_name; } my $spec_str = "Data::Dumper"->new([\%sanespec])->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 CodeRef->check($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_method(@_) if CodeLike->check($val); return $self->process_meta(@_) if $name =~ /^-/; 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 = Exporter::Tiny::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 (@{ Exporter::Tiny::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, @_); } 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. May only be called as an instance method. =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. May be called as an instance or class method. =item C Returns the type name of the struct, e.g. C<< 'Point3D' >>. May be called as an instance or class method. =item C Returns the internally used package name for the struct, e.g. C<< 'MooX::Struct::__ANON__::0007' >>. Pretty rare you'd want to see this. May be called as an instance or class method. =item C Returns a L type constraint corresponding to the CLASSNAME, suitable for a Moose/Moo C. package Foo { use Moo; use MooX::Struct Bar => [qw( $name )]; has left_bar => (is => 'rw', isa => Bar->TYPE_TINY, coerce => 1); has right_bar => (is => 'rw', isa => Bar->TYPE_TINY, coerce => 1); ...; } May be called as an instance or class method. =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. May only be called as an instance method. =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. May only be called as an instance method. =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; }, ] ; May only be called as an instance method. =item C Creates a shallow clone of the object. May only be called as an instance method. =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. May be called as an instance or class method. =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-2018 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.pm000644001750001750 272613625500407 16654 0ustar00taitai000000000000MooX-Struct-0.020/lib/MooX/Structpackage MooX::Struct::Util; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.020'; use strict; use warnings; use Exporter::Tiny (); our @ISA = qw(Exporter::Tiny); our @EXPORT = qw(lazy_default); 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-2018 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.