MooseX-Types-Structured-0.30/000755 000767 000024 00000000000 12254674163 016400 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/Build.PL000644 000767 000024 00000000066 12254674163 017676 0ustar00etherstaff000000 000000 use 5.008; use Module::Build::Tiny 0.030; Build_PL(); MooseX-Types-Structured-0.30/Changes000644 000767 000024 00000016252 12254674163 017701 0ustar00etherstaff000000 000000 Revision history for MooseX-Types-Structured 0.30 2013-12-19 22:51:17Z - remove pod from internal and unindexed modules, for a prettier metacpan release page 0.29 2013-11-20 23:36:48Z - fixed use of an interface that was deprecated in Moose-2.1100 (ether) - repository migrated from shadowcat to the github moose organization 0.28 2011-10-03 - Fixed regression where mixed type constraints (MX:Types style and 'classic' Stringy style) are used in a single structured type doesn't work. 0.27 2011-04-28 - test fixes for new Moose 0.26 2011-01-02 - removed version from Test::Fatal as asked by the debian folks - small documentation updates 0.25 2010-12-28 - fixed bug where ->is_subtype_of dies meaninglessly when the type we are trying to check is not a type we can find. This makes our handling consistent with core Moose. Also changed ->equals and ->is_a_type_of to be consistent. - Added test case for above - The test suite now uses Test::Fatal instead of Test::Exception (Karen Etheridge). 0.24 2010-11-16 - Added some performance enhancing caching code (phaeton) 0.23 2010-07-01 - Changes to the return value of ->validate that hopefully is both backwardly compatible as well as more detailed. Now if you have a deeply recursive of repeated type constraints inside other type constraints you will get a drill down report to show the actual type constraint that failed 0.22 2010-06-01 - Added tests to demonstrate type constraint equality problem introduced in Moose 1.05 0.21 2010-03-26 - Removed unneed module from test - additional contributed documentation fixes 0.20 2010-02-04 - Add a new Map type. (Ricardo SIGNES) - Properly handle Optional[] types within Tuples and Dicts. (Florian Ragwitz) 0.19 2009-11-06 - Require Devel::PartialDump 0.10 and change tests to expect the correct format of error. 0.18 2009-08-17 - Changed the Makefile.PL to reduce dependencies not needed by users that are not authors. Bumped the revision and released to clear an error with cpan permissions. 0.17 2009-08-12 - No new functionality. - Changed the way we specify dependencies in the Makefile.PL to reduce the depth of the dependency chain in cases where we don't need to be running the author quality tests. - Some documentation tweaks. 0.16 2009-05-28 - Fix failing tests and test warnings on MooseX::Types 0.11. 0.15 2009-05-27 - Change copy on license and added contributors section 0.14 2009-05-01 - Use a builder instead of wrapping new to set the default structured coercion (rafl). - Make overflow (slurpy) type constraints introspectable and the name of constraints using them reasonable (rafl). 0.13 2009-04-25 - Explicitly don't inline yet another constructor to avoid warnings (autarch). 0.12 2009-04-21 - Explicitly don't inline the constructor to avoid warnings (rafl). - Pathological test cases for API methods equals, is_a_type_of and is_subtype_of (rafl). - significant improvements to API methods is_a_type_of, is_subtype_of and equals (nothingmuch). 0.11 2009-04-06 - Fixed braindead bug in the way I override ->validate, which caused valiate to never correctly pass a constraint. 0.10 2009-04-02 - Minor documentation grammar fixes and one major example error fixed - Much improved error reporting. Now we return the 'internal' error that kicked a validation failure. It's still best to use this for debugging rather than for actual user error messages, since I think we are rapidly approaching a need for Moose constraints needing more in the error and message reporting. - Documentation for the above. 0.09 2009-03-07 - I guess we don't support the "subtype MyType, [TypeConstraint]" syntax anymore. Changed the recursion test to reflect that, which should fix my 100% fail rate :) 0.08 2009-03-06 - New Feature: slurpy method for when you want a structured type constraint that allows trailing arguments of indeterminate length. Please see the documentation and the '11-overflow.t' test for more. - Documentation for above as well as a bunch of POD cleanups, spell checks and improvements to formatting. - Stevan Little submitted a sweet update to the '10-recursion.t' test that blows my mind. Will probably form the core of a to be done set of cookbook style PODs. Worth looking at. - First step at improving the error message you get when validation fails. A full error stacktrace is not in this release, but you now at least get to see part of the offending value. 0.07 2008-12-09 - Fixed typo in previous changelog - documentation improvements and updates - increased version requirement for MooseX::Types so that we can take advantage of the recursion support added. - added test for recursion. 0.06 2008-12-06 - Added a 'helper' type constraint called Optional. See docs for more. - added lots of tests to cover the API better, coverage and fixes for the ->parameterize method in particular have been clarified. - changes so that the type contraints are more forgiving when null values appear in method calls. - used ->make_immutable which should speed up the constraints. - removed some unnecessary calls to use Moose when I wasn't using Moose. - lots of little code cleanup work and more internal documentation. - This version requires a newer Moose than previous versions. The Makefile.PL has been updated to reflect this. This is a required update. 0.05 2008-11-08 - Fixed some wackiness in the documentation. 0.04 2008-11-07 - Bumped minimum required versions of Moose and MooseX-Types to solve problem with overloading and type constraint names (issue resolved in Moose code.) - Changed the way the required Perl version string is used to increase compatibility and lowered minimum required Perl 0.03 2008-10-29 - Fixed incorrect Perl version string (rafl) - hide the meta classes from pause. This should clarify which POD is the right one to read and also I want to discourage people from subclassing that stuff since it will probably change - various documentation cleanup - new test 'example.t' with runable versions of the code in the example POD section. 0.02 2008-10-28 - cleared up some typos in the test suite - Fixed some POD formatting issues, mostly some dumb tabs I ended up with when I switched editors. Added a bit more documentation 0.01 2008-10-27 - Completed basic requirements, documentation and tests. MooseX-Types-Structured-0.30/CONTRIBUTING000644 000767 000024 00000005407 12254674163 020240 0ustar00etherstaff000000 000000 CONTRIBUTING Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with Dist::Zilla. This means than many of the usual files you might expect are not in the repository, but are generated at release time (e.g. Makefile.PL). However, you can run tests directly using the 'prove' tool: $ prove -l $ prove -lv t/some_test_file.t $ prove -lvr t/ In most cases, 'prove' is entirely sufficent for you to test any patches you have. You may need to satisfy some dependencies. The easiest way to satisfy dependencies is to install the last release -- this is available at https://metacpan.org/release/MooseX-Types-Structured. If you use cpanminus, you can do it without downloading the tarball first: $ cpanm --reinstall --installdeps --with-recommends MooseX::Types::Structured Dist::Zilla is a very powerful authoring tool, but requires a number of author-specific plugins. If you would like to use it for contributing, install it from CPAN, then run one of the following commands, depending on your CPAN client: $ cpan `dzil authordeps --missing` $ dzil authordeps --missing | cpanm You should then also install any additional requirements not needed by the dzil build but may be needed by tests or other development: # cpan `dzil listdeps --author --missing` $ dzil listdeps --author --missing | cpanm You can also do this via cpanm directly: $ cpanm --reinstall --installdeps --with-develop --with-recommends MooseX::Types::Structured Once installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil test --release $ dzil xtest $ dzil listdeps --json $ dzil build --notgz You can learn more about Dist::Zilla at http://dzil.org/. The code for this distribution is hosted at GitHub. The main repository is: https://github.com/moose/MooseX-Types-Structured. You can submit code changes by forking the repository, pushing your code changes to your clone, and then submitting a pull request. Detailed instructions for doing that is available here: https://help.github.com/ https://help.github.com/articles/creating-a-pull-request If you have found a bug, but do not have an accompanying patch to fix it, you can submit an issue report here: https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types-Structured or via bug-MooseX-Types-Structured@rt.cpan.org. There is also a mailing list available for users of this distribution, at http://lists.perl.org/list/moose.html. There is also an irc channel available for users of this distribution, at irc://irc.perl.org/#moose. This file was generated via Dist::Zilla::Plugin::GenerateFile::ShareDir 0.003 from a template file originating in Dist-Zilla-PluginBundle-Author-ETHER-0.043. MooseX-Types-Structured-0.30/dist.ini000644 000767 000024 00000001456 12254674163 020052 0ustar00etherstaff000000 000000 name = MooseX-Types-Structured author = John Napiorkowski author = Florian Ragwitz author = יובל קוג'מן (Yuval Kogman) author = Tomas (t0m) Doran author = Robert Sedlacek license = Perl_5 copyright_holder = John Napiorkowski copyright_year = 2008 [SurgicalPodWeaver] [@Author::ETHER] Authority.authority = cpan:JJNAPIORK server = github Test::Version.has_version = 0 ; skips modules with no $VERSION -remove = PodWeaver [Prereqs] Moose = 1.08 [Prereqs / TestRequires] Test::More = 0.94 ; authordep Pod::Weaver 4 ; authordep Pod::Weaver::Section::Contributors [ContributorsFromGit] [MetaResources] x_IRC = irc://irc.perl.org/#moose x_MailingList = http://lists.perl.org/list/moose.html MooseX-Types-Structured-0.30/INSTALL000644 000767 000024 00000002024 12254674163 017427 0ustar00etherstaff000000 000000 This is the Perl distribution MooseX-Types-Structured. Installing MooseX-Types-Structured is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm MooseX::Types::Structured 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 MooseX::Types::Structured ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan MooseX::Types::Structured ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Build.PL % ./Build && ./Build test Then install it: % ./Build install If you are installing into a system-wide directory, you may need to run: % sudo ./Build install ## Documentation MooseX-Types-Structured documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc MooseX::Types::Structured MooseX-Types-Structured-0.30/lib/000755 000767 000024 00000000000 12254674163 017146 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/LICENSE000644 000767 000024 00000043672 12254674163 017421 0ustar00etherstaff000000 000000 This software is copyright (c) 2008 by John Napiorkowski. 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) 2008 by John Napiorkowski. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2008 by John Napiorkowski. 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 MooseX-Types-Structured-0.30/Makefile.PL000644 000767 000024 00000010054 12254674163 020352 0ustar00etherstaff000000 000000 # This Makefile.PL for MooseX-Types-Structured was generated by # Dist::Zilla::Plugin::MakeMaker::Fallback 0.005. # Don't edit it but the dist.ini used to construct it. use strict; use warnings; BEGIN { my %configure_requires = ( 'Module::Build::Tiny' => '0.030', 'ExtUtils::MakeMaker' => '6.30', ); my @missing = grep { ! eval "require $_; $_->VERSION($configure_requires{$_}); 1" } keys %configure_requires; if (not @missing) { print "Congratulations, your toolchain understands 'configure_requires'!\n\n"; } else { $ENV{PERL_MM_FALLBACK_SILENCE_WARNING} or warn <<'EOW'; *** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *** If you're seeing this warning, your toolchain is really, really old* and you'll almost certainly have problems installing CPAN modules from this century. But never fear, dear user, for we have the technology to fix this! If you're using CPAN.pm to install things, then you can upgrade it using: cpan CPAN If you're using CPANPLUS to install things, then you can upgrade it using: cpanp CPANPLUS If you're using cpanminus, you shouldn't be seeing this message in the first place, so please file an issue on github. If you're installing manually, please retrain your fingers to run Build.PL when present instead. This public service announcement was brought to you by the Perl Toolchain Gang, the irc.perl.org #toolchain IRC channel, and the number 42. ---- * Alternatively, you are doing something overly clever, in which case you should consider setting the 'prefer_installer' config option in CPAN.pm, or 'prefer_makefile' in CPANPLUS, to 'mb" and '0' respectively. You can also silence this warning for future installations by setting the PERL_MM_FALLBACK_SILENCE_WARNING environment variable. EOW sleep 10 if -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)); } } use 5.008; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Structured Type Constraints for Moose", "AUTHOR" => "John Napiorkowski , Florian Ragwitz , \x{5d9}\x{5d5}\x{5d1}\x{5dc} \x{5e7}\x{5d5}\x{5d2}'\x{5de}\x{5df} (Yuval Kogman) , Tomas (t0m) Doran , Robert Sedlacek ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30", "Module::Build::Tiny" => "0.030" }, "DISTNAME" => "MooseX-Types-Structured", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "MooseX::Types::Structured", "PREREQ_PM" => { "Devel::PartialDump" => "0.13", "Moose" => "1.08", "Moose::Meta::TypeCoercion" => 0, "Moose::Meta::TypeConstraint" => 0, "Moose::Meta::TypeConstraint::Parameterizable" => 0, "Moose::Util::TypeConstraints" => "1.06", "MooseX::Types" => "0.22", "Scalar::Util" => 0, "Sub::Exporter" => "0.982", "overload" => 0 }, "TEST_REQUIRES" => { "Data::Dumper" => 0, "DateTime" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec::Functions" => 0, "List::Util" => 0, "MooseX::Types::DateTime" => 0, "MooseX::Types::Moose" => 0, "Test::Fatal" => 0, "Test::More" => "0.94", "strict" => 0, "warnings" => 0 }, "VERSION" => "0.30", "test" => { "TESTS" => "t/*.t t/regressions/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { my $tr = delete $WriteMakefileArgs{TEST_REQUIRES}; my $br = $WriteMakefileArgs{BUILD_REQUIRES}; for my $mod ( keys %$tr ) { if ( exists $br->{$mod} ) { $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod}; } else { $br->{$mod} = $tr->{$mod}; } } } unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); MooseX-Types-Structured-0.30/MANIFEST000644 000767 000024 00000002232 12254674163 017530 0ustar00etherstaff000000 000000 Build.PL CONTRIBUTING Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README README.md dist.ini lib/MooseX/Meta/TypeCoercion/Structured.pm lib/MooseX/Meta/TypeCoercion/Structured/Optional.pm lib/MooseX/Meta/TypeConstraint/Structured.pm lib/MooseX/Meta/TypeConstraint/Structured/Optional.pm lib/MooseX/Types/Structured.pm lib/MooseX/Types/Structured/MessageStack.pm lib/MooseX/Types/Structured/OverflowHandler.pm t/00-load.t t/00-report-prereqs.t t/01-basic.t t/02-tuple.t t/03-dict.t t/04-combined.t t/04-map.t t/05-advanced.t t/06-api.t t/07-coerce.t t/08-examples.t t/09-optional.t t/10-recursion.t t/11-overflow.t t/12-error.t t/13-deeper_error.t t/bug-incorrect-message.t t/bug-is-subtype.t t/bug-mixed-stringy.t t/bug-optional.t t/regressions/01-is_type_of.t weaver.ini xt/author/00-compile.t xt/author/pod-spell.t xt/release/changes_has_content.t xt/release/cpan-changes.t xt/release/distmeta.t xt/release/eol.t xt/release/kwalitee.t xt/release/minimum-version.t xt/release/mojibake.t xt/release/no-tabs.t xt/release/pod-coverage.t xt/release/pod-no404s.t xt/release/pod-syntax.t xt/release/portability.t xt/release/test-version.t xt/release/unused-vars.t MooseX-Types-Structured-0.30/META.json000644 000767 000024 00000061742 12254674163 020033 0ustar00etherstaff000000 000000 { "abstract" : "Structured Type Constraints for Moose", "author" : [ "John Napiorkowski ", "Florian Ragwitz ", "\u05d9\u05d5\u05d1\u05dc \u05e7\u05d5\u05d2'\u05de\u05df (Yuval Kogman) ", "Tomas (t0m) Doran ", "Robert Sedlacek " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.006, CPAN::Meta::Converter version 2.133380", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "MooseX-Types-Structured", "no_index" : { "directory" : [ "t", "xt", "examples" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30", "Module::Build::Tiny" : "0.030" } }, "develop" : { "recommends" : { "Dist::Zilla::PluginBundle::Author::ETHER" : "0.043" }, "requires" : { "Dist::Zilla" : "5.006", "Dist::Zilla::Plugin::ContributorsFromGit" : "0", "Dist::Zilla::Plugin::GitHub::Update" : "0", "Dist::Zilla::Plugin::GithubMeta" : "0", "Dist::Zilla::Plugin::MakeMaker::Fallback" : "0", "Dist::Zilla::Plugin::MetaResources" : "0", "Dist::Zilla::Plugin::ModuleBuildTiny" : "0.004", "Dist::Zilla::Plugin::Prereqs" : "0", "Dist::Zilla::Plugin::SurgicalPodWeaver" : "0", "Dist::Zilla::PluginBundle::Author::ETHER" : "0", "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Pod::Coverage::TrustPod" : "0", "Pod::Weaver::Section::Contributors" : "0", "Test::CPAN::Changes" : "0.19", "Test::CPAN::Meta" : "0", "Test::Kwalitee" : "1.12", "Test::More" : "0.94", "Test::NoTabs" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Devel::PartialDump" : "0.13", "Moose" : "1.08", "Moose::Meta::TypeCoercion" : "0", "Moose::Meta::TypeConstraint" : "0", "Moose::Meta::TypeConstraint::Parameterizable" : "0", "Moose::Util::TypeConstraints" : "1.06", "MooseX::Types" : "0.22", "Scalar::Util" : "0", "Sub::Exporter" : "0.982", "overload" : "0", "perl" : "5.008" } }, "test" : { "recommends" : { "CPAN::Meta" : "0", "CPAN::Meta::Requirements" : "0" }, "requires" : { "Data::Dumper" : "0", "DateTime" : "0", "ExtUtils::MakeMaker" : "0", "File::Spec::Functions" : "0", "List::Util" : "0", "MooseX::Types::DateTime" : "0", "MooseX::Types::Moose" : "0", "Test::Fatal" : "0", "Test::More" : "0.94", "strict" : "0", "warnings" : "0" } } }, "provides" : { "MooseX::Types::Structured" : { "file" : "lib/MooseX/Types/Structured.pm", "version" : "0.30" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-MooseX-Types-Structured@rt.cpan.org", "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types-Structured" }, "homepage" : "https://github.com/moose/MooseX-Types-Structured", "repository" : { "type" : "git", "url" : "https://github.com/moose/MooseX-Types-Structured.git", "web" : "https://github.com/moose/MooseX-Types-Structured" }, "x_IRC" : "irc://irc.perl.org/#moose", "x_MailingList" : "http://lists.perl.org/list/moose.html" }, "version" : "0.30", "x_Dist_Zilla" : { "perl" : { "version" : "5.019006" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::SurgicalPodWeaver", "config" : { "Dist::Zilla::Plugin::PodWeaver" : { "finder" : [ ":InstallModules", ":ExecFiles" ], "plugins" : [ { "class" : "Pod::Weaver::Plugin::EnsurePod5", "name" : "@CorePrep/EnsurePod5", "version" : "4.004" }, { "class" : "Pod::Weaver::Plugin::H1Nester", "name" : "@CorePrep/H1Nester", "version" : "4.004" }, { "class" : "Pod::Weaver::Plugin::SingleEncoding", "name" : "@Default/SingleEncoding", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Name", "name" : "@Default/Name", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Version", "name" : "@Default/Version", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@Default/prelude", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "SYNOPSIS", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "DESCRIPTION", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "OVERVIEW", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "ATTRIBUTES", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "METHODS", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "FUNCTIONS", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Leftovers", "name" : "@Default/Leftovers", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@Default/postlude", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Authors", "name" : "@Default/Authors", "version" : "4.004" }, { "class" : "Pod::Weaver::Section::Legal", "name" : "@Default/Legal", "version" : "4.004" }, { "class" : "Pod::Weaver::Plugin::Transformer", "name" : "-Transformer", "version" : "4.004" }, { "class" : "Pod::Weaver::Plugin::StopWords", "name" : "-StopWords", "version" : "1.008" }, { "class" : "Pod::Weaver::Section::Contributors", "name" : "Contributors", "version" : "0.007" } ] } }, "name" : "SurgicalPodWeaver", "version" : "0.0021" }, { "class" : "Dist::Zilla::Plugin::Git::NextVersion", "name" : "@Author::ETHER/Git::NextVersion", "version" : "2.019" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "config" : { "Dist::Zilla::Plugin::PromptIfStale" : { "check_all_plugins" : 0, "check_all_prereqs" : 0, "modules" : [ "Dist::Zilla::PluginBundle::Author::ETHER" ], "phase" : "build", "skip" : [] } }, "name" : "@Author::ETHER/build", "version" : "0.015" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "config" : { "Dist::Zilla::Plugin::PromptIfStale" : { "check_all_plugins" : "1", "check_all_prereqs" : "1", "modules" : [], "phase" : "release", "skip" : [] } }, "name" : "@Author::ETHER/release", "version" : "0.015" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Author::ETHER/ExecDir", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Author::ETHER/ShareDir", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::FileFinder::ByName", "name" : "@Author::ETHER/Examples", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Git::GatherDir", "name" : "@Author::ETHER/Git::GatherDir", "version" : "2.019" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Author::ETHER/MetaYAML", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@Author::ETHER/MetaJSON", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Author::ETHER/License", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Readme", "name" : "@Author::ETHER/Readme", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Author::ETHER/Manifest", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::GenerateFile::ShareDir", "config" : { "Dist::Zilla::Plugin::GenerateFile::ShareDir" : { "destination_filename" : "CONTRIBUTING", "dist" : "Dist-Zilla-PluginBundle-Author-ETHER", "encoding" : "UTF-8", "source_filename" : "CONTRIBUTING" } }, "name" : "@Author::ETHER/GenerateFile::ShareDir", "version" : "0.003" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "config" : { "Dist::Zilla::Plugin::Test::Compile" : { "filename" : "xt/author/00-compile.t", "module_finder" : [ ":InstallModules" ], "script_finder" : [ ":ExecFiles", "@Author::ETHER/Examples" ] } }, "name" : "@Author::ETHER/Test::Compile", "version" : "2.039" }, { "class" : "Dist::Zilla::Plugin::Test::NoTabs", "config" : { "Dist::Zilla::Plugin::Test::NoTabs" : { "module_finder" : [ ":InstallModules" ], "script_finder" : [ ":ExecFiles", "@Author::ETHER/Examples" ] } }, "name" : "@Author::ETHER/Test::NoTabs", "version" : "0.06" }, { "class" : "Dist::Zilla::Plugin::EOLTests", "name" : "@Author::ETHER/EOLTests", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::MetaTests", "name" : "@Author::ETHER/MetaTests", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Test::Version", "name" : "@Author::ETHER/Test::Version", "version" : "0.002004" }, { "class" : "Dist::Zilla::Plugin::Test::CPAN::Changes", "name" : "@Author::ETHER/Test::CPAN::Changes", "version" : "0.008" }, { "class" : "Dist::Zilla::Plugin::Test::ChangesHasContent", "name" : "@Author::ETHER/Test::ChangesHasContent", "version" : "0.006" }, { "class" : "Dist::Zilla::Plugin::Test::UnusedVars", "name" : "@Author::ETHER/Test::UnusedVars", "version" : "2.000005" }, { "class" : "Dist::Zilla::Plugin::Test::MinimumVersion", "name" : "@Author::ETHER/Test::MinimumVersion", "version" : "2.000005" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@Author::ETHER/PodSyntaxTests", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::PodCoverageTests", "name" : "@Author::ETHER/PodCoverageTests", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Test::PodSpelling", "name" : "@Author::ETHER/Test::PodSpelling", "version" : "2.006002" }, { "class" : "Dist::Zilla::Plugin::Test::Pod::No404s", "name" : "@Author::ETHER/Test::Pod::No404s", "version" : "1.001" }, { "class" : "Dist::Zilla::Plugin::Test::Kwalitee", "name" : "@Author::ETHER/Test::Kwalitee", "version" : "2.07" }, { "class" : "Dist::Zilla::Plugin::MojibakeTests", "name" : "@Author::ETHER/MojibakeTests", "version" : "0.5" }, { "class" : "Dist::Zilla::Plugin::Test::ReportPrereqs", "name" : "@Author::ETHER/Test::ReportPrereqs", "version" : "0.010" }, { "class" : "Dist::Zilla::Plugin::Test::Portability", "name" : "@Author::ETHER/Test::Portability", "version" : "2.000005" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Author::ETHER/PruneCruft", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Author::ETHER/ManifestSkip", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Authority", "name" : "@Author::ETHER/Authority", "version" : "1.006" }, { "class" : "Dist::Zilla::Plugin::Git::Describe", "name" : "@Author::ETHER/Git::Describe", "version" : "0.003" }, { "class" : "Dist::Zilla::Plugin::PkgVersion", "name" : "@Author::ETHER/PkgVersion", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@Author::ETHER/NextRelease", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "name" : "@Author::ETHER/ReadmeAnyFromPod", "version" : "0.133360" }, { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "@Author::ETHER/GithubMeta", "version" : "0.42" }, { "class" : "Dist::Zilla::Plugin::AutoMetaResources", "name" : "@Author::ETHER/AutoMetaResources", "version" : "1.20" }, { "class" : "Dist::Zilla::Plugin::MetaNoIndex", "name" : "@Author::ETHER/MetaNoIndex", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@Author::ETHER/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::MetaProvides::Package", "config" : { "Dist::Zilla::Plugin::MetaProvides::Package" : {}, "Dist::Zilla::Role::MetaProvider::Provider" : { "inherit_missing" : "1", "inherit_version" : "1", "meta_noindex" : "1" } }, "name" : "@Author::ETHER/MetaProvides::Package", "version" : "1.15000001" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@Author::ETHER/MetaConfig", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "@Author::ETHER/AutoPrereqs", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Prereqs::AuthorDeps", "name" : "@Author::ETHER/Prereqs::AuthorDeps", "version" : "0.002" }, { "class" : "Dist::Zilla::Plugin::MinimumPerl", "name" : "@Author::ETHER/MinimumPerl", "version" : "1.003" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "develop", "type" : "requires" } }, "name" : "@Author::ETHER/installer_requirements", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "develop", "type" : "recommends" } }, "name" : "@Author::ETHER/pluginbundle_version", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::RunExtraTests", "name" : "@Author::ETHER/RunExtraTests", "version" : "0.016" }, { "class" : "Dist::Zilla::Plugin::MakeMaker::Fallback", "name" : "@Author::ETHER/MakeMaker::Fallback", "version" : "0.005" }, { "class" : "Dist::Zilla::Plugin::ModuleBuildTiny", "name" : "@Author::ETHER/ModuleBuildTiny", "version" : "0.005" }, { "class" : "Dist::Zilla::Plugin::InstallGuide", "name" : "@Author::ETHER/InstallGuide", "version" : "1.200002" }, { "class" : "Dist::Zilla::Plugin::CheckSelfDependency", "name" : "@Author::ETHER/CheckSelfDependency", "version" : "0.006" }, { "class" : "Dist::Zilla::Plugin::Run::AfterBuild", "name" : "@Author::ETHER/Run::AfterBuild", "version" : "0.020" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "name" : "@Author::ETHER/initial check", "version" : "2.019" }, { "class" : "Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts", "name" : "@Author::ETHER/Git::CheckFor::MergeConflicts", "version" : "0.008" }, { "class" : "Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch", "name" : "@Author::ETHER/Git::CheckFor::CorrectBranch", "version" : "0.008" }, { "class" : "Dist::Zilla::Plugin::Git::Remote::Check", "name" : "@Author::ETHER/Git::Remote::Check", "version" : "0.1.2" }, { "class" : "Dist::Zilla::Plugin::CheckPrereqsIndexed", "name" : "@Author::ETHER/CheckPrereqsIndexed", "version" : "0.009" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@Author::ETHER/TestRelease", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "name" : "@Author::ETHER/after tests", "version" : "2.019" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@Author::ETHER/UploadToCPAN", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::CopyFilesFromRelease", "name" : "@Author::ETHER/CopyFilesFromRelease", "version" : "0.001" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "name" : "@Author::ETHER/Git::Commit", "version" : "2.019" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "name" : "@Author::ETHER/Git::Tag", "version" : "2.019" }, { "class" : "Dist::Zilla::Plugin::GitHub::Update", "name" : "@Author::ETHER/GitHub::Update", "version" : "0.36" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "name" : "@Author::ETHER/Git::Push", "version" : "2.019" }, { "class" : "Dist::Zilla::Plugin::InstallRelease", "name" : "@Author::ETHER/InstallRelease", "version" : "0.008" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Author::ETHER/ConfirmRelease", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "develop", "type" : "requires" } }, "name" : "@Author::ETHER/via_options", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "runtime", "type" : "requires" } }, "name" : "Prereqs", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "TestRequires", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::ContributorsFromGit", "name" : "ContributorsFromGit", "version" : "0.006" }, { "class" : "Dist::Zilla::Plugin::MetaResources", "name" : "MetaResources", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "5.006" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "5.006" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : "0" }, "version" : "5.006" } }, "x_authority" : "cpan:JJNAPIORK", "x_contributors" : [ "Ansgar Burchardt ", "Dave Rolsky ", "Jesse Luehrs ", "Karen Etheridge ", "Ricardo Signes ", "Robert 'phaylon' Sedlacek ", "Stevan Little ", "arcanez " ] } MooseX-Types-Structured-0.30/META.yml000644 000767 000024 00000037333 12254674163 017662 0ustar00etherstaff000000 000000 --- abstract: 'Structured Type Constraints for Moose' author: - 'John Napiorkowski ' - 'Florian Ragwitz ' - "יובל קוג'מן (Yuval Kogman) " - 'Tomas (t0m) Doran ' - 'Robert Sedlacek ' build_requires: Data::Dumper: 0 DateTime: 0 ExtUtils::MakeMaker: 0 File::Spec::Functions: 0 List::Util: 0 MooseX::Types::DateTime: 0 MooseX::Types::Moose: 0 Test::Fatal: 0 Test::More: 0.94 strict: 0 warnings: 0 configure_requires: ExtUtils::MakeMaker: 6.30 Module::Build::Tiny: 0.030 dynamic_config: 0 generated_by: 'Dist::Zilla version 5.006, CPAN::Meta::Converter version 2.133380' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: MooseX-Types-Structured no_index: directory: - t - xt - examples provides: MooseX::Types::Structured: file: lib/MooseX/Types/Structured.pm version: 0.30 requires: Devel::PartialDump: 0.13 Moose: 1.08 Moose::Meta::TypeCoercion: 0 Moose::Meta::TypeConstraint: 0 Moose::Meta::TypeConstraint::Parameterizable: 0 Moose::Util::TypeConstraints: 1.06 MooseX::Types: 0.22 Scalar::Util: 0 Sub::Exporter: 0.982 overload: 0 perl: 5.008 resources: IRC: irc://irc.perl.org/#moose MailingList: http://lists.perl.org/list/moose.html bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types-Structured homepage: https://github.com/moose/MooseX-Types-Structured repository: https://github.com/moose/MooseX-Types-Structured.git version: 0.30 x_Dist_Zilla: perl: version: 5.019006 plugins: - class: Dist::Zilla::Plugin::SurgicalPodWeaver config: Dist::Zilla::Plugin::PodWeaver: finder: - ':InstallModules' - ':ExecFiles' plugins: - class: Pod::Weaver::Plugin::EnsurePod5 name: '@CorePrep/EnsurePod5' version: 4.004 - class: Pod::Weaver::Plugin::H1Nester name: '@CorePrep/H1Nester' version: 4.004 - class: Pod::Weaver::Plugin::SingleEncoding name: '@Default/SingleEncoding' version: 4.004 - class: Pod::Weaver::Section::Name name: '@Default/Name' version: 4.004 - class: Pod::Weaver::Section::Version name: '@Default/Version' version: 4.004 - class: Pod::Weaver::Section::Region name: '@Default/prelude' version: 4.004 - class: Pod::Weaver::Section::Generic name: SYNOPSIS version: 4.004 - class: Pod::Weaver::Section::Generic name: DESCRIPTION version: 4.004 - class: Pod::Weaver::Section::Generic name: OVERVIEW version: 4.004 - class: Pod::Weaver::Section::Collect name: ATTRIBUTES version: 4.004 - class: Pod::Weaver::Section::Collect name: METHODS version: 4.004 - class: Pod::Weaver::Section::Collect name: FUNCTIONS version: 4.004 - class: Pod::Weaver::Section::Leftovers name: '@Default/Leftovers' version: 4.004 - class: Pod::Weaver::Section::Region name: '@Default/postlude' version: 4.004 - class: Pod::Weaver::Section::Authors name: '@Default/Authors' version: 4.004 - class: Pod::Weaver::Section::Legal name: '@Default/Legal' version: 4.004 - class: Pod::Weaver::Plugin::Transformer name: '-Transformer' version: 4.004 - class: Pod::Weaver::Plugin::StopWords name: '-StopWords' version: 1.008 - class: Pod::Weaver::Section::Contributors name: Contributors version: 0.007 name: SurgicalPodWeaver version: 0.0021 - class: Dist::Zilla::Plugin::Git::NextVersion name: '@Author::ETHER/Git::NextVersion' version: 2.019 - class: Dist::Zilla::Plugin::PromptIfStale config: Dist::Zilla::Plugin::PromptIfStale: check_all_plugins: 0 check_all_prereqs: 0 modules: - Dist::Zilla::PluginBundle::Author::ETHER phase: build skip: [] name: '@Author::ETHER/build' version: 0.015 - class: Dist::Zilla::Plugin::PromptIfStale config: Dist::Zilla::Plugin::PromptIfStale: check_all_plugins: 1 check_all_prereqs: 1 modules: [] phase: release skip: [] name: '@Author::ETHER/release' version: 0.015 - class: Dist::Zilla::Plugin::ExecDir name: '@Author::ETHER/ExecDir' version: 5.006 - class: Dist::Zilla::Plugin::ShareDir name: '@Author::ETHER/ShareDir' version: 5.006 - class: Dist::Zilla::Plugin::FileFinder::ByName name: '@Author::ETHER/Examples' version: 5.006 - class: Dist::Zilla::Plugin::Git::GatherDir name: '@Author::ETHER/Git::GatherDir' version: 2.019 - class: Dist::Zilla::Plugin::MetaYAML name: '@Author::ETHER/MetaYAML' version: 5.006 - class: Dist::Zilla::Plugin::MetaJSON name: '@Author::ETHER/MetaJSON' version: 5.006 - class: Dist::Zilla::Plugin::License name: '@Author::ETHER/License' version: 5.006 - class: Dist::Zilla::Plugin::Readme name: '@Author::ETHER/Readme' version: 5.006 - class: Dist::Zilla::Plugin::Manifest name: '@Author::ETHER/Manifest' version: 5.006 - class: Dist::Zilla::Plugin::GenerateFile::ShareDir config: Dist::Zilla::Plugin::GenerateFile::ShareDir: destination_filename: CONTRIBUTING dist: Dist-Zilla-PluginBundle-Author-ETHER encoding: UTF-8 source_filename: CONTRIBUTING name: '@Author::ETHER/GenerateFile::ShareDir' version: 0.003 - class: Dist::Zilla::Plugin::Test::Compile config: Dist::Zilla::Plugin::Test::Compile: filename: xt/author/00-compile.t module_finder: - ':InstallModules' script_finder: - ':ExecFiles' - '@Author::ETHER/Examples' name: '@Author::ETHER/Test::Compile' version: 2.039 - class: Dist::Zilla::Plugin::Test::NoTabs config: Dist::Zilla::Plugin::Test::NoTabs: module_finder: - ':InstallModules' script_finder: - ':ExecFiles' - '@Author::ETHER/Examples' name: '@Author::ETHER/Test::NoTabs' version: 0.06 - class: Dist::Zilla::Plugin::EOLTests name: '@Author::ETHER/EOLTests' version: 0.02 - class: Dist::Zilla::Plugin::MetaTests name: '@Author::ETHER/MetaTests' version: 5.006 - class: Dist::Zilla::Plugin::Test::Version name: '@Author::ETHER/Test::Version' version: 0.002004 - class: Dist::Zilla::Plugin::Test::CPAN::Changes name: '@Author::ETHER/Test::CPAN::Changes' version: 0.008 - class: Dist::Zilla::Plugin::Test::ChangesHasContent name: '@Author::ETHER/Test::ChangesHasContent' version: 0.006 - class: Dist::Zilla::Plugin::Test::UnusedVars name: '@Author::ETHER/Test::UnusedVars' version: 2.000005 - class: Dist::Zilla::Plugin::Test::MinimumVersion name: '@Author::ETHER/Test::MinimumVersion' version: 2.000005 - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@Author::ETHER/PodSyntaxTests' version: 5.006 - class: Dist::Zilla::Plugin::PodCoverageTests name: '@Author::ETHER/PodCoverageTests' version: 5.006 - class: Dist::Zilla::Plugin::Test::PodSpelling name: '@Author::ETHER/Test::PodSpelling' version: 2.006002 - class: Dist::Zilla::Plugin::Test::Pod::No404s name: '@Author::ETHER/Test::Pod::No404s' version: 1.001 - class: Dist::Zilla::Plugin::Test::Kwalitee name: '@Author::ETHER/Test::Kwalitee' version: 2.07 - class: Dist::Zilla::Plugin::MojibakeTests name: '@Author::ETHER/MojibakeTests' version: 0.5 - class: Dist::Zilla::Plugin::Test::ReportPrereqs name: '@Author::ETHER/Test::ReportPrereqs' version: 0.010 - class: Dist::Zilla::Plugin::Test::Portability name: '@Author::ETHER/Test::Portability' version: 2.000005 - class: Dist::Zilla::Plugin::PruneCruft name: '@Author::ETHER/PruneCruft' version: 5.006 - class: Dist::Zilla::Plugin::ManifestSkip name: '@Author::ETHER/ManifestSkip' version: 5.006 - class: Dist::Zilla::Plugin::Authority name: '@Author::ETHER/Authority' version: 1.006 - class: Dist::Zilla::Plugin::Git::Describe name: '@Author::ETHER/Git::Describe' version: 0.003 - class: Dist::Zilla::Plugin::PkgVersion name: '@Author::ETHER/PkgVersion' version: 5.006 - class: Dist::Zilla::Plugin::NextRelease name: '@Author::ETHER/NextRelease' version: 5.006 - class: Dist::Zilla::Plugin::ReadmeAnyFromPod name: '@Author::ETHER/ReadmeAnyFromPod' version: 0.133360 - class: Dist::Zilla::Plugin::GithubMeta name: '@Author::ETHER/GithubMeta' version: 0.42 - class: Dist::Zilla::Plugin::AutoMetaResources name: '@Author::ETHER/AutoMetaResources' version: 1.20 - class: Dist::Zilla::Plugin::MetaNoIndex name: '@Author::ETHER/MetaNoIndex' version: 5.006 - class: Dist::Zilla::Plugin::FinderCode name: '@Author::ETHER/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: 5.006 - class: Dist::Zilla::Plugin::MetaProvides::Package config: Dist::Zilla::Plugin::MetaProvides::Package: {} Dist::Zilla::Role::MetaProvider::Provider: inherit_missing: 1 inherit_version: 1 meta_noindex: 1 name: '@Author::ETHER/MetaProvides::Package' version: 1.15000001 - class: Dist::Zilla::Plugin::MetaConfig name: '@Author::ETHER/MetaConfig' version: 5.006 - class: Dist::Zilla::Plugin::AutoPrereqs name: '@Author::ETHER/AutoPrereqs' version: 5.006 - class: Dist::Zilla::Plugin::Prereqs::AuthorDeps name: '@Author::ETHER/Prereqs::AuthorDeps' version: 0.002 - class: Dist::Zilla::Plugin::MinimumPerl name: '@Author::ETHER/MinimumPerl' version: 1.003 - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: develop type: requires name: '@Author::ETHER/installer_requirements' version: 5.006 - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: develop type: recommends name: '@Author::ETHER/pluginbundle_version' version: 5.006 - class: Dist::Zilla::Plugin::RunExtraTests name: '@Author::ETHER/RunExtraTests' version: 0.016 - class: Dist::Zilla::Plugin::MakeMaker::Fallback name: '@Author::ETHER/MakeMaker::Fallback' version: 0.005 - class: Dist::Zilla::Plugin::ModuleBuildTiny name: '@Author::ETHER/ModuleBuildTiny' version: 0.005 - class: Dist::Zilla::Plugin::InstallGuide name: '@Author::ETHER/InstallGuide' version: 1.200002 - class: Dist::Zilla::Plugin::CheckSelfDependency name: '@Author::ETHER/CheckSelfDependency' version: 0.006 - class: Dist::Zilla::Plugin::Run::AfterBuild name: '@Author::ETHER/Run::AfterBuild' version: 0.020 - class: Dist::Zilla::Plugin::Git::Check name: '@Author::ETHER/initial check' version: 2.019 - class: Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts name: '@Author::ETHER/Git::CheckFor::MergeConflicts' version: 0.008 - class: Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch name: '@Author::ETHER/Git::CheckFor::CorrectBranch' version: 0.008 - class: Dist::Zilla::Plugin::Git::Remote::Check name: '@Author::ETHER/Git::Remote::Check' version: 0.1.2 - class: Dist::Zilla::Plugin::CheckPrereqsIndexed name: '@Author::ETHER/CheckPrereqsIndexed' version: 0.009 - class: Dist::Zilla::Plugin::TestRelease name: '@Author::ETHER/TestRelease' version: 5.006 - class: Dist::Zilla::Plugin::Git::Check name: '@Author::ETHER/after tests' version: 2.019 - class: Dist::Zilla::Plugin::UploadToCPAN name: '@Author::ETHER/UploadToCPAN' version: 5.006 - class: Dist::Zilla::Plugin::CopyFilesFromRelease name: '@Author::ETHER/CopyFilesFromRelease' version: 0.001 - class: Dist::Zilla::Plugin::Git::Commit name: '@Author::ETHER/Git::Commit' version: 2.019 - class: Dist::Zilla::Plugin::Git::Tag name: '@Author::ETHER/Git::Tag' version: 2.019 - class: Dist::Zilla::Plugin::GitHub::Update name: '@Author::ETHER/GitHub::Update' version: 0.36 - class: Dist::Zilla::Plugin::Git::Push name: '@Author::ETHER/Git::Push' version: 2.019 - class: Dist::Zilla::Plugin::InstallRelease name: '@Author::ETHER/InstallRelease' version: 0.008 - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Author::ETHER/ConfirmRelease' version: 5.006 - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: develop type: requires name: '@Author::ETHER/via_options' version: 5.006 - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: runtime type: requires name: Prereqs version: 5.006 - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: TestRequires version: 5.006 - class: Dist::Zilla::Plugin::ContributorsFromGit name: ContributorsFromGit version: 0.006 - class: Dist::Zilla::Plugin::MetaResources name: MetaResources version: 5.006 - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: 5.006 - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: 5.006 - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: 5.006 - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: 5.006 - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: 5.006 - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: 5.006 zilla: class: Dist::Zilla::Dist::Builder config: is_trial: 0 version: 5.006 x_authority: cpan:JJNAPIORK x_contributors: - 'Ansgar Burchardt ' - 'Dave Rolsky ' - 'Jesse Luehrs ' - 'Karen Etheridge ' - 'Ricardo Signes ' - "Robert 'phaylon' Sedlacek " - 'Stevan Little ' - 'arcanez ' MooseX-Types-Structured-0.30/README000644 000767 000024 00000000476 12254674163 017267 0ustar00etherstaff000000 000000 This archive contains the distribution MooseX-Types-Structured, version 0.30: Structured Type Constraints for Moose This software is copyright (c) 2008 by John Napiorkowski. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. MooseX-Types-Structured-0.30/README.md000644 000767 000024 00000053350 12254674163 017665 0ustar00etherstaff000000 000000 # NAME MooseX::Types::Structured - Structured Type Constraints for Moose # VERSION version 0.30 # SYNOPSIS The following is example usage for this module. package Person; use Moose; use MooseX::Types::Moose qw(Str Int HashRef); use MooseX::Types::Structured qw(Dict Tuple Optional); ## A name has a first and last part, but middle names are not required has name => ( isa=>Dict[ first => Str, last => Str, middle => Optional[Str], ], ); ## description is a string field followed by a HashRef of tagged data. has description => ( isa=>Tuple[ Str, Optional[HashRef], ], ); ## Remainder of your class attributes and methods Then you can instantiate this class with something like: my $john = Person->new( name => { first => 'John', middle => 'James' last => 'Napiorkowski', }, description => [ 'A cool guy who loves Perl and Moose.', { married_to => 'Vanessa Li', born_in => 'USA', }; ] ); Or with: my $vanessa = Person->new( name => { first => 'Vanessa', last => 'Li' }, description => ['A great student!'], ); But all of these would cause a constraint error for the `name` attribute: ## Value for 'name' not a HashRef Person->new( name => 'John' ); ## Value for 'name' has incorrect hash key and missing required keys Person->new( name => { first_name => 'John' }); ## Also incorrect keys Person->new( name => { first_name => 'John', age => 39, }); ## key 'middle' incorrect type, should be a Str not a ArrayRef Person->new( name => { first => 'Vanessa', middle => [1,2], last => 'Li', }); And these would cause a constraint error for the `description` attribute: ## Should be an ArrayRef Person->new( description => 'Hello I am a String' ); ## First element must be a string not a HashRef. Person->new (description => [{ tag1 => 'value1', tag2 => 'value2' }]); Please see the test cases for more examples. # DESCRIPTION A structured type constraint is a standard container [Moose](https://metacpan.org/pod/Moose) type constraint, such as an `ArrayRef` or `HashRef`, which has been enhanced to allow you to explicitly name all the allowed type constraints inside the structure. The generalized form is: TypeConstraint[@TypeParameters or %TypeParameters] Where `TypeParameters` is an array reference or hash references of [Moose::Meta::TypeConstraint](https://metacpan.org/pod/Moose::Meta::TypeConstraint) objects. This type library enables structured type constraints. It is built on top of the [MooseX::Types](https://metacpan.org/pod/MooseX::Types) library system, so you should review the documentation for that if you are not familiar with it. ## Comparing Parameterized types to Structured types Parameterized constraints are built into core Moose and you are probably already familiar with the type constraints `HashRef` and `ArrayRef`. Structured types have similar functionality, so their syntax is likewise similar. For example, you could define a parameterized constraint like: subtype ArrayOfInts, as ArrayRef[Int]; which would constrain a value to something like \[1,2,3,...\] and so on. On the other hand, a structured type constraint explicitly names all it's allowed 'internal' type parameter constraints. For the example: subtype StringFollowedByInt, as Tuple[Str,Int]; would constrain its value to things like `['hello', 111]` but `['hello', 'world']` would fail, as well as `['hello', 111, 'world']` and so on. Here's another example: package MyApp::Types; use MooseX::Types -declare [qw(StringIntOptionalHashRef)]; use MooseX::Types::Moose qw(Str Int); use MooseX::Types::Structured qw(Tuple Optional); subtype StringIntOptionalHashRef, as Tuple[ Str, Int, Optional[HashRef] ]; This defines a type constraint that validates values like: ['Hello', 100, {key1 => 'value1', key2 => 'value2'}]; ['World', 200]; Notice that the last type constraint in the structure is optional. This is enabled via the helper `Optional` type constraint, which is a variation of the core Moose type constraint `Maybe`. The main difference is that `Optional` type constraints are required to validate if they exist, while `Maybe` permits undefined values. So the following example would not validate: StringIntOptionalHashRef->validate(['Hello Undefined', 1000, undef]); Please note the subtle difference between undefined and null. If you wish to allow both null and undefined, you should use the core Moose `Maybe` type constraint instead: package MyApp::Types; use MooseX::Types -declare [qw(StringIntMaybeHashRef)]; use MooseX::Types::Moose qw(Str Int Maybe); use MooseX::Types::Structured qw(Tuple); subtype StringIntMaybeHashRef, as Tuple[ Str, Int, Maybe[HashRef] ]; This would validate the following: ['Hello', 100, {key1 => 'value1', key2 => 'value2'}]; ['World', 200, undef]; ['World', 200]; Structured constraints are not limited to arrays. You can define a structure against a `HashRef` with the `Dict` type constraint as in this example: subtype FirstNameLastName, as Dict[ firstname => Str, lastname => Str, ]; This would constrain a `HashRef` that validates something like: {firstname => 'Christopher', lastname => 'Parsons'}; but all the following would fail validation: ## Incorrect keys {first => 'Christopher', last => 'Parsons'}; ## Too many keys {firstname => 'Christopher', lastname => 'Parsons', middlename => 'Allen'}; ## Not a HashRef ['Christopher', 'Parsons']; These structures can be as simple or elaborate as you wish. You can even combine various structured, parameterized and simple constraints all together: subtype Crazy, as Tuple[ Int, Dict[name=>Str, age=>Int], ArrayRef[Int] ]; Which would match: [1, {name=>'John', age=>25},[10,11,12]]; Please notice how the type parameters can be visually arranged to your liking and to improve the clarity of your meaning. You don't need to run then altogether onto a single line. Additionally, since the `Dict` type constraint defines a hash constraint, the key order is not meaningful. For example: subtype AnyKeyOrder, as Dict[ key1=>Int, key2=>Str, key3=>Int, ]; Would validate both: {key1 => 1, key2 => "Hi!", key3 => 2}; {key2 => "Hi!", key1 => 100, key3 => 300}; As you would expect, since underneath it's just a plain old Perl hash at work. ## Alternatives You should exercise some care as to whether or not your complex structured constraints would be better off contained by a real object as in the following example: package MyApp::MyStruct; use Moose; ## lazy way to make a bunch of attributes has $_ for qw(full_name age_in_years); package MyApp::MyClass; use Moose; has person => (isa => 'MyApp::MyStruct'); my $instance = MyApp::MyClass->new( person=>MyApp::MyStruct->new( full_name => 'John', age_in_years => 39, ), ); This method may take some additional time to set up but will give you more flexibility. However, structured constraints are highly compatible with this method, granting some interesting possibilities for coercion. Try: package MyApp::MyClass; use Moose; use MyApp::MyStruct; ## It's recommended your type declarations live in a separate class in order ## to promote reusability and clarity. Inlined here for brevity. use MooseX::Types::DateTime qw(DateTime); use MooseX::Types -declare [qw(MyStruct)]; use MooseX::Types::Moose qw(Str Int); use MooseX::Types::Structured qw(Dict); ## Use class_type to create an ISA type constraint if your object doesn't ## inherit from Moose::Object. class_type 'MyApp::MyStruct'; ## Just a shorter version really. subtype MyStruct, as 'MyApp::MyStruct'; ## Add the coercions. coerce MyStruct, from Dict[ full_name=>Str, age_in_years=>Int ], via { MyApp::MyStruct->new(%$_); }, from Dict[ lastname=>Str, firstname=>Str, dob=>DateTime ], via { my $name = $_->{firstname} .' '. $_->{lastname}; my $age = DateTime->now - $_->{dob}; MyApp::MyStruct->new( full_name=>$name, age_in_years=>$age->years, ); }; has person => (isa=>MyStruct); This would allow you to instantiate with something like: my $obj = MyApp::MyClass->new( person => { full_name=>'John Napiorkowski', age_in_years=>39, }); Or even: my $obj = MyApp::MyClass->new( person => { lastname=>'John', firstname=>'Napiorkowski', dob=>DateTime->new(year=>1969), }); If you are not familiar with how coercions work, check out the [Moose](https://metacpan.org/pod/Moose) cookbook entry [Moose::Cookbook::Recipe5](https://metacpan.org/pod/Moose::Cookbook::Recipe5) for an explanation. The section ["Coercions"](#coercions) has additional examples and discussion. ## Subtyping a Structured type constraint You need to exercise some care when you try to subtype a structured type as in this example: subtype Person, as Dict[name => Str]; subtype FriendlyPerson, as Person[ name => Str, total_friends => Int, ]; This will actually work BUT you have to take care that the subtype has a structure that does not contradict the structure of it's parent. For now the above works, but I will clarify the syntax for this at a future point, so it's recommended to avoid (should not really be needed so much anyway). For now this is supported in an EXPERIMENTAL way. Your thoughts, test cases and patches are welcomed for discussion. If you find a good use for this, please let me know. ## Coercions Coercions currently work for 'one level' deep. That is you can do: subtype Person, as Dict[ name => Str, age => Int ]; subtype Fullname, as Dict[ first => Str, last => Str ]; coerce Person, ## Coerce an object of a particular class from BlessedPersonObject, via { +{ name=>$_->name, age=>$_->age, }; }, ## Coerce from [$name, $age] from ArrayRef, via { +{ name=>$_->[0], age=>$_->[1], }, }, ## Coerce from {fullname=>{first=>...,last=>...}, dob=>$DateTimeObject} from Dict[fullname=>Fullname, dob=>DateTime], via { my $age = $_->dob - DateTime->now; my $firstn = $_->{fullname}->{first}; my $lastn = $_->{fullname}->{last} +{ name => $_->{fullname}->{first} .' '. , age =>$age->years } }; And that should just work as expected. However, if there are any 'inner' coercions, such as a coercion on `Fullname` or on `DateTime`, that coercion won't currently get activated. Please see the test `07-coerce.t` for a more detailed example. Discussion on extending coercions to support this welcome on the Moose development channel or mailing list. ## Recursion Newer versions of [MooseX::Types](https://metacpan.org/pod/MooseX::Types) support recursive type constraints. That is you can include a type constraint as a contained type constraint of itself. For example: subtype Person, as Dict[ name=>Str, friends=>Optional[ ArrayRef[Person] ], ]; This would declare a `Person` subtype that contains a name and an optional `ArrayRef` of `Person`s who are friends as in: { name => 'Mike', friends => [ { name => 'John' }, { name => 'Vincent' }, { name => 'Tracey', friends => [ { name => 'Stephenie' }, { name => 'Ilya' }, ], }, ], }; Please take care to make sure the recursion node is either `Optional`, or declare a union with an non-recursive option such as: subtype Value as Tuple[ Str, Str|Tuple, ]; Which validates: [ 'Hello', [ 'World', [ 'Is', [ 'Getting', 'Old', ], ], ], ]; Otherwise you will define a subtype that is impossible to validate since it is infinitely recursive. For more information about defining recursive types, please see the documentation in [MooseX::Types](https://metacpan.org/pod/MooseX::Types) and the test cases. # TYPE CONSTRAINTS This type library defines the following constraints. ## Tuple\[@constraints\] This defines an ArrayRef based constraint which allows you to validate a specific list of contained constraints. For example: Tuple[Int,Str]; ## Validates [1,'hello'] Tuple[Str|Object, Int]; ## Validates ['hello', 1] or [$object, 2] The Values of @constraints should ideally be [MooseX::Types](https://metacpan.org/pod/MooseX::Types) declared type constraints. We do support 'old style' [Moose](https://metacpan.org/pod/Moose) string based constraints to a limited degree but these string type constraints are considered deprecated. There will be limited support for bugs resulting from mixing string and [MooseX::Types](https://metacpan.org/pod/MooseX::Types) in your structures. If you encounter such a bug and really need it fixed, we will required a detailed test case at the minimum. ## Dict\[%constraints\] This defines a HashRef based constraint which allowed you to validate a specific hashref. For example: Dict[name=>Str, age=>Int]; ## Validates {name=>'John', age=>39} The keys in `%constraints` follow the same rules as `@constraints` in the above section. ## Map\[ $key\_constraint, $value\_constraint \] This defines a `HashRef`\-based constraint in which both the keys and values are required to meet certain constraints. For example, to map hostnames to IP addresses, you might say: Map[ HostName, IPAddress ] The type constraint would only be met if every key was a valid `HostName` and every value was a valid `IPAddress`. ## Optional\[$constraint\] This is primarily a helper constraint for `Dict` and `Tuple` type constraints. What this allows is for you to assert that a given type constraint is allowed to be null (but NOT undefined). If the value is null, then the type constraint passes but if the value is defined it must validate against the type constraint. This makes it easy to make a Dict where one or more of the keys doesn't have to exist or a tuple where some of the values are not required. For example: subtype Name() => as Dict[ first=>Str, last=>Str, middle=>Optional[Str], ]; ...creates a constraint that validates against a hashref with the keys 'first' and 'last' being strings and required while an optional key 'middle' is must be a string if it appears but doesn't have to appear. So in this case both the following are valid: {first=>'John', middle=>'James', last=>'Napiorkowski'} {first=>'Vanessa', last=>'Li'} If you use the `Maybe` type constraint instead, your values will also validate against `undef`, which may be incorrect for you. # EXPORTABLE SUBROUTINES This type library makes available for export the following subroutines ## slurpy Structured type constraints by their nature are closed; that is validation will depend on an exact match between your structure definition and the arguments to be checked. Sometimes you might wish for a slightly looser amount of validation. For example, you may wish to validate the first 3 elements of an array reference and allow for an arbitrary number of additional elements. At first thought you might think you could do it this way: # I want to validate stuff like: [1,"hello", $obj, 2,3,4,5,6,...] subtype AllowTailingArgs, as Tuple[ Int, Str, Object, ArrayRef[Int], ]; However what this will actually validate are structures like this: [10,"Hello", $obj, [11,12,13,...] ]; # Notice element 4 is an ArrayRef In order to allow structured validation of, "and then some", arguments, you can use the ["slurpy"](#slurpy) method against a type constraint. For example: use MooseX::Types::Structured qw(Tuple slurpy); subtype AllowTailingArgs, as Tuple[ Int, Str, Object, slurpy ArrayRef[Int], ]; This will now work as expected, validating ArrayRef structures such as: [1,"hello", $obj, 2,3,4,5,6,...] A few caveats apply. First, the slurpy type constraint must be the last one in the list of type constraint parameters. Second, the parent type of the slurpy type constraint must match that of the containing type constraint. That means that a `Tuple` can allow a slurpy `ArrayRef` (or children of `ArrayRef`s, including another `Tuple`) and a `Dict` can allow a slurpy `HashRef` (or children/subtypes of HashRef, also including other `Dict` constraints). Please note the technical way this works 'under the hood' is that the slurpy keyword transforms the target type constraint into a coderef. Please do not try to create your own custom coderefs; always use the slurpy method. The underlying technology may change in the future but the slurpy keyword will be supported. # ERROR MESSAGES Error reporting has been improved to return more useful debugging messages. Now I will stringify the incoming check value with [Devel::PartialDump](https://metacpan.org/pod/Devel::PartialDump) so that you can see the actual structure that is tripping up validation. Also, I report the 'internal' validation error, so that if a particular element inside the Structured Type is failing validation, you will see that. There's a limit to how deep this internal reporting goes, but you shouldn't see any of the "failed with ARRAY(XXXXXX)" that we got with earlier versions of this module. This support is continuing to expand, so it's best to use these messages for debugging purposes and not for creating messages that 'escape into the wild' such as error messages sent to the user. Please see the test '12-error.t' for a more lengthy example. Your thoughts and preferable tests or code patches very welcome! # EXAMPLES Here are some additional example usage for structured types. All examples can be found also in the 't/examples.t' test. Your contributions are also welcomed. ## Normalize a HashRef You need a hashref to conform to a canonical structure but are required accept a bunch of different incoming structures. You can normalize using the `Dict` type constraint and coercions. This example also shows structured types mixed which other [MooseX::Types](https://metacpan.org/pod/MooseX::Types) libraries. package Test::MooseX::Meta::TypeConstraint::Structured::Examples::Normalize; use Moose; use DateTime; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::DateTime qw(DateTime); use MooseX::Types::Moose qw(Int Str Object); use MooseX::Types -declare => [qw(Name Age Person)]; subtype Person, as Dict[ name=>Str, age=>Int, ]; coerce Person, from Dict[ first=>Str, last=>Str, years=>Int, ], via { +{ name => "$_->{first} $_->{last}", age => $_->{years}, }}, from Dict[ fullname=>Dict[ last=>Str, first=>Str, ], dob=>DateTime, ], ## DateTime needs to be inside of single quotes here to disambiguate the ## class package from the DataTime type constraint imported via the ## line "use MooseX::Types::DateTime qw(DateTime);" via { +{ name => "$_->{fullname}{first} $_->{fullname}{last}", age => ($_->{dob} - 'DateTime'->now)->years, }}; has person => (is=>'rw', isa=>Person, coerce=>1); And now you can instantiate with all the following: __PACKAGE__->new( person=>{ name=>'John Napiorkowski', age=>39, }, ); __PACKAGE__->new( person=>{ first=>'John', last=>'Napiorkowski', years=>39, }, ); __PACKAGE__->new( person=>{ fullname => { first=>'John', last=>'Napiorkowski' }, dob => 'DateTime'->new( year=>1969, month=>2, day=>13 ), }, ); This technique is a way to support various ways to instantiate your class in a clean and declarative way. # SEE ALSO The following modules or resources may be of interest. [Moose](https://metacpan.org/pod/Moose), [MooseX::Types](https://metacpan.org/pod/MooseX::Types), [Moose::Meta::TypeConstraint](https://metacpan.org/pod/Moose::Meta::TypeConstraint), [MooseX::Meta::TypeConstraint::Structured](https://metacpan.org/pod/MooseX::Meta::TypeConstraint::Structured) # AUTHORS - John Napiorkowski - Florian Ragwitz - יובל קוג'מן (Yuval Kogman) - Tomas (t0m) Doran - Robert Sedlacek # COPYRIGHT AND LICENSE This software is copyright (c) 2008 by John Napiorkowski. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. # CONTRIBUTORS - Ansgar Burchardt - Dave Rolsky - Jesse Luehrs - Karen Etheridge - Ricardo Signes - Robert 'phaylon' Sedlacek - Stevan Little - arcanez MooseX-Types-Structured-0.30/t/000755 000767 000024 00000000000 12254674163 016643 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/weaver.ini000644 000767 000024 00000000114 12254674163 020366 0ustar00etherstaff000000 000000 [@Default] [-Transformer] transformer = List [-StopWords] [Contributors] MooseX-Types-Structured-0.30/xt/000755 000767 000024 00000000000 12254674163 017033 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/xt/author/000755 000767 000024 00000000000 12254674163 020335 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/xt/release/000755 000767 000024 00000000000 12254674163 020453 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/xt/release/changes_has_content.t000644 000767 000024 00000002010 12254674163 024626 0ustar00etherstaff000000 000000 #!perl use Test::More tests => 2; note 'Checking Changes'; my $changes_file = 'Changes'; my $newver = '0.30'; my $trial_token = '-TRIAL'; SKIP: { ok(-e $changes_file, "$changes_file file exists") or skip 'Changes is missing', 1; ok(_get_changes($newver), "$changes_file has content for $newver"); } done_testing; # _get_changes copied and adapted from Dist::Zilla::Plugin::Git::Commit # by Jerome Quelin sub _get_changes { my $newver = shift; # parse changelog to find commit message open(my $fh, '<', $changes_file) or die "cannot open $changes_file: $!"; my $changelog = join('', <$fh>); close $fh; my @content = grep { /^$newver(?:$trial_token)?(?:\s+|$)/ ... /^\S/ } # from newver to un-indented split /\n/, $changelog; shift @content; # drop the version line # drop unindented last line and trailing blank lines pop @content while ( @content && $content[-1] =~ /^(?:\S|\s*$)/ ); # return number of non-blank lines return scalar @content; } MooseX-Types-Structured-0.30/xt/release/cpan-changes.t000644 000767 000024 00000000263 12254674163 023170 0ustar00etherstaff000000 000000 #!perl use strict; use warnings; use Test::More 0.96 tests => 2; use_ok('Test::CPAN::Changes'); subtest 'changes_ok' => sub { changes_file_ok('Changes'); }; done_testing(); MooseX-Types-Structured-0.30/xt/release/distmeta.t000644 000767 000024 00000000217 12254674163 022452 0ustar00etherstaff000000 000000 #!perl use Test::More; eval "use Test::CPAN::Meta"; plan skip_all => "Test::CPAN::Meta required for testing META.yml" if $@; meta_yaml_ok(); MooseX-Types-Structured-0.30/xt/release/eol.t000644 000767 000024 00000000240 12254674163 021413 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; eval 'use Test::EOL'; plan skip_all => 'Test::EOL required' if $@; all_perl_files_ok({ trailing_whitespace => 1 }); MooseX-Types-Structured-0.30/xt/release/kwalitee.t000644 000767 000024 00000000166 12254674163 022450 0ustar00etherstaff000000 000000 # this test was generated with Dist::Zilla::Plugin::Test::Kwalitee 2.07 use strict; use warnings; use Test::Kwalitee; MooseX-Types-Structured-0.30/xt/release/minimum-version.t000644 000767 000024 00000000271 12254674163 023776 0ustar00etherstaff000000 000000 #!perl use Test::More; eval "use Test::MinimumVersion"; plan skip_all => "Test::MinimumVersion required for testing minimum versions" if $@; all_minimum_version_ok( qq{5.008001} ); MooseX-Types-Structured-0.30/xt/release/mojibake.t000644 000767 000024 00000000406 12254674163 022421 0ustar00etherstaff000000 000000 #!perl use strict; use warnings qw(all); use Test::More; ## no critic (ProhibitStringyEval, RequireCheckingReturnValueOfEval) eval q(use Test::Mojibake); plan skip_all => q(Test::Mojibake required for source encoding testing) if $@; all_files_encoding_ok(); MooseX-Types-Structured-0.30/xt/release/no-tabs.t000644 000767 000024 00000001064 12254674163 022204 0ustar00etherstaff000000 000000 use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::NoTabs 0.06 use Test::More 0.88; use Test::NoTabs; my @files = ( 'lib/MooseX/Meta/TypeCoercion/Structured.pm', 'lib/MooseX/Meta/TypeCoercion/Structured/Optional.pm', 'lib/MooseX/Meta/TypeConstraint/Structured.pm', 'lib/MooseX/Meta/TypeConstraint/Structured/Optional.pm', 'lib/MooseX/Types/Structured.pm', 'lib/MooseX/Types/Structured/MessageStack.pm', 'lib/MooseX/Types/Structured/OverflowHandler.pm' ); notabs_ok($_) foreach @files; done_testing; MooseX-Types-Structured-0.30/xt/release/pod-coverage.t000644 000767 000024 00000000527 12254674163 023217 0ustar00etherstaff000000 000000 #!perl use Test::More; eval "use Test::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); MooseX-Types-Structured-0.30/xt/release/pod-no404s.t000644 000767 000024 00000000527 12254674163 022453 0ustar00etherstaff000000 000000 #!perl use strict; use warnings; use Test::More; foreach my $env_skip ( qw( SKIP_POD_NO404S AUTOMATED_TESTING ) ){ plan skip_all => "\$ENV{$env_skip} is set, skipping" if $ENV{$env_skip}; } eval "use Test::Pod::No404s"; if ( $@ ) { plan skip_all => 'Test::Pod::No404s required for testing POD'; } else { all_pod_files_ok(); } MooseX-Types-Structured-0.30/xt/release/pod-syntax.t000644 000767 000024 00000000212 12254674163 022741 0ustar00etherstaff000000 000000 #!perl use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); MooseX-Types-Structured-0.30/xt/release/portability.t000644 000767 000024 00000000276 12254674163 023207 0ustar00etherstaff000000 000000 #!perl use strict; use warnings; use Test::More; eval 'use Test::Portability::Files'; plan skip_all => 'Test::Portability::Files required for testing portability' if $@; run_tests(); MooseX-Types-Structured-0.30/xt/release/test-version.t000644 000767 000024 00000000643 12254674163 023305 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 0.002004 BEGIN { eval "use Test::Version; 1;" or die $@; } my @imports = ( 'version_all_ok' ); my $params = { is_strict => 1, has_version => 0, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; MooseX-Types-Structured-0.30/xt/release/unused-vars.t000644 000767 000024 00000000207 12254674163 023113 0ustar00etherstaff000000 000000 #!perl use Test::More; eval "use Test::Vars"; plan skip_all => "Test::Vars required for testing unused vars" if $@; all_vars_ok(); MooseX-Types-Structured-0.30/xt/author/00-compile.t000644 000767 000024 00000002524 12254674163 022372 0ustar00etherstaff000000 000000 use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.039 use Test::More 0.94 tests => 7 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'MooseX/Meta/TypeCoercion/Structured.pm', 'MooseX/Meta/TypeCoercion/Structured/Optional.pm', 'MooseX/Meta/TypeConstraint/Structured.pm', 'MooseX/Meta/TypeConstraint/Structured/Optional.pm', 'MooseX/Types/Structured.pm', 'MooseX/Types/Structured/MessageStack.pm', 'MooseX/Types/Structured/OverflowHandler.pm' ); # no fake home requested my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') if $ENV{AUTHOR_TESTING}; BAIL_OUT("Compilation problems") if !Test::More->builder->is_passing; MooseX-Types-Structured-0.30/xt/author/pod-spell.t000644 000767 000024 00000001141 12254674163 022416 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.006002 use Test::Spelling 0.12; use Pod::Wordlist; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ John Napiorkowski jjnapiork Florian Ragwitz rafl יובל קוג Yuval Kogman nothingmuch Tomas t0m Doran bobtfish Robert Sedlacek rs Ansgar Burchardt ansgar Dave Rolsky autarch Jesse Luehrs doy Karen Etheridge ether Ricardo Signes rjbs phaylon Stevan Little stevan arcanez justin lib MooseX Meta TypeConstraint Structured Types MessageStack TypeCoercion Optional OverflowHandler MooseX-Types-Structured-0.30/t/00-load.t000644 000767 000024 00000000461 12254674163 020165 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests=>4; ## List all the modules we want to make sure can at least compile use_ok 'MooseX::Meta::TypeConstraint::Structured'; use_ok 'MooseX::Meta::TypeCoercion::Structured'; use_ok 'MooseX::Types::Structured::MessageStack'; use_ok 'MooseX::Types::Structured'; MooseX-Types-Structured-0.30/t/00-report-prereqs.t000644 000767 000024 00000007266 12254674163 022252 0ustar00etherstaff000000 000000 #!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.010 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec::Functions; use List::Util qw/max/; my @modules = qw( CPAN::Meta CPAN::Meta::Requirements Data::Dumper DateTime Devel::PartialDump ExtUtils::MakeMaker File::Spec::Functions List::Util Module::Build::Tiny Moose Moose::Meta::TypeCoercion Moose::Meta::TypeConstraint Moose::Meta::TypeConstraint::Parameterizable Moose::Util::TypeConstraints MooseX::Types MooseX::Types::DateTime MooseX::Types::Moose Scalar::Util Sub::Exporter Test::Fatal Test::More overload perl strict warnings ); my %exclude = map {; $_ => 1 } qw( ); my ($source) = grep { -f $_ } qw/MYMETA.json MYMETA.yml META.json/; $source = "META.yml" unless defined $source; # replace modules with dynamic results from MYMETA.json if we can # (hide CPAN::Meta from prereq scanner) my $cpan_meta = "CPAN::Meta"; my $cpan_meta_req = "CPAN::Meta::Requirements"; my $all_requires; if ( -f $source && eval "require $cpan_meta" ) { ## no critic if ( my $meta = eval { CPAN::Meta->load_file($source) } ) { # Get ALL modules mentioned in META (any phase/type) my $prereqs = $meta->prereqs; delete $prereqs->{develop} if not $ENV{AUTHOR_TESTING}; my %uniq = map {$_ => 1} map { keys %$_ } map { values %$_ } values %$prereqs; $uniq{$_} = 1 for @modules; # don't lose any static ones @modules = sort grep { ! $exclude{$_} } keys %uniq; # If verifying, merge 'requires' only for major phases if ( 1 ) { $prereqs = $meta->effective_prereqs; # get the object, not the hash if (eval "require $cpan_meta_req; 1") { ## no critic $all_requires = $cpan_meta_req->new; for my $phase ( qw/configure build test runtime/ ) { $all_requires->add_requirements( $prereqs->requirements_for($phase, 'requires') ); } } } } } my @reports = [qw/Version Module/]; my @dep_errors; my $req_hash = defined($all_requires) ? $all_requires->as_string_hash : {}; for my $mod ( @modules ) { next if $mod eq 'perl'; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e catfile($_, $file) } @INC; if ( $prefix ) { my $ver = MM->parse_version( catfile($prefix, $file) ); $ver = "undef" unless defined $ver; # Newer MM should do this anyway push @reports, [$ver, $mod]; if ( 1 && $all_requires ) { my $req = $req_hash->{$mod}; if ( defined $req && length $req ) { if ( ! defined eval { version->parse($ver) } ) { push @dep_errors, "$mod version '$ver' cannot be parsed (version '$req' required)"; } elsif ( ! $all_requires->accepts_module( $mod => $ver ) ) { push @dep_errors, "$mod version '$ver' is not in required range '$req'"; } } } } else { push @reports, ["missing", $mod]; if ( 1 && $all_requires ) { my $req = $req_hash->{$mod}; if ( defined $req && length $req ) { push @dep_errors, "$mod is not installed (version '$req' required)"; } } } } if ( @reports ) { my $vl = max map { length $_->[0] } @reports; my $ml = max map { length $_->[1] } @reports; splice @reports, 1, 0, ["-" x $vl, "-" x $ml]; diag "\nVersions for all modules listed in $source (including optional ones):\n", map {sprintf(" %*s %*s\n",$vl,$_->[0],-$ml,$_->[1])} @reports; } if ( @dep_errors ) { diag join("\n", "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n", "The following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=2 sts=2 sw=2 et: MooseX-Types-Structured-0.30/t/01-basic.t000644 000767 000024 00000002615 12254674163 020333 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests=>14; use_ok 'MooseX::Meta::TypeConstraint::Structured'; use_ok 'Moose::Util::TypeConstraints'; ok my $int = find_type_constraint('Int') => 'Got Int'; ok my $str = find_type_constraint('Str') => 'Got Str'; ok my $arrayref = find_type_constraint('ArrayRef') => 'Got ArrayRef'; my $list_tc = MooseX::Meta::TypeConstraint::Structured->new( name => 'list_tc', parent => $arrayref, type_constraints => [$int, $str], constraint_generator=> sub { my ($self) = @_; my @type_constraints = @{ $self->type_constraints }; return sub { my ($values, $err) = @_; my @values = @$values; for my $type_constraint (@type_constraints) { my $value = shift @values || return; $type_constraint->check($value) || return; } if(@values) { return; } else { return 1; } } } ); isa_ok $list_tc, 'MooseX::Meta::TypeConstraint::Structured'; ok !$arrayref->check() => 'Parent undef fails'; ok !$list_tc->check() => 'undef fails'; ok !$list_tc->check(1) => '1 fails'; ok !$list_tc->check([]) => '[] fails'; ok !$list_tc->check([1]) => '[1] fails'; ok !$list_tc->check([1,2,3]) => '[1,2,3] fails'; ok !$list_tc->check(['a','b']) => '["a","b"] fails'; ok $list_tc->check([1,'a']) => '[1,"a"] passes'; MooseX-Types-Structured-0.30/t/02-tuple.t000644 000767 000024 00000015137 12254674163 020407 0ustar00etherstaff000000 000000 BEGIN { use strict; use warnings; use Test::More tests=>32; use Test::Fatal; } { package Test::MooseX::Meta::TypeConstraint::Structured::Tuple; use Moose; use MooseX::Types::Structured qw(Tuple); use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef Maybe); use MooseX::Types -declare => [qw(MyString MoreThanFive FiveByFive MyArrayRefMoreThanTwoInt)]; subtype MyString, as Str, where { $_=~m/abc/}; subtype MoreThanFive, as Int, where { $_ > 5}; subtype MyArrayRefMoreThanTwoInt, as ArrayRef[MoreThanFive], where { scalar @$_ > 2 }; subtype FiveByFive, as Tuple[MoreThanFive, MyArrayRefMoreThanTwoInt]; #use Data::Dump qw/dump/; warn dump Tuple; has 'tuple' => (is=>'rw', isa=>Tuple[Int, Str, MyString]); has 'tuple_with_param' => (is=>'rw', isa=>Tuple[Int, Str, ArrayRef[Int]]); has 'tuple_with_maybe' => (is=>'rw', isa=>Tuple[Int, Str, Maybe[Int], Object]); has 'tuple_with_maybe2' => (is=>'rw', isa=>Tuple[Int, Str, Maybe[Int]]); has 'tuple_with_union' => (is=>'rw', isa=>Tuple[Int,Str,Int|Object,Int]); has 'tuple2' => (is=>'rw', isa=>Tuple[Int,Str,Int]); has 'tuple_with_parameterized' => (is=>'rw', isa=>Tuple[Int,Str,Int,ArrayRef[Int]]); has 'FiveByFiveAttr' => (is=>'rw', isa=>FiveByFive); } ## Instantiate a new test object ok my $record = Test::MooseX::Meta::TypeConstraint::Structured::Tuple->new => 'Instantiated new Record test class.'; isa_ok $record => 'Test::MooseX::Meta::TypeConstraint::Structured::Tuple' => 'Created correct object type.'; ## Test Tuple type constraint is( exception { $record->tuple([1,'hello', 'test.abc.test']); } => undef, 'Set tuple attribute without error'); is $record->tuple->[0], 1 => 'correct set the tuple attribute index 0'; is $record->tuple->[1], 'hello' => 'correct set the tuple attribute index 1'; is $record->tuple->[2], 'test.abc.test' => 'correct set the tuple attribute index 2'; like( exception { $record->tuple([1,'hello', 'test.xxx.test']); }, qr/Attribute \(tuple\) does not pass the type constraint/ => 'Properly failed for bad value in custom type constraint'); like( exception { $record->tuple(['asdasd',2, 'test.abc.test']); }, qr/Attribute \(tuple\) does not pass the type constraint/ => 'Got Expected Error for violating constraints'); ## Test tuple_with_maybe is( exception { $record->tuple_with_maybe([1,'hello', 1, $record]); } => undef, 'Set tuple attribute without error'); like( exception { $record->tuple_with_maybe([1,'hello', 'a', $record]); }, qr/Attribute \(tuple_with_maybe\) does not pass the type constraint/ => 'Properly failed for bad value parameterized constraint'); is( exception { $record->tuple_with_maybe([1,'hello',undef, $record]); } => undef, 'Set tuple attribute without error skipping optional parameter'); ## Test tuple_with_maybe2 is( exception { $record->tuple_with_maybe2([1,'hello', 1]); } => undef, 'Set tuple attribute without error'); like( exception { $record->tuple_with_maybe2([1,'hello', 'a']); }, qr/Attribute \(tuple_with_maybe2\) does not pass the type constraint/ => 'Properly failed for bad value parameterized constraint'); is( exception { $record->tuple_with_maybe2([1,'hello',undef]); } => undef, 'Set tuple attribute without error skipping optional parameter'); SKIP: { skip 'Core Maybe incorrectly allows null.', 1, 1; like( exception { $record->tuple_with_maybe2([1,'hello']); }, qr/Attribute \(tuple_with_maybe2\) does not pass the type constraint/ => 'Properly fails for missing maybe (needs to be at least undef)'); } ## Test Tuple with parameterized type is( exception { $record->tuple_with_param([1,'hello', [1,2,3]]); } => undef, 'Set tuple attribute without error'); like( exception { $record->tuple_with_param([1,'hello', [qw/a b c/]]); }, qr/Attribute \(tuple_with_param\) does not pass the type constraint/ => 'Properly failed for bad value parameterized constraint'); ## Test tuple2 (Tuple[Int,Str,Int]) ok $record->tuple2([1,'hello',3]) => "[1,'hello',3] properly suceeds"; like( exception { $record->tuple2([1,2,'world']); }, qr/Attribute \(tuple2\) does not pass the type constraint/ => "[1,2,'world'] properly fails"); like( exception { $record->tuple2(['hello1',2,3]); }, qr/Attribute \(tuple2\) does not pass the type constraint/ => "['hello',2,3] properly fails"); like( exception { $record->tuple2(['hello2',2,'world']); }, qr/Attribute \(tuple2\) does not pass the type constraint/ => "['hello',2,'world'] properly fails"); ## Test tuple_with_parameterized (Tuple[Int,Str,Int,ArrayRef[Int]]) ok $record->tuple_with_parameterized([1,'hello',3,[1,2,3]]) => "[1,'hello',3,[1,2,3]] properly suceeds"; like( exception { $record->tuple_with_parameterized([1,2,'world']); }, qr/Attribute \(tuple_with_parameterized\) does not pass the type constraint/ => "[1,2,'world'] properly fails"); like( exception { $record->tuple_with_parameterized(['hello1',2,3]); }, qr/Attribute \(tuple_with_parameterized\) does not pass the type constraint/ => "['hello',2,3] properly fails"); like( exception { $record->tuple_with_parameterized(['hello2',2,'world']); }, qr/Attribute \(tuple_with_parameterized\) does not pass the type constraint/ => "['hello',2,'world'] properly fails"); like( exception { $record->tuple_with_parameterized([1,'hello',3,[1,2,'world']]); }, qr/Attribute \(tuple_with_parameterized\) does not pass the type constraint/ => "[1,'hello',3,[1,2,'world']] properly fails"); ## Test FiveByFiveAttr is( exception { $record->FiveByFiveAttr([6,[7,8,9]]); } => undef, 'Set FiveByFiveAttr correctly'); like( exception { $record->FiveByFiveAttr([1,'hello', 'test']); }, qr/Attribute \(FiveByFiveAttr\) does not pass the type constraint/ => q{Properly failed for bad value in FiveByFiveAttr [1,'hello', 'test']}); like( exception { $record->FiveByFiveAttr([1,[8,9,10]]); }, qr/Attribute \(FiveByFiveAttr\) does not pass the type constraint/ => q{Properly failed for bad value in FiveByFiveAttr [1,[8,9,10]]}); like( exception { $record->FiveByFiveAttr([10,[11,12,0]]); }, qr/Attribute \(FiveByFiveAttr\) does not pass the type constraint/ => q{Properly failed for bad value in FiveByFiveAttr [10,[11,12,0]]}); like( exception { $record->FiveByFiveAttr([1,[1,1,0]]); }, qr/Attribute \(FiveByFiveAttr\) does not pass the type constraint/ => q{Properly failed for bad value in FiveByFiveAttr [1,[1,1,0]]}); like( exception { $record->FiveByFiveAttr([10,[11,12]]); }, qr/Attribute \(FiveByFiveAttr\) does not pass the type constraint/ => q{Properly failed for bad value in FiveByFiveAttr [10,[11,12]}); MooseX-Types-Structured-0.30/t/03-dict.t000644 000767 000024 00000006214 12254674163 020176 0ustar00etherstaff000000 000000 BEGIN { use strict; use warnings; use Test::More tests=>17; use Test::Fatal; } { package Test::MooseX::Meta::TypeConstraint::Structured::Dict; use Moose; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef Maybe); use MooseX::Types -declare => [qw(MyString)]; subtype MyString, as Str, where { $_=~m/abc/}; has 'dict' => (is=>'rw', isa=>Dict[name=>Str, age=>Int]); has 'dict_with_maybe' => (is=>'rw', isa=>Dict[name=>Str, age=>Maybe[Int]]); has 'dict_with_tuple_with_union' => (is=>'rw', isa=>Dict[key1=>Str|Object, key2=>Tuple[Int,Str|Object]] ); } ## Instantiate a new test object ok my $record = Test::MooseX::Meta::TypeConstraint::Structured::Dict->new => 'Instantiated new Record test class.'; isa_ok $record => 'Test::MooseX::Meta::TypeConstraint::Structured::Dict' => 'Created correct object type.'; # Test dict Dict[name=>Str, age=>Int] is( exception { $record->dict({name=>'frith', age=>23}); } => undef, 'Set dict attribute without error'); is $record->dict->{name}, 'frith' => 'correct set the dict attribute name'; is $record->dict->{age}, 23 => 'correct set the dict attribute age'; like( exception { $record->dict({name=>[1,2,3], age=>'sdfsdfsd'}); }, qr/Attribute \(dict\) does not pass the type constraint/ => 'Got Expected Error for bad value in dict'); ## Test dict_with_maybe is( exception { $record->dict_with_maybe({name=>'frith', age=>23}); } => undef, 'Set dict attribute without error'); is $record->dict_with_maybe->{name}, 'frith' => 'correct set the dict attribute name'; is $record->dict_with_maybe->{age}, 23 => 'correct set the dict attribute age'; like( exception { $record->dict_with_maybe({name=>[1,2,3], age=>'sdfsdfsd'}); }, qr/Attribute \(dict_with_maybe\) does not pass the type constraint/ => 'Got Expected Error for bad value in dict'); like( exception { $record->dict_with_maybe({age=>30}); }, qr/Attribute \(dict_with_maybe\) does not pass the type constraint/ => 'Got Expected Error for missing named parameter'); is( exception { $record->dict_with_maybe({name=>'usal', age=>undef}); } => undef, 'Set dict attribute without error, skipping maybe'); ## Test dict_with_tuple_with_union: Dict[key1=>'Str|Object', key2=>Tuple['Int','Str|Object']] is( exception { $record->dict_with_tuple_with_union({key1=>'Hello', key2=>[1,'World']}); } => undef, 'Set tuple attribute without error'); like( exception { $record->dict_with_tuple_with_union({key1=>'Hello', key2=>['World',2]}); }, qr/Attribute \(dict_with_tuple_with_union\) does not pass the type constraint/ => 'Threw error on bad constraint'); is( exception { $record->dict_with_tuple_with_union({key1=>$record, key2=>[1,'World']}); } => undef, 'Set tuple attribute without error'); is( exception { $record->dict_with_tuple_with_union({key1=>'Hello', key2=>[1,$record]}); } => undef, 'Set tuple attribute without error'); like( exception { $record->dict_with_tuple_with_union({key1=>1, key2=>['World',2]}); }, qr/Attribute \(dict_with_tuple_with_union\) does not pass the type constraint/ => 'Threw error on bad constraint'); MooseX-Types-Structured-0.30/t/04-combined.t000644 000767 000024 00000004037 12254674163 021035 0ustar00etherstaff000000 000000 BEGIN { use strict; use warnings; use Test::More tests=>9; use Test::Fatal; } { package Test::MooseX::Meta::TypeConstraint::Structured::Combined; use Moose; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef Maybe); has 'dict_with_tuple' => (is=>'rw', isa=>Dict[key1=>Str, key2=>Tuple[Int,Str]]); has 'dict_with_tuple_with_union' => (is=>'rw', isa=>Dict[key1=>Str|Object, key2=>Tuple[Int,Str|Object]] ); } ## Instantiate a new test object ok my $record = Test::MooseX::Meta::TypeConstraint::Structured::Combined->new => 'Instantiated new Record test class.'; isa_ok $record => 'Test::MooseX::Meta::TypeConstraint::Structured::Combined' => 'Created correct object type.'; ## Test dict_with_tuple is( exception { $record->dict_with_tuple({key1=>'Hello', key2=>[1,'World']}); } => undef, 'Set tuple attribute without error'); like( exception { $record->dict_with_tuple({key1=>'Hello', key2=>['World',2]}); }, qr/Attribute \(dict_with_tuple\) does not pass the type constraint/ => 'Threw error on bad constraint'); ## Test dict_with_tuple_with_union: Dict[key1=>'Str|Object', key2=>Tuple['Int','Str|Object']] is( exception { $record->dict_with_tuple_with_union({key1=>'Hello', key2=>[1,'World']}); } => undef, 'Set tuple attribute without error'); like( exception { $record->dict_with_tuple_with_union({key1=>'Hello', key2=>['World',2]}); }, qr/Attribute \(dict_with_tuple_with_union\) does not pass the type constraint/ => 'Threw error on bad constraint'); is( exception { $record->dict_with_tuple_with_union({key1=>$record, key2=>[1,'World']}); } => undef, 'Set tuple attribute without error'); is( exception { $record->dict_with_tuple_with_union({key1=>'Hello', key2=>[1,$record]}); } => undef, 'Set tuple attribute without error'); like( exception { $record->dict_with_tuple_with_union({key1=>1, key2=>['World',2]}); }, qr/Attribute \(dict_with_tuple_with_union\) does not pass the type constraint/ => 'Threw error on bad constraint'); MooseX-Types-Structured-0.30/t/04-map.t000644 000767 000024 00000001131 12254674163 020022 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; use Test::Fatal; use MooseX::Types::Moose qw(Int Num); use MooseX::Types::Structured qw(Map); my $type = Map[ Int, Num ]; ok($type->assert_valid({ 10 => 10.5 }), "simple Int -> Num mapping"); like( exception { $type->assert_valid({ 10.5 => 10.5 }) }, qr{value .*10\.5.*}, "non-Int causes rejection on key"); like( exception { $type->assert_valid({ 10 => "ten and a half" }) }, qr{value .*ten and a half.*}, "non-Num value causes rejection on value"); ok($type->assert_valid({ }), "empty hashref is a valid mapping of any sort"); done_testing; MooseX-Types-Structured-0.30/t/05-advanced.t000644 000767 000024 00000011257 12254674163 021025 0ustar00etherstaff000000 000000 BEGIN { use strict; use warnings; use Test::More tests=>16; use Test::Fatal; } { package Test::MooseX::Meta::TypeConstraint::Structured::Advanced; use Moose; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef Maybe); use MooseX::Types -declare => [qw( EqualLength MoreThanFive MoreLengthPlease PersonalInfo MorePersonalInfo MinFiveChars )]; subtype MoreThanFive, as Int, where { $_ > 5}; ## Tuple contains two equal length Arrays subtype EqualLength, as Tuple[ArrayRef[MoreThanFive],ArrayRef[MoreThanFive]], where { $#{$_->[0]} == $#{$_->[1]} }; ## subclass the complex tuple subtype MoreLengthPlease, as EqualLength, where { $#{$_->[0]} >= 4}; ## Complexe Dict subtype PersonalInfo, as Dict[name=>Str, stats=>MoreLengthPlease|Object]; ## Minimum 5 char string subtype MinFiveChars, as Str, where { length($_) > 5}; ## Dict key overloading subtype MorePersonalInfo, as PersonalInfo[name=>MinFiveChars, stats=>MoreLengthPlease|Object]; has 'EqualLengthAttr' => (is=>'rw', isa=>EqualLength); has 'MoreLengthPleaseAttr' => (is=>'rw', isa=>MoreLengthPlease); has 'PersonalInfoAttr' => (is=>'rw', isa=>PersonalInfo); has 'MorePersonalInfoAttr' => (is=>'rw', isa=>MorePersonalInfo); } ## Instantiate a new test object ok my $obj = Test::MooseX::Meta::TypeConstraint::Structured::Advanced->new => 'Instantiated new Record test class.'; isa_ok $obj => 'Test::MooseX::Meta::TypeConstraint::Structured::Advanced' => 'Created correct object type.'; ## Test EqualLengthAttr is( exception { $obj->EqualLengthAttr([[6,7,8],[9,10,11]]); } => undef, 'Set EqualLengthAttr attribute without error'); like( exception { $obj->EqualLengthAttr([1,'hello', 'test.xxx.test']); }, qr/Attribute \(EqualLengthAttr\) does not pass the type constraint/ => q{EqualLengthAttr correctly fails [1,'hello', 'test.xxx.test']}); like( exception { $obj->EqualLengthAttr([[6,7],[9,10,11]]); }, qr/Attribute \(EqualLengthAttr\) does not pass the type constraint/ => q{EqualLengthAttr correctly fails [[6,7],[9,10,11]]}); like( exception { $obj->EqualLengthAttr([[6,7,1],[9,10,11]]); }, qr/Attribute \(EqualLengthAttr\) does not pass the type constraint/ => q{EqualLengthAttr correctly fails [[6,7,1],[9,10,11]]}); ## Test MoreLengthPleaseAttr is( exception { $obj->MoreLengthPleaseAttr([[6,7,8,9,10],[11,12,13,14,15]]); } => undef, 'Set MoreLengthPleaseAttr attribute without error'); like( exception { $obj->MoreLengthPleaseAttr([[6,7,8,9],[11,12,13,14]]); }, qr/Attribute \(MoreLengthPleaseAttr\) does not pass the type constraint/ => q{MoreLengthPleaseAttr correctly fails [[6,7,8,9],[11,12,13,14]]}); ## Test PersonalInfoAttr is( exception { $obj->PersonalInfoAttr({name=>'John', stats=>[[6,7,8,9,10],[11,12,13,14,15]]}); } => undef, 'Set PersonalInfoAttr attribute without error 1'); is( exception { $obj->PersonalInfoAttr({name=>'John', stats=>$obj}); } => undef, 'Set PersonalInfoAttr attribute without error 2'); like( exception { $obj->PersonalInfoAttr({name=>'John', stats=>[[6,7,8,9],[11,12,13,14]]}); }, qr/Attribute \(PersonalInfoAttr\) does not pass the type constraint/ => q{PersonalInfoAttr correctly fails name=>'John', stats=>[[6,7,8,9],[11,12,13,14]]}); like( exception { $obj->PersonalInfoAttr({name=>'John', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]}); }, qr/Attribute \(PersonalInfoAttr\) does not pass the type constraint/ => q{PersonalInfoAttr correctly fails name=>'John', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]}); ## Test MorePersonalInfoAttr is( exception { $obj->MorePersonalInfoAttr({name=>'Johnnap', stats=>[[6,7,8,9,10],[11,12,13,14,15]]}); } => undef, 'Set MorePersonalInfoAttr attribute without error 1'); like( exception { $obj->MorePersonalInfoAttr({name=>'Johnnap', stats=>[[6,7,8,9],[11,12,13,14]]}); }, qr/Attribute \(MorePersonalInfoAttr\) does not pass the type constraint/ => q{MorePersonalInfoAttr correctly fails name=>'Johnnap', stats=>[[6,7,8,9],[11,12,13,14]]}); like( exception { $obj->MorePersonalInfoAttr({name=>'Johnnap', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]}); }, qr/Attribute \(MorePersonalInfoAttr\) does not pass the type constraint/ => q{MorePersonalInfoAttr correctly fails name=>'Johnnap', extra=>1, stats=>[[6,7,8,9,10],[11,12,13,14,15]]}); like( exception { $obj->MorePersonalInfoAttr({name=>'.bc', stats=>[[6,7,8,9,10],[11,12,13,14,15]]}); }, qr/Attribute \(MorePersonalInfoAttr\) does not pass the type constraint/ => q{MorePersonalInfoAttr correctly fails name=>'.bc', stats=>[[6,7,8,9,10],[11,12,13,14,15]]}); MooseX-Types-Structured-0.30/t/06-api.t000644 000767 000024 00000017002 12254674163 020024 0ustar00etherstaff000000 000000 BEGIN { use strict; use warnings; use Test::More tests=>88; } { package TypeLib; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::Moose qw(Int Str Item Object ArrayRef HashRef); use MooseX::Types -declare => [qw( MyDict1 MyDict2 MyDict3 MyDict4 subMyDict3 subMyDict1 MyTuple1 MyTuple2 MyTuple3 subMyTuple3 )]; ## Create some sample Dicts subtype MyDict1, as Dict[name=>Str, age=>Int]; subtype subMyDict1, as MyDict1; subtype MyDict2, as Dict[name=>Str, age=>Int]; subtype MyDict3, as Dict[key=>Int, anotherkey=>Str]; subtype subMyDict3, as MyDict3; subtype MyDict4, as Dict[name=>Str, age=>Item]; ## Create some sample Tuples subtype MyTuple1, as Tuple[Int,Int,Str]; subtype MyTuple2, as Tuple[Int,Int,Str]; subtype MyTuple3, as Tuple[Object, HashRef]; subtype subMyTuple3, as MyTuple3; } use Moose::Util::TypeConstraints; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::Moose qw(Int Str Item Object ArrayRef HashRef); BEGIN { TypeLib->import(':all'); } ## Test equals ok ( MyDict1->equals(MyDict2), 'MyDict1 == MyDict2'); ok ( MyDict2->equals(MyDict1), 'MyDict2 == MyDict1'); ok (!MyDict1->equals(MyDict3), 'MyDict1 == MyDict3'); ok (!MyDict2->equals(MyDict3), 'MyDict2 == MyDict3'); ok (!MyDict3->equals(MyDict2), 'MyDict3 == MyDict2'); ok (!MyDict3->equals(MyDict1), 'MyDict3 == MyDict1'); ok ( MyTuple1->equals(MyTuple2), 'MyTuple1 == MyTuple2'); ok ( MyTuple2->equals(MyTuple1), 'MyTuple2 == MyTuple1'); ok (!MyTuple1->equals(MyTuple3), 'MyTuple1 == MyTuple3'); ok (!MyTuple2->equals(MyTuple3), 'MyTuple2 == MyTuple3'); ok (!MyTuple3->equals(MyTuple2), 'MyTuple3 == MyTuple2'); ok (!MyTuple3->equals(MyTuple1), 'MyTuple3 == MyTuple1'); ok ( MyDict1->equals(MyDict2), 'MyDict1 == MyDict2'); ok ( MyDict2->equals(MyDict1), 'MyDict2 == MyDict1'); ok (!MyDict1->equals(MyDict3), 'MyDict1 == MyDict3'); ok (!MyDict1->equals(MyDict4), 'MyDict1 == MyDict3'); ok (!MyDict2->equals(MyDict3), 'MyDict2 == MyDict3'); ok (!MyDict2->equals(MyDict4), 'MyDict2 == MyDict3'); ok (!MyDict3->equals(MyDict2), 'MyDict3 == MyDict2'); ok (!MyDict3->equals(MyDict4), 'MyDict3 == MyDict2'); ok (!MyDict3->equals(MyDict1), 'MyDict3 == MyDict1'); ok (!MyDict4->equals(MyDict1), 'MyDict3 == MyDict1'); ok (!MyDict4->equals(MyDict2), 'MyDict3 == MyDict1'); ok (!MyDict4->equals(MyDict3), 'MyDict3 == MyDict1'); ok ( MyTuple1->equals(MyTuple2), 'MyTuple1 == MyTuple2'); ok ( MyTuple2->equals(MyTuple1), 'MyTuple2 == MyTuple1'); ok (!MyTuple1->equals(MyTuple3), 'MyTuple1 == MyTuple3'); ok (!MyTuple2->equals(MyTuple3), 'MyTuple2 == MyTuple3'); ok (!MyTuple3->equals(MyTuple2), 'MyTuple3 == MyTuple2'); ok (!MyTuple3->equals(MyTuple1), 'MyTuple3 == MyTuple1'); ## Test is_a_type_of ok ( MyDict1->is_a_type_of(HashRef), 'MyDict1 is_a_type_of HashRef'); ok ( MyDict1->is_a_type_of(Dict), 'MyDict1 is_a_type_of Dict'); ok (!MyDict1->is_a_type_of(Tuple), 'MyDict1 NOT is_a_type_of Tuple'); ok ( MyDict1->is_a_type_of(MyDict2), 'MyDict1 is_a_type_of MyDict2'); ok ( MyDict2->is_a_type_of(MyDict1), 'MyDict2 is_a_type_of MyDict1'); ok (!MyDict1->is_a_type_of(MyDict3), 'MyDict1 NOT is_a_type_of MyDict3'); ok (!MyDict2->is_a_type_of(MyDict3), 'MyDict2 NOT is_a_type_of MyDict3'); ok ( subMyDict1->is_a_type_of(Dict), 'subMyDict1 type of Dict'); ok ( subMyDict1->is_a_type_of(MyDict1), 'subMyDict1 type of MyDict1'); ok ( subMyDict1->is_a_type_of(subMyDict1), 'subMyDict1 type of subMyDict1'); ok ( subMyDict1->is_a_type_of(MyDict2), 'subMyDict1 type of MyDict2'); ok ( MyDict4->is_a_type_of(HashRef), 'MyDict4 is_a_type_of HashRef'); ok ( MyDict4->is_a_type_of(Dict), 'MyDict4 is_a_type_of Dict'); ok (!MyDict4->is_a_type_of(Tuple), 'MyDict4 NOT is_a_type_of Tuple'); ok (!MyDict4->is_a_type_of(MyDict2), 'MyDict4 NOT is_a_type_of MyDict2'); ok ( MyDict2->is_a_type_of(MyDict4), 'MyDict2 is_a_type_of MyDict4'); ok (!MyDict4->is_a_type_of(MyDict3), 'MyDict4 NOT is_a_type_of MyDict3'); ok ( MyTuple1->is_a_type_of(Tuple), 'MyTuple1 is_a_type_of Tuple'); ok (!MyTuple1->is_a_type_of(Dict), 'MyTuple1 NOT is_a_type_of Dict'); ok ( MyTuple1->is_a_type_of(MyTuple2), 'MyTuple1 is_a_type_of MyTuple2'); ok ( MyTuple2->is_a_type_of(MyTuple1), 'MyTuple2 is_a_type_of MyTuple1'); ok (!MyTuple1->is_a_type_of(MyTuple3), 'MyTuple1 NOT is_a_type_of MyTuple3'); ok (!MyTuple2->is_a_type_of(MyTuple3), 'MyTuple2 NOT is_a_type_of MyTuple3'); ## is_subtype_of ok ( not((Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->equals( Tuple[Tuple[ Item, Item ], Dict[]] )), "tuple of tuple" ); ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->equals( Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]] ), "tuple of tuple" ); ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->is_a_type_of( Tuple[Tuple[ Item, Item ], Dict[]] ), "tuple of tuple" ); ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->is_a_type_of( Tuple[Tuple[ Item, Item ], Dict[]] ), "tuple of tuple" ); ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->is_subtype_of( Tuple[Tuple[ Item, Item ], Dict[]] ), "tuple of tuple" ); ok ( MyDict1->is_subtype_of(HashRef), 'MyDict1 is_subtype_of HashRef'); ok ( MyDict1->is_subtype_of(Dict), 'MyDict1 is_subtype_of Dict'); ok ( MyDict1->is_subtype_of(MyDict4), 'MyDict1 is_subtype_of MyDict4'); ok (!MyDict1->is_subtype_of(Tuple), 'MyDict1 NOT is_subtype_of Tuple'); ok (!MyDict1->is_subtype_of(MyDict2), 'MyDict1 NOT is_subtype_of MyDict2'); ok (!MyDict2->is_subtype_of(MyDict1), 'MyDict2 NOT is_subtype_of MyDict1'); ok (!MyDict1->is_subtype_of(MyDict3), 'MyDict1 NOT is_subtype_of MyDict3'); ok (!MyDict2->is_subtype_of(MyDict3), 'MyDict2 NOT is_subtype_of MyDict3'); ok ( subMyDict1->is_subtype_of(Dict), 'subMyDict1 is_subtype_of Dict'); ok ( subMyDict1->is_subtype_of(MyDict1), 'subMyDict1 is_subtype_of MyDict1'); ok (!subMyDict1->is_subtype_of(subMyDict1), 'subMyDict1 NOT is_subtype_of subMyDict1'); ok ( subMyDict1->is_subtype_of(MyDict2), 'subMyDict1 is_subtype_of MyDict2'); ok ( MyTuple1->is_subtype_of(Tuple), 'MyTuple1 is_subtype_of Tuple'); ok (!MyTuple1->is_subtype_of(Dict), 'MyTuple1 NOT is_subtype_of Dict'); ok (!MyTuple1->is_subtype_of(MyTuple2), 'MyTuple1 is_subtype_of MyTuple2'); ok (!MyTuple2->is_subtype_of(MyTuple1), 'MyTuple2 is_subtype_of MyTuple1'); ok (!MyTuple1->is_subtype_of(MyTuple3), 'MyTuple1 NOT is_subtype_of MyTuple3'); ok (!MyTuple2->is_subtype_of(MyTuple3), 'MyTuple2 NOT is_subtype_of MyTuple3'); ## Test manual parameterizing PARAMETERIZE: { ok (my $int = Moose::Util::TypeConstraints::find_or_parse_type_constraint('Int'), 'Got Int'); ok (my $str = Moose::Util::TypeConstraints::find_or_parse_type_constraint('Str'), 'Got Str'); ok (my $hashref = Moose::Util::TypeConstraints::find_or_parse_type_constraint('HashRef[Int]'), 'Got HashRef'); ## Test Dict->parameterize ok (my $test_dict = Dict(), 'Created Test Dict'); ok (my $person = $test_dict->parameterize(name=>$str, age=>$int), 'Parameterized It'); ok ($person->check({name=>'John', age=>21}), 'Passed'); ok ($person->check({age=>25, name=>'User'}), 'Passed'); ## Test Tuple->parameterize ok (my $test_tuple = Tuple(), 'Created Test Tuple'); ok (my $int_and_hashref = $test_tuple->parameterize($int, $hashref), 'Parameterized It'); ok ($int_and_hashref->check([1, {key=>2, key2=>3}]), "Passed"); ok (!$int_and_hashref->check(['a', {key=>2, key2=>3}]), "Not Passed"); ok (!$int_and_hashref->check([1, {key=>'a', key2=>3}]), "Not Passed"); } MooseX-Types-Structured-0.30/t/07-coerce.t000644 000767 000024 00000005570 12254674163 020523 0ustar00etherstaff000000 000000 BEGIN { use strict; use warnings; use Test::More tests=>16; } { package Test::MooseX::Meta::TypeConstraint::Structured::Coerce; use Moose; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef); use MooseX::Types -declare => [qw( myDict myTuple Fullname )]; subtype myDict, as Dict[name=>Str, age=>Int]; subtype Fullname, as Dict[first=>Str, last=>Str]; coerce Fullname, from ArrayRef, via { +{first=>$_->[0], last=>$_->[1]} }; subtype myTuple, as Tuple[Str, Int]; ## Create some coercions. Note the dob_epoch could be a more useful convert ## from a dob datetime object, I'm just lazy. coerce myDict, from Int, via { +{name=>'JohnDoe', age=>$_} }, from Dict[aname=>HashRef, dob_in_years=>Int], via { +{ name=> $_->{aname}->{first} .' '. $_->{aname}->{last}, age=>$_->{dob_in_years}, } }, from Dict[bname=>HashRef, dob_in_years=>Int], via { +{ name=> $_->{bname}->{first} .' '. $_->{bname}->{last}, age=>$_->{dob_in_years}, } }, from Dict[fullname=>Fullname, dob_epoch=>Int], via { +{ name=> $_->{fullname}->{first} .' '. $_->{fullname}->{last}, age=>$_->{dob_epoch}} }, from myTuple, via { +{name=>$_->[0], age=>$_->[1]} }; has 'stuff' => (is=>'rw', isa=>myDict, coerce=>1); } ## Create an object to test ok my $person = Test::MooseX::Meta::TypeConstraint::Structured::Coerce->new(); isa_ok $person, 'Test::MooseX::Meta::TypeConstraint::Structured::Coerce';## Try out the coercions ok $person->stuff({name=>"John",age=>25}), 'Set Stuff {name=>"John",age=>25}'; is_deeply $person->stuff, {name=>"John",age=>25}, 'Correct set'; ok $person->stuff(30), 'Set Stuff 30'; is_deeply $person->stuff, {name=>"JohnDoe",age=>30}, 'Correct set'; ok $person->stuff({aname=>{first=>"frank", last=>"herbert"},dob_in_years=>80}), '{{first=>"frank", last=>"herbert"},80}'; is_deeply $person->stuff, {name=>"frank herbert",age=>80}, 'Correct set'; ok $person->stuff({bname=>{first=>"frankbbb", last=>"herbert"},dob_in_years=>84}), '{{first=>"frankbbb", last=>"herbert"},84}'; is_deeply $person->stuff, {name=>"frankbbb herbert",age=>84}, 'Correct set'; ok $person->stuff(["mary",40]), 'Set Stuff ["mary",40]'; is_deeply $person->stuff, {name=>"mary",age=>40}, 'Correct set'; ok $person->stuff({fullname=>{first=>"frank", last=>"herbert1"},dob_epoch=>85}), '{{first=>"frank", last=>"herbert1"},85}'; is_deeply $person->stuff, {name=>"frank herbert1",age=>85}, 'Correct set'; SKIP: { skip 'deep coercions not yet supported', 2, 1; ok $person->stuff({fullname=>["frank", "herbert2"],dob_epoch=>86}), '{fullname=>["frank", "herbert2"],dob_epoch=>86}'; is_deeply $person->stuff, {name=>"frank herbert2",age=>86}, 'Correct set'; } MooseX-Types-Structured-0.30/t/08-examples.t000644 000767 000024 00000004243 12254674163 021076 0ustar00etherstaff000000 000000 BEGIN { use strict; use warnings; use Test::More; eval "use MooseX::Types::DateTime"; plan $@ ? ( skip_all => "Tests require MooseX::Types::DateTime" ) : ( tests => 10 ); } { ## Normalize a HashRef package Test::MooseX::Meta::TypeConstraint::Structured::Examples::Normalize; use Moose; use DateTime; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::DateTime qw(DateTime); use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef); use MooseX::Types -declare => [qw( Name Age Person FullName )]; ## So that our test works, we'll set Now to 2008. sub Now { return 'DateTime'->new(year=>2008); } subtype FullName, as Dict[last=>Str, first=>Str]; subtype Person, as Dict[name=>Str, age=>Int]; coerce Person, from Dict[first=>Str, last=>Str, years=>Int], via { +{ name => "$_->{first} $_->{last}", age=>$_->{years}, }}, from Dict[fullname=>FullName, dob=>DateTime], via { +{ name => "$_->{fullname}{first} $_->{fullname}{last}", age => ($_->{dob} - Now)->years, }}; has person => (is=>'rw', isa=>Person, coerce=>1); } NORMALIZE: { ok my $normalize = Test::MooseX::Meta::TypeConstraint::Structured::Examples::Normalize->new(); isa_ok $normalize, 'Test::MooseX::Meta::TypeConstraint::Structured::Examples::Normalize'; ok $normalize->person({name=>'John', age=>25}) => 'Set value'; is_deeply $normalize->person, {name=>'John', age=>25} => 'Value is correct'; ok $normalize->person({first=>'John', last=>'Napiorkowski', years=>35}) => 'Set value'; is_deeply $normalize->person, {name=>'John Napiorkowski', age=>35} => 'Value is correct'; ok $normalize->person({years=>36, last=>'Napiorkowski', first=>'John'}) => 'Set value'; is_deeply $normalize->person, {name=>'John Napiorkowski', age=>36} => 'Value is correct'; ok $normalize->person({fullname=>{first=>'Vanessa', last=>'Li'}, dob=>DateTime->new(year=>1974)}) => 'Set value'; is_deeply $normalize->person, {name=>'Vanessa Li', age=>34} => 'Value is correct'; } MooseX-Types-Structured-0.30/t/09-optional.t000755 000767 000024 00000016135 12254674163 021114 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests=>46; use Test::Fatal; use Moose::Util::TypeConstraints; use MooseX::Types::Structured qw(Optional); APITEST: { ok my $Optional = Moose::Util::TypeConstraints::find_or_parse_type_constraint('MooseX::Types::Structured::Optional') => 'Got Optional'; isa_ok $Optional => 'Moose::Meta::TypeConstraint::Parameterizable'; ok my $int = Moose::Util::TypeConstraints::find_or_parse_type_constraint('Int') => 'Got Int'; ok my $arrayref = Moose::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[Int]') => 'Got ArrayRef[Int]'; BASIC: { ok my $Optional_Int = $Optional->parameterize($int), 'Parameterized Int'; ok my $Optional_ArrayRef = $Optional->parameterize($arrayref), 'Parameterized ArrayRef'; ok $Optional_Int->check() => 'Optional is allowed to not exist'; ok !$Optional_Int->check(undef) => 'Optional is NOT allowed to be undef'; ok $Optional_Int->check(199) => 'Correctly validates 199'; ok !$Optional_Int->check("a") => 'Correctly fails "a"'; ok $Optional_ArrayRef->check() => 'Optional is allowed to not exist'; ok !$Optional_ArrayRef->check(undef) => 'Optional is NOT allowed to be undef'; ok $Optional_ArrayRef->check([1,2,3]) => 'Correctly validates [1,2,3]'; ok !$Optional_ArrayRef->check("a") => 'Correctly fails "a"'; ok !$Optional_ArrayRef->check(["a","b"]) => 'Correctly fails ["a","b"]'; } SUBREF: { ok my $Optional_Int = Optional->parameterize($int),'Parameterized Int'; ok my $Optional_ArrayRef = Optional->parameterize($arrayref), 'Parameterized ArrayRef'; ok $Optional_Int->check() => 'Optional is allowed to not exist'; ok !$Optional_Int->check(undef) => 'Optional is NOT allowed to be undef'; ok $Optional_Int->check(199) => 'Correctly validates 199'; ok !$Optional_Int->check("a") => 'Correctly fails "a"'; ok $Optional_ArrayRef->check() => 'Optional is allowed to not exist'; ok !$Optional_ArrayRef->check(undef) => 'Optional is NOT allowed to be undef'; ok $Optional_ArrayRef->check([1,2,3]) => 'Correctly validates [1,2,3]'; ok !$Optional_ArrayRef->check("a") => 'Correctly fails "a"'; ok !$Optional_ArrayRef->check(["a","b"]) => 'Correctly fails ["a","b"]'; } } OBJECTTEST: { package Test::MooseX::Meta::TypeConstraint::Structured::Optional; use Moose; use MooseX::Types::Structured qw(Dict Tuple Optional); use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef Maybe); use MooseX::Types -declare => [qw( MoreThanFive TupleOptional1 TupleOptional2 Gender DictOptional1 Insane )]; subtype MoreThanFive, as Int, where { $_ > 5}; enum Gender, [ qw/male female transgendered/ ]; subtype TupleOptional1() => as Tuple[Int, MoreThanFive, Optional[Str|Object]]; subtype TupleOptional2, as Tuple[Int, MoreThanFive, Optional[HashRef[Int|Object]]]; subtype DictOptional1, as Dict[name=>Str, age=>Int, gender=>Optional[Gender]]; subtype Insane, as Tuple[ Int, Optional[Str|Object], DictOptional1, Optional[ArrayRef[Int]] ]; has 'TupleOptional1Attr' => (is=>'rw', isa=>TupleOptional1); has 'TupleOptional2Attr' => (is=>'rw', isa=>TupleOptional2); has 'DictOptional1Attr' => (is=>'rw', isa=>DictOptional1); has 'InsaneAttr' => (is=>'rw', isa=>Insane); } ok my $obj = Test::MooseX::Meta::TypeConstraint::Structured::Optional->new => 'Instantiated new test class.'; isa_ok $obj => 'Test::MooseX::Meta::TypeConstraint::Structured::Optional' => 'Created correct object type.'; # Test Insane is( exception { $obj->InsaneAttr([1,"hello",{name=>"John",age=>39,gender=>"male"},[1,2,3]]); } => undef, 'Set InsaneAttr attribute without error [1,"hello",{name=>"John",age=>39,gender=>"male"},[1,2,3]]'); is( exception { $obj->InsaneAttr([1,$obj,{name=>"John",age=>39},[1,2,3]]); } => undef, 'Set InsaneAttr attribute without error [1,$obj,{name=>"John",age=>39},[1,2,3]]'); is( exception { $obj->InsaneAttr([1,$obj,{name=>"John",age=>39}]); } => undef, 'Set InsaneAttr attribute without error [1,$obj,{name=>"John",age=>39}]'); like( exception { $obj->InsaneAttr([1,$obj,{name=>"John",age=>39},[qw/a b c/]]); }, qr/Attribute \(InsaneAttr\) does not pass the type constraint/ => q{InsaneAttr correctly fails [1,$obj,{name=>"John",age=>39},[qw/a b c/]]}); like( exception { $obj->InsaneAttr([1,"hello",{name=>"John",age=>39,gender=>undef},[1,2,3]]); }, qr/Attribute \(InsaneAttr\) does not pass the type constraint/ => q{InsaneAttr correctly fails [1,"hello",{name=>"John",age=>39,gender=>undef},[1,2,3]]}); # Test TupleOptional1Attr is( exception { $obj->TupleOptional1Attr([1,10,"hello"]); } => undef, 'Set TupleOptional1Attr attribute without error [1,10,"hello"]'); is( exception { $obj->TupleOptional1Attr([1,10,$obj]); } => undef, 'Set TupleOptional1Attr attribute without error [1,10,$obj]'); is( exception { $obj->TupleOptional1Attr([1,10]); } => undef, 'Set TupleOptional1Attr attribute without error [1,10]'); like( exception { $obj->TupleOptional1Attr([1,10,[1,2,3]]); }, qr/Attribute \(TupleOptional1Attr\) does not pass the type constraint/ => q{TupleOptional1Attr correctly fails [1,10,[1,2,3]]}); like( exception { $obj->TupleOptional1Attr([1,10,undef]); }, qr/Attribute \(TupleOptional1Attr\) does not pass the type constraint/ => q{TupleOptional1Attr correctly fails [1,10,undef]}); # Test TupleOptional2Attr is( exception { $obj->TupleOptional2Attr([1,10,{key1=>1,key2=>$obj}]); } => undef, 'Set TupleOptional2Attr attribute without error [1,10,{key1=>1,key2=>$obj}]'); is( exception { $obj->TupleOptional2Attr([1,10]); } => undef, 'Set TupleOptional2Attr attribute without error [1,10]'); like( exception { $obj->TupleOptional2Attr([1,10,[1,2,3]]); }, qr/Attribute \(TupleOptional2Attr\) does not pass the type constraint/ => q{TupleOptional2Attr correctly fails [1,10,[1,2,3]]}); like( exception { $obj->TupleOptional2Attr([1,10,undef]); }, qr/Attribute \(TupleOptional2Attr\) does not pass the type constraint/ => q{TupleOptional2Attr correctly fails [1,10,undef]}); # Test DictOptional1Attr: Dict[name=>Str, age=>Int, gender=>Optional[Gender]]; is( exception { $obj->DictOptional1Attr({name=>"John",age=>39,gender=>"male"}); } => undef, 'Set DictOptional1Attr attribute without error {name=>"John",age=>39,gender=>"male"}'); is( exception { $obj->DictOptional1Attr({name=>"Vanessa",age=>34}); } => undef, 'Set DictOptional1Attr attribute without error {name=>"Vanessa",age=>34}'); like( exception { $obj->DictOptional1Attr({name=>"John",age=>39,gender=>undef}); }, qr/Attribute \(DictOptional1Attr\) does not pass the type constraint/ => q{TupleOptional2Attr correctly fails {name=>"John",age=>39,gender=>undef}}); like( exception { $obj->DictOptional1Attr({name=>"John",age=>39,gender=>"aaa"}); }, qr/Attribute \(DictOptional1Attr\) does not pass the type constraint/ => q{TupleOptional2Attr correctly fails {name=>"John",age=>39,gender=>"aaa"}}); MooseX-Types-Structured-0.30/t/10-recursion.t000644 000767 000024 00000011776 12254674163 021273 0ustar00etherstaff000000 000000 ## Test case donated by Stevan Little use strict; use warnings; use Test::More tests => 25; use Data::Dumper; BEGIN { package Interpreter; use Moose; use Moose::Util::TypeConstraints; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::Moose qw( Int Str ScalarRef ); use MooseX::Types -declare => [qw( Var Const Pair Op BinOp Lambda App Expr )]; use Data::Dumper 'Dumper'; subtype Var() => as ScalarRef; subtype Const() => as Int | Str; subtype Pair() => as Tuple[ Expr, Expr ]; enum Op() => [ qw[ + - ] ]; subtype BinOp() => as Tuple[ Expr, Op, Expr ]; subtype Lambda() => as Tuple[ Var, Expr ]; subtype App() => as Tuple[ Lambda, Expr ]; subtype Expr() => as Var | Const | Pair | BinOp | Lambda | App; sub match { my ($to_match, @cases) = @_; my $default; if (@cases % 2 != 0) { $default = pop @cases; } while (@cases) { my ($type, $action) = splice @cases, 0, 2; #warn "Got " . Dumper($to_match) . " in " . $type->name; if ($type->check($to_match)) { local $_ = $to_match; return $action->($to_match); } } { local $_ = $to_match; return $default->($to_match) if $default; } } sub run { my ($source, $e) = @_; $e ||= {}; #use Data::Dumper; warn "run(e) => " . Dumper $e; return match $source, Var() => sub { $e->{ ${$_} } }, Const() => sub { $_[0] }, BinOp() => sub { $_->[1] eq '+' ? ( run( $_->[0], $e ) + run( $_->[2], $e ) ) : ( run( $_->[0], $e ) - run( $_->[2], $e ) ) }, Lambda() => sub { $_ }, App() => sub { my ( $p, $body ) = @{ run( $_[0]->[0], $e ) }; $e->{ ${ $p } } = run( $_[0]->[1], $e ); run( $body, $e ); }, Pair() => sub { $_ }, Expr() => sub { run($_, $e) }, sub { confess "[run] Bad Source:" . Dumper $_ }; } sub pprint { my ($source) = @_; return match $source, Var() => sub { 'Var(' . ${$_} . ')' }, Op() => sub { 'Op(' . $_ . ')' }, Const() => sub { 'Const(' . $_ . ')' }, BinOp() => sub { 'BinOp( ' . ( join ' ' => map { pprint($_) } @{$_} ) . ' )' }, Lambda() => sub { "Lambda( " . pprint($_->[0]) . ' ' . pprint($_->[1]) . " )" }, App() => sub { "App( " . pprint($_->[0]) . ' ' . pprint($_->[1]) . " )" }, Pair() => sub { 'Pair(' . pprint($_->[0]) . ' => ' . pprint($_->[1]) . ')' }, Expr() => sub { pprint($_) }, sub { confess "[pprint] Bad Source:" . Dumper $_ }; } } { BEGIN { Interpreter->import(':all') }; ok is_Var(\'x'), q{passes is_Var('x')}; ok is_Const(1), q{passes is_Const(1)}; ok is_Const('Hello World'), q{passes is_Const}; ok is_Pair([ 'Hello', 'World' ]), q{passes is_Pair}; ok is_Pair([ \'Hello', 'World' ]), q{passes is_Pair}; ok is_Pair([ \'Hello', 100 ]), q{passes is_Pair}; ok is_Pair([ \'Hello', [ 1, '+', 1] ]), q{passes is_Pair}; ok is_Op('+'), q{passes is_Op('+')}; ok is_Op('-'), q{passes is_Op('-')}; ok is_BinOp([ 1, '+', 1]), q{passes is_BinOp([ 1, '+', 1])}; ok is_BinOp([ '+', '+', '+' ]), q{passes is_BinOp([ '+', '+', '+' ])}; ok is_BinOp([ 1, '+', [ 1, '+', 1 ]]), q{passes is_BinOp([ 1, '+', 1])}; ok is_Lambda([ \'x', [ \'x', '+', \'x' ]]), q{passes is_Lambda}; ok is_App([ [ \'x', [ \'x', '+', \'x' ]], 10 ]), q{passes is_App}; ok Expr->check([ 11, '+', 12]), '... check is supported'; ok is_Expr(\'x'), q{passes is_Expr(\'x')}; ok is_Expr(10), q{passes is_Expr(10)}; ok is_Expr([ 1, '+', 1]), q{passes is_Expr([ 1, '+', 1])}; ok is_Expr([ 1, '+', [ 1, '+', 1 ]]), q{passes is_Expr([ 1, '+', [ 1, '+', 1 ]])}; my $source = [ [ \'x', [ \'x', '+', \'x' ]], 10 ]; is Interpreter::pprint($source), 'App( Lambda( Var(x) BinOp( Var(x) Op(+) Var(x) ) ) Const(10) )', '... pretty printed correctly'; is Interpreter::run([ 1, '+', 1 ]), 2, '... eval-ed correctly'; is Interpreter::run([ 1, '+', [ 1, '+', 1 ] ]), 3, '... eval-ed correctly'; is_deeply Interpreter::run([ \'x', [ \'x', '+', \'x' ]]), [ \'x', [ \'x', '+', \'x' ]], '... eval-ed correctly'; is Interpreter::run($source), 20, '... eval-ed correctly'; is Interpreter::run( [ [ \'x', [ \'x', '+', \'x' ] ], [ 2, '+', 2 ] ] ), 8, '... eval-ed correctly'; } MooseX-Types-Structured-0.30/t/11-overflow.t000644 000767 000024 00000002517 12254674163 021117 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests=>12; use Moose::Util::TypeConstraints; use MooseX::Types::Structured qw(Dict Tuple slurpy); use MooseX::Types::Moose qw(Int Str ArrayRef HashRef Object); my $array_tailed_tuple = Tuple[ Int, Str, slurpy ArrayRef[Int], ]; is($array_tailed_tuple->name, 'MooseX::Types::Structured::Tuple[Int,Str,slurpy ArrayRef[Int]]'); ok !$array_tailed_tuple->check(['ss',1]), 'correct fail'; ok $array_tailed_tuple->check([1,'ss']), 'correct pass'; ok !$array_tailed_tuple->check({}), 'correct fail'; ok $array_tailed_tuple->check([1,'hello',1,2,3,4]), 'correct pass with tail'; ok !$array_tailed_tuple->check([1,'hello',1,2,'bad',4]), 'correct fail with tail'; my $hash_tailed_dict = Dict[ name=>Str, age=>Int, slurpy HashRef[Int], ]; is($hash_tailed_dict->name, 'MooseX::Types::Structured::Dict[name,Str,age,Int,slurpy HashRef[Int]]'); ok !$hash_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail'; ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass'; ok !$hash_tailed_dict->check([]), 'correct fail'; ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>2}), 'correct pass with tail'; ok !$hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>"aa"}), 'correct fail with tail'; MooseX-Types-Structured-0.30/t/12-error.t000644 000767 000024 00000010365 12254674163 020406 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; use Moose::Util::TypeConstraints; use MooseX::Types::Structured qw(Dict Tuple Optional); use MooseX::Types::Moose qw(Int Str ArrayRef HashRef); # Create some TCs from which errors will be generated my $simple_tuple = subtype 'simple_tuple', as Tuple[Int,Str]; my $simple_dict = subtype 'simple_dict', as Dict[name=>Str,age=>Int]; # Make sure the constraints we made validate as expected ok $simple_tuple->check([1,'hello']), "simple_tuple validates: 1,'hello'"; ok !$simple_tuple->check(['hello',1]), "simple_tuple fails: 'hello',1"; ok $simple_dict->check({name=>'Vanessa',age=>34}), "simple_dict validates: {name=>'Vanessa',age=>34}"; ok !$simple_dict->check({name=>$simple_dict,age=>'hello'}), "simple_dict fails: {name=>Object, age=>String}"; ## Let's check all the expected validation errors for tuple like $simple_tuple->validate({a=>1,b=>2}), qr/Validation failed for 'simple_tuple' with value .*{ a: 1, b: 2 }/, 'Wrong basic type'; like $simple_tuple->validate(['a','b']), qr/failed for 'simple_tuple' with value .*\[ "a", "b" \]/, 'Correctly failed due to "a" not an Int'; like $simple_tuple->validate([1,$simple_tuple]), qr/Validation failed for 'simple_tuple' with value .*\[ 1, MooseX::Meta::TypeConstraint::Structured/, 'Correctly failed due to object not a Str'; like $simple_tuple->validate([1]), qr/Validation failed for 'Str' with value .*NULL/, 'Not enought values'; like $simple_tuple->validate([1,'hello','too many']), qr/More values than Type Constraints!/, 'Too Many values'; ## And the same thing for dicts [name=>Str,age=>Int] like $simple_dict->validate([1,2]), qr/ with value .*\[ 1, 2 \]/, 'Wrong basic type'; like $simple_dict->validate({name=>'John',age=>'foobar'}), qr/failed for 'Int' with value .*foobar/, 'Correctly failed due to age not an Int'; like $simple_dict->validate({name=>$simple_dict,age=>1}), qr/with value .*{ age: 1, name: MooseX:/, 'Correctly failed due to object not a Str'; like $simple_dict->validate({name=>'John'}), qr/failed for 'Int' with value .*NULL/, 'Not enought values'; like $simple_dict->validate({name=>'Vincent', age=>15,extra=>'morethanIneed'}), qr/More values than Type Constraints!/, 'Too Many values'; ## TODO some with Optional (or Maybe) and slurpy my $optional_tuple = subtype 'optional_tuple', as Tuple[Int,Optional[Str]]; my $optional_dict = subtype 'optional_dict', as Dict[name=>Str,age=>Optional[Int]]; like $optional_tuple->validate({a=>1,b=>2}), qr/Validation failed for 'optional_tuple' with value .*{ a: 1, b: 2 }/, 'Wrong basic type'; like $optional_tuple->validate(['baz','b']), qr/failed for 'Int' with value .*baz/, 'Correctly failed due to "baz" not an Int'; like $optional_tuple->validate([1,$simple_tuple]), qr/failed for 'Optional\[Str\]' with value .*MooseX/, 'Correctly failed due to object not a Str'; like $optional_tuple->validate([1,'hello','too many']), qr/More values than Type Constraints!/, 'Too Many values'; like $optional_dict->validate([1,2]), qr/ with value .*\[ 1, 2 \]/, 'Wrong basic type'; like $optional_dict->validate({name=>'John',age=>'quux'}), qr/Validation failed for 'Optional\[Int\]' with value .*quux/, 'Correctly failed due to age not an Int'; like $optional_dict->validate({name=>$simple_dict,age=>1}), qr/with value .*{ age: 1, name: MooseX:/, 'Correctly failed due to object not a Str'; like $optional_dict->validate({name=>'Vincent', age=>15,extra=>'morethanIneed'}), qr/More values than Type Constraints!/, 'Too Many values'; ## Deeper constraints my $deep_tuple = subtype 'deep_tuple', as Tuple[ Int, HashRef, Dict[ name=>Str, age=>Int, ], ]; ok $deep_tuple->check([1,{a=>2},{name=>'Vincent',age=>15}]), 'Good Constraint'; { my $message = $deep_tuple->validate([1,{a=>2},{name=>'Vincent',age=>'Hello'}]); like $message, qr/Validation failed for 'Dict\[name,Str,age,Int\]'/, 'Example deeper error'; } like $simple_tuple->validate(["aaa","bbb"]), qr/'Int' with value .*aaa/, 'correct deeper error'; like $deep_tuple->validate([1,{a=>2},{name=>'Vincent1',age=>'Hello1'}]), qr/'Int' with value .*Hello1/, 'correct deeper error'; ## Success Tests... ok !$deep_tuple->validate([1,{a=>2},{name=>'John',age=>40}]), 'Validates ok'; done_testing(); MooseX-Types-Structured-0.30/t/13-deeper_error.t000644 000767 000024 00000002023 12254674163 021723 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; use Moose::Util::TypeConstraints; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::Moose qw(Int); my $deeper_tc = subtype as Dict[ a => Tuple[ Dict[ a1a => Tuple[Int], a1b => Tuple[Int], ], Dict[ a2a => Tuple[Int], a2b => Tuple[Int], ], ], b => Tuple[ Dict[ b1a => Tuple[Int], b1b => Tuple[Int], ], Dict[ b2a => Tuple[Int], b2b => Tuple[Int], ], ], ]; my $struc_to_validate = { a=>[ { a1a=>[1], a1b=>[2] }, { a2a=>['AA'], a2b=>[4] } ], b=>[ { b1a=>[5], b1b=>['BB'] }, { b2a=>[7], b2b=>[8] } ] }; ok my $message = $deeper_tc->validate($struc_to_validate), 'got error message of some sort'; done_testing(); ## warn $message; MooseX-Types-Structured-0.30/t/bug-incorrect-message.t000644 000767 000024 00000001337 12254674163 023221 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; { package Test::MooseX::Types::Structured::IncorrectMessage; use Moose; use MooseX::Types::Moose qw(Str Int); use MooseX::Types::Structured qw(Tuple Dict); use MooseX::Types -declare => [qw(WrongMessage MyInt)]; subtype MyInt, as Int, message { 'Oh, my Int!' }; subtype WrongMessage, as Dict[name=>Str, age=>MyInt]; has 'person' => ( is => 'rw', required => 1, isa => WrongMessage, ); } my %init_args = ( person => { name => 'a', age => 'v', }, ); SKIP: { skip 'Deeper Error Messges not yet supported', 1,1; ok( Test::MooseX::Types::Structured::IncorrectMessage->new(%init_args), 'Made a class', ); } done_testing; MooseX-Types-Structured-0.30/t/bug-is-subtype.t000644 000767 000024 00000003565 12254674163 021720 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; ## Bug report was that if calling ->is_subtype on crap (not a type, etc) you ## get a not very helpful error message. Fix was to make crap just return ## boolean false to make this like the rest of Moose type constraints. I am ## not convinced this is good, but at least is consistent. # # I also changed ->equals and ->is_a_type_of to be consistent { package moosex::types::structured::bug_is_subtype; use Moose; use MooseX::Types -declare => [qw/ ThingType /]; use MooseX::Types::Moose qw/ Int Str /; use MooseX::Types::Structured qw/ Dict /; subtype ThingType, as Dict [ id => Int, name => Str, ]; has thing => ( is => 'ro', isa => ThingType, ); } ok my $test = moosex::types::structured::bug_is_subtype->new, 'created class'; is( moosex::types::structured::bug_is_subtype::ThingType, 'moosex::types::structured::bug_is_subtype::ThingType', 'correct type', ); use MooseX::Types::Moose 'HashRef'; is( HashRef, 'HashRef', 'correct type', ); ok( moosex::types::structured::bug_is_subtype::ThingType->is_subtype_of(HashRef), 'is a subtype', ); ok( !moosex::types::structured::bug_is_subtype::ThingType ->is_subtype_of(moosex::types::structured::bug_is_subtype::ThingType), 'is not a subtype', ); ok( !moosex::types::structured::bug_is_subtype::ThingType ->is_subtype_of('SomeCrap'), 'is not a subtype', ); sub SomeCrap {} ok( !moosex::types::structured::bug_is_subtype::ThingType ->is_subtype_of(SomeCrap), 'is not a subtype', ); ok( !moosex::types::structured::bug_is_subtype::ThingType ->is_subtype_of(undef), 'is not a subtype', ); ok( !moosex::types::structured::bug_is_subtype::ThingType ->equals(undef), 'is not a subtype', ); ok( !moosex::types::structured::bug_is_subtype::ThingType ->is_a_type_of(undef), 'is not a subtype', ); done_testing; MooseX-Types-Structured-0.30/t/bug-mixed-stringy.t000644 000767 000024 00000001540 12254674163 022406 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; { package Test::MooseX::Types::Structured::StringyBug; use Moose; use MooseX::Types::Moose qw(Str); use MooseX::Types::Structured qw(Tuple Dict); use Moose::Util::TypeConstraints; subtype "TestStringTypes::SubType", as Str, where { 1 }; has 'attr1' => ( is => 'ro', required => 1, isa => Dict[ foo1 => Str, foo2 => "Int", foo3 => "TestStringTypes::SubType", ], ); has 'attr2' => ( is => 'ro', required => 1, isa => Tuple[ Str, "Int", "TestStringTypes::SubType", ], ); } my %init_args = ( attr1 => { foo1 => 'a', foo2 => 2, foo3 => 'c', }, attr2 => ['a', 2, 'c'], ); ok( Test::MooseX::Types::Structured::StringyBug->new(%init_args), 'Made a class with mixed constraint types', ); done_testing; MooseX-Types-Structured-0.30/t/bug-optional.t000644 000767 000024 00000002133 12254674163 021427 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; BEGIN { package MyTypes; use MooseX::Types::Structured qw(Dict Tuple Optional); use MooseX::Types::Moose qw(Object Any); use MooseX::Types -declare => [qw( Signature MyDict MyTuple )]; subtype Signature, as Tuple[Tuple[Object], Dict[optional => Optional[Any], required => Any]]; subtype MyDict, as Dict[optional => Optional[Any], required => Any]; subtype MyTuple, as Tuple[Object, Any, Optional[Any]]; } BEGIN { MyTypes->import(':all'); } ok(!Signature->check([ [bless {}, 'Foo'], {} ])); ok(!MyDict->check({ })); ok(!MyDict->check({ optional => 42 })); ok(!MyDict->check({ optional => 42, unknown => 23 })); ok(!MyDict->check({ required => 42, unknown => 23 })); ok(MyDict->check({ optional => 42, required => 23 })); ok(MyDict->check({ required => 23 })); ok(!MyTuple->check([])); ok(!MyTuple->check([bless({}, 'Foo')])); ok(!MyTuple->check([bless({}, 'Foo'), 'bar', 'baz', 'moo'])); ok(MyTuple->check([bless({}, 'Foo'), 'bar'])); ok(MyTuple->check([bless({}, 'Foo'), 'bar', 'baz'])); done_testing; MooseX-Types-Structured-0.30/t/regressions/000755 000767 000024 00000000000 12254674163 021206 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/t/regressions/01-is_type_of.t000644 000767 000024 00000003203 12254674163 023747 0ustar00etherstaff000000 000000 BEGIN { use strict; use warnings; use Test::More tests=>11; } { package TypeLib; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::Moose qw(Int Str Item); use MooseX::Types -declare => [qw( MyDict1 MyDict2 MyDict4 )]; subtype MyDict1, as Dict[name=>Str, age=>Int]; subtype MyDict2, as Dict[name=>Str, age=>Int]; subtype MyDict4, as Dict[name=>Str, age=>Item]; } BEGIN { TypeLib->import(':all'); } use Moose::Util::TypeConstraints; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::Moose qw(Item Any); ok ( MyDict2->is_a_type_of(MyDict4), 'MyDict2 is_a_type_of MyDict4'); ok ( MyDict1->is_subtype_of(MyDict4), 'MyDict1 is_subtype_of MyDict4'); ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->is_a_type_of( Tuple[Tuple[ Item, Item ], Dict[]] ), "tuple of tuple" ); ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->is_a_type_of( Tuple[Tuple[ Item, Item ], Dict[]] ), "tuple of tuple" ); ok ( (Tuple[Tuple[ class_type('Paper'), class_type('Stone') ], Dict[]])->is_subtype_of( Tuple[Tuple[ Item, Item ], Dict[]] ), "tuple of tuple" ); my $item = subtype as 'Item'; ok ( $item->is_subtype_of('Any'), q[$item is subtype of 'Any']); ok ( Item->is_subtype_of('Any'), q[Item is subtype of 'Any']); ok ( $item->is_subtype_of(Any), q[Item is subtype of Any]); ok ( Item->is_subtype_of(Any), q[Item is subtype of Any]); my $any = subtype as 'Any'; ok ( ! $item->is_subtype_of($any), q[$item is NOT a subtype of $any]); ok ( ! Item->is_subtype_of($any), q[Item is NOT a subtype of $any]); MooseX-Types-Structured-0.30/lib/MooseX/000755 000767 000024 00000000000 12254674163 020360 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/lib/MooseX/Meta/000755 000767 000024 00000000000 12254674163 021246 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/lib/MooseX/Types/000755 000767 000024 00000000000 12254674163 021464 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/lib/MooseX/Types/Structured/000755 000767 000024 00000000000 12254674163 023630 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/lib/MooseX/Types/Structured.pm000644 000767 000024 00000101462 12254674163 024172 0ustar00etherstaff000000 000000 package MooseX::Types::Structured; { $MooseX::Types::Structured::VERSION = '0.30'; } # git description: v0.29-5-g1d33691 BEGIN { $MooseX::Types::Structured::AUTHORITY = 'cpan:JJNAPIORK'; } # ABSTRACT: Structured Type Constraints for Moose use 5.008; use Moose::Util::TypeConstraints 1.06; use MooseX::Meta::TypeConstraint::Structured; use MooseX::Meta::TypeConstraint::Structured::Optional; use MooseX::Types::Structured::OverflowHandler; use MooseX::Types::Structured::MessageStack; use MooseX::Types 0.22 -declare => [qw(Dict Map Tuple Optional)]; use Sub::Exporter 0.982 -setup => [ qw(Dict Map Tuple Optional slurpy) ]; use Devel::PartialDump 0.13; use Scalar::Util qw(blessed); my $Optional = MooseX::Meta::TypeConstraint::Structured::Optional->new( name => 'MooseX::Types::Structured::Optional', package_defined_in => __PACKAGE__, parent => find_type_constraint('Item'), constraint => sub { 1 }, constraint_generator => sub { my ($type_parameter, @args) = @_; my $check = $type_parameter->_compiled_type_constraint(); return sub { my (@args) = @_; ## Does the arg exist? Something exists if it's a 'real' value ## or if it is set to undef. if(exists($args[0])) { ## If it exists, we need to validate it $check->($args[0]); } else { ## But it's is okay if the value doesn't exists return 1; } } } ); my $IsType = sub { my ($obj, $type) = @_; return $obj->can('equals') ? $obj->equals($type) : undef; }; my $CompiledTC = sub { my ($obj) = @_; my $method = '_compiled_type_constraint'; return( $obj->$IsType('Any') ? undef : $obj->can($method) ? $obj->$method : sub { $obj->check(shift) }, ); }; Moose::Util::TypeConstraints::register_type_constraint($Optional); Moose::Util::TypeConstraints::add_parameterizable_type($Optional); Moose::Util::TypeConstraints::get_type_constraint_registry->add_type_constraint( MooseX::Meta::TypeConstraint::Structured->new( name => "MooseX::Types::Structured::Tuple" , parent => find_type_constraint('ArrayRef'), constraint_generator=> sub { ## Get the constraints and values to check my ($self, $type_constraints) = @_; $type_constraints ||= $self->type_constraints; my @type_constraints = defined $type_constraints ? @$type_constraints : (); my $overflow_handler; if($type_constraints[-1] && blessed $type_constraints[-1] && $type_constraints[-1]->isa('MooseX::Types::Structured::OverflowHandler')) { $overflow_handler = pop @type_constraints; } my $length = $#type_constraints; foreach my $idx (0..$length) { unless(blessed $type_constraints[$idx]) { ($type_constraints[$idx] = find_type_constraint($type_constraints[$idx])) || die "$type_constraints[$idx] is not a registered type"; } } my (@checks, @optional, $o_check, $is_compiled); return sub { my ($values, $err) = @_; my @values = defined $values ? @$values : (); ## initialise on first time run unless ($is_compiled) { @checks = map { $_->$CompiledTC } @type_constraints; @optional = map { $_->is_subtype_of($Optional) } @type_constraints; $o_check = $overflow_handler->$CompiledTC if $overflow_handler; $is_compiled++; } ## Perform the checking VALUE: for my $type_index (0 .. $#checks) { my $type_constraint = $checks[ $type_index ]; if(@values) { my $value = shift @values; next VALUE unless $type_constraint; unless($type_constraint->($value)) { if($err) { my $message = $type_constraints[ $type_index ]->validate($value,$err); $err->add_message({message=>$message,level=>$err->level}); } return; } } else { ## Test if the TC supports null values unless ($optional[ $type_index ]) { if($err) { my $message = $type_constraints[ $type_index ]->get_message('NULL',$err); $err->add_message({message=>$message,level=>$err->level}); } return; } } } ## Make sure there are no leftovers. if(@values) { if($overflow_handler) { return $o_check->([@values], $err); } else { if($err) { my $message = "More values than Type Constraints!"; $err->add_message({message=>$message,level=>$err->level}); } return; } } else { return 1; } }; } ) ); Moose::Util::TypeConstraints::get_type_constraint_registry->add_type_constraint( MooseX::Meta::TypeConstraint::Structured->new( name => "MooseX::Types::Structured::Dict", parent => find_type_constraint('HashRef'), constraint_generator => sub { ## Get the constraints and values to check my ($self, $type_constraints) = @_; $type_constraints = $self->type_constraints; my @type_constraints = defined $type_constraints ? @$type_constraints : (); my $overflow_handler; if($type_constraints[-1] && blessed $type_constraints[-1] && $type_constraints[-1]->isa('MooseX::Types::Structured::OverflowHandler')) { $overflow_handler = pop @type_constraints; } my %type_constraints = @type_constraints; foreach my $key (keys %type_constraints) { unless(blessed $type_constraints{$key}) { ($type_constraints{$key} = find_type_constraint($type_constraints{$key})) || die "$type_constraints{$key} is not a registered type"; } } my (%check, %optional, $o_check, $is_compiled); return sub { my ($values, $err) = @_; my %values = defined $values ? %$values: (); unless ($is_compiled) { %check = map { ($_ => $type_constraints{ $_ }->$CompiledTC) } keys %type_constraints; %optional = map { ($_ => $type_constraints{ $_ }->is_subtype_of($Optional)) } keys %type_constraints; $o_check = $overflow_handler->$CompiledTC if $overflow_handler; $is_compiled++; } ## Perform the checking KEY: for my $key (keys %check) { my $type_constraint = $check{ $key }; if(exists $values{$key}) { my $value = $values{$key}; delete $values{$key}; next KEY unless $type_constraint; unless($type_constraint->($value)) { if($err) { my $message = $type_constraints{ $key }->validate($value,$err); $err->add_message({message=>$message,level=>$err->level}); } return; } } else { ## Test to see if the TC supports null values unless ($optional{ $key }) { if($err) { my $message = $type_constraints{ $key }->get_message('NULL',$err); $err->add_message({message=>$message,level=>$err->level}); } return; } } } ## Make sure there are no leftovers. if(%values) { if($overflow_handler) { return $o_check->(+{%values}); } else { if($err) { my $message = "More values than Type Constraints!"; $err->add_message({message=>$message,level=>$err->level}); } return; } } else { return 1; } } }, ) ); Moose::Util::TypeConstraints::get_type_constraint_registry->add_type_constraint( MooseX::Meta::TypeConstraint::Structured->new( name => "MooseX::Types::Structured::Map", parent => find_type_constraint('HashRef'), constraint_generator=> sub { ## Get the constraints and values to check my ($self, $type_constraints) = @_; $type_constraints = $self->type_constraints; my @constraints = defined $type_constraints ? @$type_constraints : (); Carp::confess( "too many args for Map type" ) if @constraints > 2; my ($key_type, $value_type) = @constraints == 2 ? @constraints : @constraints == 1 ? (undef, @constraints) : (); my ($key_check, $value_check, $is_compiled); return sub { my ($values, $err) = @_; my %values = defined $values ? %$values: (); unless ($is_compiled) { ($key_check, $value_check) = map { $_ ? $_->$CompiledTC : undef } $key_type, $value_type; $is_compiled++; } ## Perform the checking if ($value_check) { for my $value (values %$values) { unless ($value_check->($value)) { if($err) { my $message = $value_type->validate($value,$err); $err->add_message({message=>$message,level=>$err->level}); } return; } } } if ($key_check) { for my $key (keys %$values) { unless ($key_check->($key)) { if($err) { my $message = $key_type->validate($key,$err); $err->add_message({message=>$message,level=>$err->level}); } return; } } } return 1; }; }, ) ); sub slurpy ($) { my ($tc) = @_; return MooseX::Types::Structured::OverflowHandler->new( type_constraint => $tc, ); } 1; __END__ =pod =encoding UTF-8 =for :stopwords John Napiorkowski Florian Ragwitz יובל קוג'מן (Yuval Kogman) Tomas (t0m) Doran Robert Sedlacek Ansgar 'phaylon' Stevan Little arcanez Burchardt Dave Rolsky Jesse Luehrs Karen Etheridge Ricardo Signes Subtyping slurpy =head1 NAME MooseX::Types::Structured - Structured Type Constraints for Moose =head1 VERSION version 0.30 =head1 SYNOPSIS The following is example usage for this module. package Person; use Moose; use MooseX::Types::Moose qw(Str Int HashRef); use MooseX::Types::Structured qw(Dict Tuple Optional); ## A name has a first and last part, but middle names are not required has name => ( isa=>Dict[ first => Str, last => Str, middle => Optional[Str], ], ); ## description is a string field followed by a HashRef of tagged data. has description => ( isa=>Tuple[ Str, Optional[HashRef], ], ); ## Remainder of your class attributes and methods Then you can instantiate this class with something like: my $john = Person->new( name => { first => 'John', middle => 'James' last => 'Napiorkowski', }, description => [ 'A cool guy who loves Perl and Moose.', { married_to => 'Vanessa Li', born_in => 'USA', }; ] ); Or with: my $vanessa = Person->new( name => { first => 'Vanessa', last => 'Li' }, description => ['A great student!'], ); But all of these would cause a constraint error for the C attribute: ## Value for 'name' not a HashRef Person->new( name => 'John' ); ## Value for 'name' has incorrect hash key and missing required keys Person->new( name => { first_name => 'John' }); ## Also incorrect keys Person->new( name => { first_name => 'John', age => 39, }); ## key 'middle' incorrect type, should be a Str not a ArrayRef Person->new( name => { first => 'Vanessa', middle => [1,2], last => 'Li', }); And these would cause a constraint error for the C attribute: ## Should be an ArrayRef Person->new( description => 'Hello I am a String' ); ## First element must be a string not a HashRef. Person->new (description => [{ tag1 => 'value1', tag2 => 'value2' }]); Please see the test cases for more examples. =head1 DESCRIPTION A structured type constraint is a standard container L type constraint, such as an C or C, which has been enhanced to allow you to explicitly name all the allowed type constraints inside the structure. The generalized form is: TypeConstraint[@TypeParameters or %TypeParameters] Where C is an array reference or hash references of L objects. This type library enables structured type constraints. It is built on top of the L library system, so you should review the documentation for that if you are not familiar with it. =head2 Comparing Parameterized types to Structured types Parameterized constraints are built into core Moose and you are probably already familiar with the type constraints C and C. Structured types have similar functionality, so their syntax is likewise similar. For example, you could define a parameterized constraint like: subtype ArrayOfInts, as ArrayRef[Int]; which would constrain a value to something like [1,2,3,...] and so on. On the other hand, a structured type constraint explicitly names all it's allowed 'internal' type parameter constraints. For the example: subtype StringFollowedByInt, as Tuple[Str,Int]; would constrain its value to things like C<< ['hello', 111] >> but C<< ['hello', 'world'] >> would fail, as well as C<< ['hello', 111, 'world'] >> and so on. Here's another example: package MyApp::Types; use MooseX::Types -declare [qw(StringIntOptionalHashRef)]; use MooseX::Types::Moose qw(Str Int); use MooseX::Types::Structured qw(Tuple Optional); subtype StringIntOptionalHashRef, as Tuple[ Str, Int, Optional[HashRef] ]; This defines a type constraint that validates values like: ['Hello', 100, {key1 => 'value1', key2 => 'value2'}]; ['World', 200]; Notice that the last type constraint in the structure is optional. This is enabled via the helper C type constraint, which is a variation of the core Moose type constraint C. The main difference is that C type constraints are required to validate if they exist, while C permits undefined values. So the following example would not validate: StringIntOptionalHashRef->validate(['Hello Undefined', 1000, undef]); Please note the subtle difference between undefined and null. If you wish to allow both null and undefined, you should use the core Moose C type constraint instead: package MyApp::Types; use MooseX::Types -declare [qw(StringIntMaybeHashRef)]; use MooseX::Types::Moose qw(Str Int Maybe); use MooseX::Types::Structured qw(Tuple); subtype StringIntMaybeHashRef, as Tuple[ Str, Int, Maybe[HashRef] ]; This would validate the following: ['Hello', 100, {key1 => 'value1', key2 => 'value2'}]; ['World', 200, undef]; ['World', 200]; Structured constraints are not limited to arrays. You can define a structure against a C with the C type constraint as in this example: subtype FirstNameLastName, as Dict[ firstname => Str, lastname => Str, ]; This would constrain a C that validates something like: {firstname => 'Christopher', lastname => 'Parsons'}; but all the following would fail validation: ## Incorrect keys {first => 'Christopher', last => 'Parsons'}; ## Too many keys {firstname => 'Christopher', lastname => 'Parsons', middlename => 'Allen'}; ## Not a HashRef ['Christopher', 'Parsons']; These structures can be as simple or elaborate as you wish. You can even combine various structured, parameterized and simple constraints all together: subtype Crazy, as Tuple[ Int, Dict[name=>Str, age=>Int], ArrayRef[Int] ]; Which would match: [1, {name=>'John', age=>25},[10,11,12]]; Please notice how the type parameters can be visually arranged to your liking and to improve the clarity of your meaning. You don't need to run then altogether onto a single line. Additionally, since the C type constraint defines a hash constraint, the key order is not meaningful. For example: subtype AnyKeyOrder, as Dict[ key1=>Int, key2=>Str, key3=>Int, ]; Would validate both: {key1 => 1, key2 => "Hi!", key3 => 2}; {key2 => "Hi!", key1 => 100, key3 => 300}; As you would expect, since underneath it's just a plain old Perl hash at work. =head2 Alternatives You should exercise some care as to whether or not your complex structured constraints would be better off contained by a real object as in the following example: package MyApp::MyStruct; use Moose; ## lazy way to make a bunch of attributes has $_ for qw(full_name age_in_years); package MyApp::MyClass; use Moose; has person => (isa => 'MyApp::MyStruct'); my $instance = MyApp::MyClass->new( person=>MyApp::MyStruct->new( full_name => 'John', age_in_years => 39, ), ); This method may take some additional time to set up but will give you more flexibility. However, structured constraints are highly compatible with this method, granting some interesting possibilities for coercion. Try: package MyApp::MyClass; use Moose; use MyApp::MyStruct; ## It's recommended your type declarations live in a separate class in order ## to promote reusability and clarity. Inlined here for brevity. use MooseX::Types::DateTime qw(DateTime); use MooseX::Types -declare [qw(MyStruct)]; use MooseX::Types::Moose qw(Str Int); use MooseX::Types::Structured qw(Dict); ## Use class_type to create an ISA type constraint if your object doesn't ## inherit from Moose::Object. class_type 'MyApp::MyStruct'; ## Just a shorter version really. subtype MyStruct, as 'MyApp::MyStruct'; ## Add the coercions. coerce MyStruct, from Dict[ full_name=>Str, age_in_years=>Int ], via { MyApp::MyStruct->new(%$_); }, from Dict[ lastname=>Str, firstname=>Str, dob=>DateTime ], via { my $name = $_->{firstname} .' '. $_->{lastname}; my $age = DateTime->now - $_->{dob}; MyApp::MyStruct->new( full_name=>$name, age_in_years=>$age->years, ); }; has person => (isa=>MyStruct); This would allow you to instantiate with something like: my $obj = MyApp::MyClass->new( person => { full_name=>'John Napiorkowski', age_in_years=>39, }); Or even: my $obj = MyApp::MyClass->new( person => { lastname=>'John', firstname=>'Napiorkowski', dob=>DateTime->new(year=>1969), }); If you are not familiar with how coercions work, check out the L cookbook entry L for an explanation. The section L has additional examples and discussion. =head2 Subtyping a Structured type constraint You need to exercise some care when you try to subtype a structured type as in this example: subtype Person, as Dict[name => Str]; subtype FriendlyPerson, as Person[ name => Str, total_friends => Int, ]; This will actually work BUT you have to take care that the subtype has a structure that does not contradict the structure of it's parent. For now the above works, but I will clarify the syntax for this at a future point, so it's recommended to avoid (should not really be needed so much anyway). For now this is supported in an EXPERIMENTAL way. Your thoughts, test cases and patches are welcomed for discussion. If you find a good use for this, please let me know. =head2 Coercions Coercions currently work for 'one level' deep. That is you can do: subtype Person, as Dict[ name => Str, age => Int ]; subtype Fullname, as Dict[ first => Str, last => Str ]; coerce Person, ## Coerce an object of a particular class from BlessedPersonObject, via { +{ name=>$_->name, age=>$_->age, }; }, ## Coerce from [$name, $age] from ArrayRef, via { +{ name=>$_->[0], age=>$_->[1], }, }, ## Coerce from {fullname=>{first=>...,last=>...}, dob=>$DateTimeObject} from Dict[fullname=>Fullname, dob=>DateTime], via { my $age = $_->dob - DateTime->now; my $firstn = $_->{fullname}->{first}; my $lastn = $_->{fullname}->{last} +{ name => $_->{fullname}->{first} .' '. , age =>$age->years } }; And that should just work as expected. However, if there are any 'inner' coercions, such as a coercion on C or on C, that coercion won't currently get activated. Please see the test F<07-coerce.t> for a more detailed example. Discussion on extending coercions to support this welcome on the Moose development channel or mailing list. =head2 Recursion Newer versions of L support recursive type constraints. That is you can include a type constraint as a contained type constraint of itself. For example: subtype Person, as Dict[ name=>Str, friends=>Optional[ ArrayRef[Person] ], ]; This would declare a C subtype that contains a name and an optional C of Cs who are friends as in: { name => 'Mike', friends => [ { name => 'John' }, { name => 'Vincent' }, { name => 'Tracey', friends => [ { name => 'Stephenie' }, { name => 'Ilya' }, ], }, ], }; Please take care to make sure the recursion node is either C, or declare a union with an non-recursive option such as: subtype Value as Tuple[ Str, Str|Tuple, ]; Which validates: [ 'Hello', [ 'World', [ 'Is', [ 'Getting', 'Old', ], ], ], ]; Otherwise you will define a subtype that is impossible to validate since it is infinitely recursive. For more information about defining recursive types, please see the documentation in L and the test cases. =head1 TYPE CONSTRAINTS This type library defines the following constraints. =head2 Tuple[@constraints] This defines an ArrayRef based constraint which allows you to validate a specific list of contained constraints. For example: Tuple[Int,Str]; ## Validates [1,'hello'] Tuple[Str|Object, Int]; ## Validates ['hello', 1] or [$object, 2] The Values of @constraints should ideally be L declared type constraints. We do support 'old style' L string based constraints to a limited degree but these string type constraints are considered deprecated. There will be limited support for bugs resulting from mixing string and L in your structures. If you encounter such a bug and really need it fixed, we will required a detailed test case at the minimum. =head2 Dict[%constraints] This defines a HashRef based constraint which allowed you to validate a specific hashref. For example: Dict[name=>Str, age=>Int]; ## Validates {name=>'John', age=>39} The keys in C<%constraints> follow the same rules as C<@constraints> in the above section. =head2 Map[ $key_constraint, $value_constraint ] This defines a C-based constraint in which both the keys and values are required to meet certain constraints. For example, to map hostnames to IP addresses, you might say: Map[ HostName, IPAddress ] The type constraint would only be met if every key was a valid C and every value was a valid C. =head2 Optional[$constraint] This is primarily a helper constraint for C and C type constraints. What this allows is for you to assert that a given type constraint is allowed to be null (but NOT undefined). If the value is null, then the type constraint passes but if the value is defined it must validate against the type constraint. This makes it easy to make a Dict where one or more of the keys doesn't have to exist or a tuple where some of the values are not required. For example: subtype Name() => as Dict[ first=>Str, last=>Str, middle=>Optional[Str], ]; ...creates a constraint that validates against a hashref with the keys 'first' and 'last' being strings and required while an optional key 'middle' is must be a string if it appears but doesn't have to appear. So in this case both the following are valid: {first=>'John', middle=>'James', last=>'Napiorkowski'} {first=>'Vanessa', last=>'Li'} If you use the C type constraint instead, your values will also validate against C, which may be incorrect for you. =head1 EXPORTABLE SUBROUTINES This type library makes available for export the following subroutines =head2 slurpy Structured type constraints by their nature are closed; that is validation will depend on an exact match between your structure definition and the arguments to be checked. Sometimes you might wish for a slightly looser amount of validation. For example, you may wish to validate the first 3 elements of an array reference and allow for an arbitrary number of additional elements. At first thought you might think you could do it this way: # I want to validate stuff like: [1,"hello", $obj, 2,3,4,5,6,...] subtype AllowTailingArgs, as Tuple[ Int, Str, Object, ArrayRef[Int], ]; However what this will actually validate are structures like this: [10,"Hello", $obj, [11,12,13,...] ]; # Notice element 4 is an ArrayRef In order to allow structured validation of, "and then some", arguments, you can use the L method against a type constraint. For example: use MooseX::Types::Structured qw(Tuple slurpy); subtype AllowTailingArgs, as Tuple[ Int, Str, Object, slurpy ArrayRef[Int], ]; This will now work as expected, validating ArrayRef structures such as: [1,"hello", $obj, 2,3,4,5,6,...] A few caveats apply. First, the slurpy type constraint must be the last one in the list of type constraint parameters. Second, the parent type of the slurpy type constraint must match that of the containing type constraint. That means that a C can allow a slurpy C (or children of Cs, including another C) and a C can allow a slurpy C (or children/subtypes of HashRef, also including other C constraints). Please note the technical way this works 'under the hood' is that the slurpy keyword transforms the target type constraint into a coderef. Please do not try to create your own custom coderefs; always use the slurpy method. The underlying technology may change in the future but the slurpy keyword will be supported. =head1 ERROR MESSAGES Error reporting has been improved to return more useful debugging messages. Now I will stringify the incoming check value with L so that you can see the actual structure that is tripping up validation. Also, I report the 'internal' validation error, so that if a particular element inside the Structured Type is failing validation, you will see that. There's a limit to how deep this internal reporting goes, but you shouldn't see any of the "failed with ARRAY(XXXXXX)" that we got with earlier versions of this module. This support is continuing to expand, so it's best to use these messages for debugging purposes and not for creating messages that 'escape into the wild' such as error messages sent to the user. Please see the test '12-error.t' for a more lengthy example. Your thoughts and preferable tests or code patches very welcome! =head1 EXAMPLES Here are some additional example usage for structured types. All examples can be found also in the 't/examples.t' test. Your contributions are also welcomed. =head2 Normalize a HashRef You need a hashref to conform to a canonical structure but are required accept a bunch of different incoming structures. You can normalize using the C type constraint and coercions. This example also shows structured types mixed which other L libraries. package Test::MooseX::Meta::TypeConstraint::Structured::Examples::Normalize; use Moose; use DateTime; use MooseX::Types::Structured qw(Dict Tuple); use MooseX::Types::DateTime qw(DateTime); use MooseX::Types::Moose qw(Int Str Object); use MooseX::Types -declare => [qw(Name Age Person)]; subtype Person, as Dict[ name=>Str, age=>Int, ]; coerce Person, from Dict[ first=>Str, last=>Str, years=>Int, ], via { +{ name => "$_->{first} $_->{last}", age => $_->{years}, }}, from Dict[ fullname=>Dict[ last=>Str, first=>Str, ], dob=>DateTime, ], ## DateTime needs to be inside of single quotes here to disambiguate the ## class package from the DataTime type constraint imported via the ## line "use MooseX::Types::DateTime qw(DateTime);" via { +{ name => "$_->{fullname}{first} $_->{fullname}{last}", age => ($_->{dob} - 'DateTime'->now)->years, }}; has person => (is=>'rw', isa=>Person, coerce=>1); And now you can instantiate with all the following: __PACKAGE__->new( person=>{ name=>'John Napiorkowski', age=>39, }, ); __PACKAGE__->new( person=>{ first=>'John', last=>'Napiorkowski', years=>39, }, ); __PACKAGE__->new( person=>{ fullname => { first=>'John', last=>'Napiorkowski' }, dob => 'DateTime'->new( year=>1969, month=>2, day=>13 ), }, ); This technique is a way to support various ways to instantiate your class in a clean and declarative way. =head1 SEE ALSO The following modules or resources may be of interest. L, L, L, L =head1 AUTHORS =over 4 =item * John Napiorkowski =item * Florian Ragwitz =item * יובל קוג'מן (Yuval Kogman) =item * Tomas (t0m) Doran =item * Robert Sedlacek =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2008 by John Napiorkowski. 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 CONTRIBUTORS =over 4 =item * Ansgar Burchardt =item * Dave Rolsky =item * Jesse Luehrs =item * Karen Etheridge =item * Ricardo Signes =item * Robert 'phaylon' Sedlacek =item * Stevan Little =item * arcanez =back =cut MooseX-Types-Structured-0.30/lib/MooseX/Types/Structured/MessageStack.pm000644 000767 000024 00000001456 12254674163 026546 0ustar00etherstaff000000 000000 package ## Hide from PAUSE MooseX::Types::Structured::MessageStack; use Moose; has 'level' => ( traits => ['Counter'], is => 'ro', isa => 'Num', required => 0, default => 0, handles => { inc_level => 'inc', dec_level => 'dec', }, ); has 'messages' => ( traits => ['Array'], is => 'ro', isa => 'ArrayRef[HashRef]', required => 1, default => sub { [] }, handles => { has_messages => 'count', add_message => 'push', all_messages => 'elements', }, ); sub as_string { my @messages = (shift)->all_messages; my @flattened_msgs = map { "\n". (" " x $_->{level}) ."[+] " . $_->{message}; } reverse @messages; return join("", @flattened_msgs); } no Moose; __PACKAGE__->meta->make_immutable; 1; MooseX-Types-Structured-0.30/lib/MooseX/Types/Structured/OverflowHandler.pm000644 000767 000024 00000000636 12254674163 027274 0ustar00etherstaff000000 000000 package ## Hide from PAUSE MooseX::Types::Structured::OverflowHandler; use Moose; use overload '""' => 'name', fallback => 1; has type_constraint => ( is => 'ro', isa => 'Moose::Meta::TypeConstraint', required => 1, handles => [qw/check/], ); sub name { my ($self) = @_; return 'slurpy ' . $self->type_constraint->name; } no Moose; __PACKAGE__->meta->make_immutable; 1; MooseX-Types-Structured-0.30/lib/MooseX/Meta/TypeCoercion/000755 000767 000024 00000000000 12254674163 023651 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/lib/MooseX/Meta/TypeConstraint/000755 000767 000024 00000000000 12254674163 024234 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/lib/MooseX/Meta/TypeConstraint/Structured/000755 000767 000024 00000000000 12254674163 026400 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/lib/MooseX/Meta/TypeConstraint/Structured.pm000644 000767 000024 00000024343 12254674163 026744 0ustar00etherstaff000000 000000 package ## Hide from PAUSE MooseX::Meta::TypeConstraint::Structured; # ABSTRACT: Structured type constraints. use Moose; use Devel::PartialDump; use Moose::Util::TypeConstraints (); use MooseX::Meta::TypeCoercion::Structured; extends 'Moose::Meta::TypeConstraint'; has 'type_constraints' => ( is=>'ro', isa=>'Ref', predicate=>'has_type_constraints', ); has 'constraint_generator' => ( is=>'ro', isa=>'CodeRef', predicate=>'has_constraint_generator', ); has coercion => ( is => 'ro', isa => 'Object', builder => '_build_coercion', ); sub _build_coercion { my ($self) = @_; return MooseX::Meta::TypeCoercion::Structured->new( type_constraint => $self, ); } sub _clean_message { my $message = shift @_; $message =~s/MooseX::Types::Structured:://g; return $message; } override 'validate' => sub { my ($self, $value, $message_stack) = @_; unless ($message_stack) { $message_stack = MooseX::Types::Structured::MessageStack->new(); } $message_stack->inc_level; if ($self->_compiled_type_constraint->($value, $message_stack)) { ## Everything is good, no error message to return return undef; } else { ## Whoops, need to figure out the right error message my $args = Devel::PartialDump::dump($value); $message_stack->dec_level; if($message_stack->has_messages) { if($message_stack->level) { ## we are inside a deeply structured constraint return $self->get_message($args); } else { my $message_str = $message_stack->as_string; return _clean_message($self->get_message("$args, Internal Validation Error is: $message_str")); } } else { return $self->get_message($args); } } }; sub generate_constraint_for { my ($self, $type_constraints) = @_; return $self->constraint_generator->($self, $type_constraints); } sub parameterize { my ($self, @type_constraints) = @_; my $class = ref $self; my $name = $self->name .'['. join(',', map {"$_"} @type_constraints) .']'; my $constraint_generator = $self->__infer_constraint_generator; return $class->new( name => $name, parent => $self, type_constraints => \@type_constraints, constraint_generator => $constraint_generator, ); } sub __infer_constraint_generator { my ($self) = @_; if($self->has_constraint_generator) { return $self->constraint_generator; } else { return sub { ## I'm not sure about this stuff but everything seems to work my $tc = shift @_; my $merged_tc = [@$tc, @{$self->parent->type_constraints}]; $self->constraint->($merged_tc, @_); }; } } around 'compile_type_constraint' => sub { my ($compile_type_constraint, $self, @args) = @_; if($self->has_type_constraints) { my $type_constraints = $self->type_constraints; my $constraint = $self->generate_constraint_for($type_constraints); $self->_set_constraint($constraint); } return $self->$compile_type_constraint(@args); }; around 'create_child_type' => sub { my ($create_child_type, $self, %opts) = @_; return $self->$create_child_type( %opts, constraint_generator => $self->__infer_constraint_generator, ); }; sub equals { my ( $self, $type_or_name ) = @_; my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; return unless $other->isa(__PACKAGE__); return ( $self->parent->equals($other->parent) and $self->type_constraints_equals($other) ); } sub is_a_type_of { my ( $self, $type_or_name ) = @_; my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; if ( $other->isa(__PACKAGE__) and @{ $other->type_constraints || [] }) { if ( $self->parent->is_a_type_of($other->parent) ) { return $self->_type_constraints_op_all($other, "is_a_type_of"); } elsif ( $self->parent->is_a_type_of($other) ) { return 1; # FIXME compare? } else { return 0; } } else { return $self->SUPER::is_a_type_of($other); } } sub is_subtype_of { my ( $self, $type_or_name ) = @_; my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name) or return; if ( $other->isa(__PACKAGE__) ) { if ( $other->type_constraints and $self->type_constraints ) { if ( $self->parent->is_a_type_of($other->parent) ) { return ( $self->_type_constraints_op_all($other, "is_a_type_of") and $self->_type_constraints_op_any($other, "is_subtype_of") ); } elsif ( $self->parent->is_a_type_of($other) ) { return 1; # FIXME compare? } else { return 0; } } else { if ( $self->type_constraints ) { if ( $self->SUPER::is_subtype_of($other) ) { return 1; } else { return; } } else { return $self->parent->is_subtype_of($other->parent); } } } else { return $self->SUPER::is_subtype_of($other); } } sub type_constraints_equals { my ( $self, $other ) = @_; $self->_type_constraints_op_all($other, "equals"); } sub _type_constraints_op_all { my ($self, $other, $op) = @_; return unless $other->isa(__PACKAGE__); my @self_type_constraints = @{$self->type_constraints||[]}; my @other_type_constraints = @{$other->type_constraints||[]}; return unless @self_type_constraints == @other_type_constraints; ## Incoming ay be either arrayref or hashref, need top compare both while(@self_type_constraints) { my $self_type_constraint = shift @self_type_constraints; my $other_type_constraint = shift @other_type_constraints; $_ = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($_) for $self_type_constraint, $other_type_constraint; my $result = $self_type_constraint->$op($other_type_constraint); return unless $result; } return 1; ##If we get this far, everything is good. } sub _type_constraints_op_any { my ($self, $other, $op) = @_; return unless $other->isa(__PACKAGE__); my @self_type_constraints = @{$self->type_constraints||[]}; my @other_type_constraints = @{$other->type_constraints||[]}; return unless @self_type_constraints == @other_type_constraints; ## Incoming ay be either arrayref or hashref, need top compare both while(@self_type_constraints) { my $self_type_constraint = shift @self_type_constraints; my $other_type_constraint = shift @other_type_constraints; $_ = Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($_) for $self_type_constraint, $other_type_constraint; return 1 if $self_type_constraint->$op($other_type_constraint); } return 0; } around 'get_message' => sub { my ($get_message, $self, $value) = @_; $value = Devel::PartialDump::dump($value) if ref $value; return $self->$get_message($value); }; __PACKAGE__->meta->make_immutable(inline_constructor => 0); __END__ =pod =encoding UTF-8 =for :stopwords John Napiorkowski Florian Ragwitz יובל קוג'מן (Yuval Kogman) Tomas (t0m) Doran Robert Sedlacek subref parameterize servicable =head1 NAME MooseX::Meta::TypeConstraint::Structured - Structured type constraints. =head1 VERSION version 0.30 =head1 DESCRIPTION A structure is a set of L that are 'aggregated' in such a way as that they are all applied to an incoming list of arguments. The idea here is that a Type Constraint could be something like, "An C followed by an C and then a C" and that this could be done so with a declaration like: Tuple[Int,Int,Str]; ## Example syntax So a structure is a list of type constraints (the C in the above example) which are intended to function together. =head1 ATTRIBUTES =head2 type_constraints A list of L objects. =head2 constraint_generator =head1 METHODS =head2 validate Messing with validate so that we can support nicer error messages. =head2 generate_constraint_for ($type_constraints) Given some type constraints, use them to generate validation rules for an ref of values (to be passed at check time) =head2 parameterize (@type_constraints) Given a ref of type constraints, create a structured type. =head2 __infer_constraint_generator =head2 compile_type_constraint hook into compile_type_constraint so we can set the correct validation rules. =head2 create_child_type modifier to make sure we get the constraint_generator =head2 is_a_type_of =head2 is_subtype_of =head2 equals Override the base class behavior. =head2 type_constraints_equals Checks to see if the internal type constraints are equal. =head2 get_message Give you a better peek into what's causing the error. For now we stringify the incoming deep value with L and pass that on to either your custom error message or the default one. In the future we'll try to provide a more complete stack trace of the actual offending elements A subref or closure that contains the way we validate incoming values against a set of type constraints. This returns a CODEREF which generates a suitable constraint generator. Not user servicable, you'll never call this directly. =head1 SEE ALSO The following modules or resources may be of interest. L, L =head1 AUTHORS =over 4 =item * John Napiorkowski =item * Florian Ragwitz =item * יובל קוג'מן (Yuval Kogman) =item * Tomas (t0m) Doran =item * Robert Sedlacek =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2008 by John Napiorkowski. 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 MooseX-Types-Structured-0.30/lib/MooseX/Meta/TypeConstraint/Structured/Optional.pm000644 000767 000024 00000000762 12254674163 030530 0ustar00etherstaff000000 000000 package ## Hide from PAUSE MooseX::Meta::TypeConstraint::Structured::Optional; use Moose; use MooseX::Meta::TypeCoercion::Structured::Optional; extends 'Moose::Meta::TypeConstraint::Parameterizable'; around parameterize => sub { my $orig = shift; my $self = shift; my $ret = $self->$orig(@_); $ret->coercion(MooseX::Meta::TypeCoercion::Structured::Optional->new(type_constraint => $ret)); return $ret; }; __PACKAGE__->meta->make_immutable(inline_constructor => 0); 1; MooseX-Types-Structured-0.30/lib/MooseX/Meta/TypeCoercion/Structured/000755 000767 000024 00000000000 12254674163 026015 5ustar00etherstaff000000 000000 MooseX-Types-Structured-0.30/lib/MooseX/Meta/TypeCoercion/Structured.pm000644 000767 000024 00000002545 12254674163 026361 0ustar00etherstaff000000 000000 package ## Hide from PAUSE MooseX::Meta::TypeCoercion::Structured; # ABSTRACT: Coerce structured type constraints use Moose; extends 'Moose::Meta::TypeCoercion'; # We need to make sure we can properly coerce the structure elements inside a # structured type constraint. However requirements for the best way to allow # this are still in flux. For now this class is a placeholder. # see also Moose::Meta::TypeCoercion. __PACKAGE__->meta->make_immutable(inline_constructor => 0); __END__ =pod =encoding UTF-8 =for :stopwords John Napiorkowski Florian Ragwitz יובל קוג'מן (Yuval Kogman) Tomas (t0m) Doran Robert Sedlacek Ansgar 'phaylon' Stevan Little arcanez Burchardt Dave Rolsky Jesse Luehrs Karen Etheridge Ricardo Signes =head1 NAME MooseX::Meta::TypeCoercion::Structured - Coerce structured type constraints =head1 VERSION version 0.30 =head1 AUTHORS =over 4 =item * John Napiorkowski =item * Florian Ragwitz =item * יובל קוג'מן (Yuval Kogman) =item * Tomas (t0m) Doran =item * Robert Sedlacek =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2008 by John Napiorkowski. 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 MooseX-Types-Structured-0.30/lib/MooseX/Meta/TypeCoercion/Structured/Optional.pm000644 000767 000024 00000001152 12254674163 030137 0ustar00etherstaff000000 000000 package ## Hide from PAUSE MooseX::Meta::TypeCoercion::Structured::Optional; use Moose; extends 'Moose::Meta::TypeCoercion'; sub compile_type_coercion { my ($self) = @_; my $constraint = $self->type_constraint->type_parameter; $self->_compiled_type_coercion(sub { my ($value) = @_; return unless $constraint->has_coercion; return $constraint->coerce($value); }); } sub has_coercion_for_type { 0 } sub add_type_coercions { Moose->throw_error("Cannot add additional type coercions to Optional types"); } __PACKAGE__->meta->make_immutable(inline_constructor => 0); 1;