COPYRIGHT000644001750001750 304213434770141 13251 0ustar00taitai000000000000Type-Tie-0.014Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: Type-Tie Upstream-Contact: Toby Inkster (TOBYINK) Source: https://metacpan.org/release/Type-Tie Files: README lib/Type/Tie.pm t/01basic.t t/02moosextypes.t t/04nots.t t/05typetiny.t Copyright: This software is copyright (c) 2013-2014, 2018-2019 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: INSTALL LICENSE Makefile.PL inc/Test/Fatal.pm inc/Test/Requires.pm inc/Try/Tiny.pm Copyright: Unknown License: Unknown Files: Changes META.json META.yml doap.ttl Copyright: Copyright 2019 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: COPYRIGHT CREDITS SIGNATURE Copyright: None License: public-domain Files: dist.ini Copyright: Copyright 2013 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/06tn-moo.t Copyright: This software is copyright (c) 2019 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: lib/Type/Nano.pm Copyright: This software is copyright (c) 2018-2019 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/03prototypicalweirdness.t Copyright: This software is copyright (c) 2014, 2018-2019 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 License: Artistic-1.0 This software is Copyright (c) 2019 by the copyright holder(s). This is free software, licensed under: The Artistic License 1.0 License: GPL-1.0 This software is Copyright (c) 2019 by the copyright holder(s). This is free software, licensed under: The GNU General Public License, Version 1, February 1989 CREDITS000644001750001750 15113434770140 12753 0ustar00taitai000000000000Type-Tie-0.014Maintainer: - Toby Inkster (TOBYINK) Thanks: - Graham Knop (HAARG) Changes000644001750001750 436513434770140 13261 0ustar00taitai000000000000Type-Tie-0.014Type-Tie ======== Created: 2013-05-05 Home page: Bug tracker: Maintainer: Toby Inkster (TOBYINK) 0.014 2019-02-25 [ Bug Fixes ] - Make Type::Nano overloading work on Perl 5.8. 0.013 2019-01-06 [ Documentation ] - Clarify rationale and use of Type::Nano. 0.012 2019-01-02 [ Test Suite ] - Check that Type::Nano type constraints work with Moo. 0.011 2018-06-26 [ Documentation ] - Improvements to Type::Nano documentation. [ Other ] - Added: Type::Nano does overloading. 0.010 2018-06-26 [ Packaging ] - Bundle Type::Nano for testing. - Bundle copies of Test::Requires, Try::Tiny, and Test::Fatal in inc. 0.009 2014-09-17 [ Packaging ] - Repackage with newer version of Dist::Inkt to fix META.json error. 0.008 2014-07-14 [ Test Suite ] - Include a test case with a simple local implementation of Type::API. [ Packaging ] - Types::Standard and MooseX::Types::Moose are now just listed as 'suggested' for testing. (They were 'required' and 'recommended' respectively.) [ Other ] - Type::Tie now passes through the type constraint's error message rather than generating its own. It will still generate its own error message if the type constraint object fails to provide a get_message method. 0.007 2014-02-17 [ Bug Fixes ] - Change ttie prototype from ([\$@%]$;@) to ([\$@%]@). Graham Knop++ [ Packaging ] - Include my TODO list. 0.006 2013-10-04 - Make Hash::FieldHash optional for Perl >= v5.9.4; use Hash::Util::FieldHash if Hash::FieldHash is unavailable. 0.005 2013-09-30 - Stop using base.pm. - Updated: Use Exporter::Tiny instead of Exporter::TypeTiny. 0.004 2013-09-06 [ Bug Fixes ] - Fix weird bug in Perl < 5.14. [ Test Suite ] - Add a test case for using Type::Tie with MooseX::Types::Moose. [ Other ] - Rename the undocumented `store_value` method to `coerce_and_check_value`. - Use compiled checks and coercions when possible. 0.003 2013-09-04 [ Bug Fixes ] - Implement SPLICE as part of the tied array interface. [ Packaging ] - Convert to Dist::Inkt. - Fix link to source code repository. 0.002 2013-06-22 - Support Type::API. 0.001 2013-05-05 Initial release INSTALL000644001750001750 164613434770140 13016 0ustar00taitai000000000000Type-Tie-0.014 Installing Type-Tie should be straightforward. INSTALLATION WITH CPANMINUS If you have cpanm, you only need one line: % cpanm Type::Tie 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 Type::Tie INSTALLATION WITH THE CPAN SHELL Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Type::Tie MANUAL INSTALLATION As a last resort, you can manually install it. Download the tarball and unpack it. Consult the file META.json for a list of pre-requisites. Install these first. To build Type-Tie: % perl Makefile.PL % make && make test Then install it: % make install If you are installing into a system-wide directory, you may need to run: % sudo make install LICENSE000644001750001750 4365513434770140 13020 0ustar00taitai000000000000Type-Tie-0.014This software is copyright (c) 2019 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2019 by Toby Inkster. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2019 by Toby Inkster. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End MANIFEST000644001750001750 45613434770141 13075 0ustar00taitai000000000000Type-Tie-0.014COPYRIGHT CREDITS Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README SIGNATURE dist.ini doap.ttl inc/Test/Fatal.pm inc/Test/Requires.pm inc/Try/Tiny.pm lib/Type/Nano.pm lib/Type/Tie.pm t/01basic.t t/02moosextypes.t t/03prototypicalweirdness.t t/04nots.t t/05typetiny.t t/06tn-moo.t META.json000644001750001750 502313434770141 13400 0ustar00taitai000000000000Type-Tie-0.014{ "abstract" : "tie a variable to a type constraint", "author" : [ "Toby Inkster (TOBYINK) " ], "dynamic_config" : 1, "generated_by" : "Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150010", "keywords" : [], "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Type-Tie", "no_index" : { "directory" : [ "eg", "examples", "inc", "t", "xt" ] }, "optional_features" : {}, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17" } }, "runtime" : { "recommends" : { "Hash::FieldHash" : "0" }, "requires" : { "Exporter::Tiny" : "0.026", "perl" : "5.008005" }, "suggests" : { "Types::Standard" : "0.004" } }, "test" : { "requires" : { "Test::More" : "0.96" }, "suggests" : { "MooseX::Types::Moose" : "0", "Test::Fatal" : "0", "Test::Requires" : "0", "Types::Standard" : "0.004" } } }, "provides" : { "Type::Nano" : { "file" : "lib/Type/Nano.pm", "version" : "0.014" }, "Type::Tie" : { "file" : "lib/Type/Tie.pm", "version" : "0.014" }, "Type::Tie::ARRAY" : { "file" : "lib/Type/Tie.pm", "version" : "0.014" }, "Type::Tie::BASE" : { "file" : "lib/Type/Tie.pm", "version" : "0.014" }, "Type::Tie::HASH" : { "file" : "lib/Type/Tie.pm", "version" : "0.014" }, "Type::Tie::SCALAR" : { "file" : "lib/Type/Tie.pm", "version" : "0.014" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "http://rt.cpan.org/Dist/Display.html?Queue=Type-Tie" }, "homepage" : "https://metacpan.org/release/Type-Tie", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/tobyink/p5-type-tie.git", "web" : "https://github.com/tobyink/p5-type-tie" }, "x_identifier" : "http://purl.org/NET/cpan-uri/dist/Type-Tie/project" }, "version" : "0.014", "x_serialization_backend" : "JSON::PP version 2.27400_02" } META.yml000644001750001750 256113434770141 13234 0ustar00taitai000000000000Type-Tie-0.014--- abstract: 'tie a variable to a type constraint' author: - 'Toby Inkster (TOBYINK) ' build_requires: Test::More: '0.96' configure_requires: ExtUtils::MakeMaker: '6.17' dynamic_config: 1 generated_by: 'Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150010' keywords: [] license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Type-Tie no_index: directory: - eg - examples - inc - t - xt optional_features: {} provides: Type::Nano: file: lib/Type/Nano.pm version: '0.014' Type::Tie: file: lib/Type/Tie.pm version: '0.014' Type::Tie::ARRAY: file: lib/Type/Tie.pm version: '0.014' Type::Tie::BASE: file: lib/Type/Tie.pm version: '0.014' Type::Tie::HASH: file: lib/Type/Tie.pm version: '0.014' Type::Tie::SCALAR: file: lib/Type/Tie.pm version: '0.014' recommends: Hash::FieldHash: '0' requires: Exporter::Tiny: '0.026' perl: '5.008005' resources: Identifier: http://purl.org/NET/cpan-uri/dist/Type-Tie/project bugtracker: http://rt.cpan.org/Dist/Display.html?Queue=Type-Tie homepage: https://metacpan.org/release/Type-Tie license: http://dev.perl.org/licenses/ repository: git://github.com/tobyink/p5-type-tie.git version: '0.014' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Makefile.PL000644001750001750 1342013434770141 13751 0ustar00taitai000000000000Type-Tie-0.014use strict; use ExtUtils::MakeMaker 6.17; my $EUMM = eval( $ExtUtils::MakeMaker::VERSION ); my $meta = { "abstract" => "tie a variable to a type constraint", "author" => ["Toby Inkster (TOBYINK) "], "dynamic_config" => 1, "generated_by" => "Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150010", "keywords" => [], "license" => ["perl_5"], "meta-spec" => { url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec", version => 2, }, "name" => "Type-Tie", "no_index" => { directory => ["eg", "examples", "inc", "t", "xt"] }, "prereqs" => { configure => { requires => { "ExtUtils::MakeMaker" => 6.17 } }, runtime => { recommends => { "Hash::FieldHash" => 0 }, requires => { "Exporter::Tiny" => 0.026, "perl" => 5.008005 }, suggests => { "Types::Standard" => 0.004 }, }, test => { requires => { "Test::More" => 0.96 }, suggests => { "MooseX::Types::Moose" => 0, "Test::Fatal" => 0, "Test::Requires" => 0, "Types::Standard" => 0.004, }, }, }, "provides" => { "Type::Nano" => { file => "lib/Type/Nano.pm", version => 0.014 }, "Type::Tie" => { file => "lib/Type/Tie.pm", version => 0.014 }, "Type::Tie::ARRAY" => { file => "lib/Type/Tie.pm", version => 0.014 }, "Type::Tie::BASE" => { file => "lib/Type/Tie.pm", version => 0.014 }, "Type::Tie::HASH" => { file => "lib/Type/Tie.pm", version => 0.014 }, "Type::Tie::SCALAR" => { file => "lib/Type/Tie.pm", version => 0.014 }, }, "release_status" => "stable", "resources" => { bugtracker => { web => "http://rt.cpan.org/Dist/Display.html?Queue=Type-Tie" }, homepage => "https://metacpan.org/release/Type-Tie", license => ["http://dev.perl.org/licenses/"], repository => { type => "git", url => "git://github.com/tobyink/p5-type-tie.git", web => "https://github.com/tobyink/p5-type-tie", }, x_identifier => "http://purl.org/NET/cpan-uri/dist/Type-Tie/project", }, "version" => 0.014, }; my %dynamic_config; do { # Hash::Util::FieldHash was first released with perl v5.9.4 $meta->{prereqs}{runtime}{requires}{'Hash::FieldHash'} = 0 if $] < 5.009004; }; my %WriteMakefileArgs = ( ABSTRACT => $meta->{abstract}, AUTHOR => ($EUMM >= 6.5702 ? $meta->{author} : $meta->{author}[0]), DISTNAME => $meta->{name}, VERSION => $meta->{version}, EXE_FILES => [ map $_->{file}, values %{ $meta->{x_provides_scripts} || {} } ], NAME => do { my $n = $meta->{name}; $n =~ s/-/::/g; $n }, test => { TESTS => "t/*.t" }, %dynamic_config, ); $WriteMakefileArgs{LICENSE} = $meta->{license}[0] if $EUMM >= 6.3001; sub deps { my %r; for my $stage (@_) { for my $dep (keys %{$meta->{prereqs}{$stage}{requires}}) { next if $dep eq 'perl'; my $ver = $meta->{prereqs}{$stage}{requires}{$dep}; $r{$dep} = $ver if !exists($r{$dep}) || $ver >= $r{$dep}; } } \%r; } my ($build_requires, $configure_requires, $runtime_requires, $test_requires); if ($EUMM >= 6.6303) { $WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build'); $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{TEST_REQUIRES} ||= deps('test'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime'); } elsif ($EUMM >= 6.5503) { $WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build', 'test'); $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime'); } elsif ($EUMM >= 6.52) { $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime', 'build', 'test'); } else { $WriteMakefileArgs{PREREQ_PM} ||= deps('configure', 'build', 'test', 'runtime'); } { my ($minperl) = reverse sort( grep defined && /^[0-9]+(\.[0-9]+)?$/, map $meta->{prereqs}{$_}{requires}{perl}, qw( configure build runtime ) ); if (defined($minperl)) { die "Installing $meta->{name} requires Perl >= $minperl" unless $] >= $minperl; $WriteMakefileArgs{MIN_PERL_VERSION} ||= $minperl if $EUMM >= 6.48; } } sub FixMakefile { return unless -d 'inc'; my $file = shift; local *MAKEFILE; open MAKEFILE, "< $file" or die "FixMakefile: Couldn't open $file: $!; bailing out"; my $makefile = do { local $/; }; close MAKEFILE or die $!; $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; open MAKEFILE, "> $file" or die "FixMakefile: Couldn't open $file: $!; bailing out"; print MAKEFILE $makefile or die $!; close MAKEFILE or die $!; } my $mm = WriteMakefile(%WriteMakefileArgs); FixMakefile($mm->{FIRST_MAKEFILE} || 'Makefile'); exit(0); README000644001750001750 514513434770140 12643 0ustar00taitai000000000000Type-Tie-0.014NAME Type::Tie - tie a variable to a type constraint SYNOPSIS Type::Tie is a response to this sort of problem... use strict; use warnings; { package Local::Testing; use Moose; has numbers => ( is => "ro", isa => "ArrayRef[Num]" ); } # Nice list of numbers. my @N = ( 1, 2, 3, 3.14159 ); # Create an object with a reference to that list. my $object = Local::Testing->new(numbers => \@N); # Everything OK so far... # Now watch this! push @N, "Monkey!"; print $object->dump; # Houston, we have a problem! Just declare @N like this: use Type::Tie; use Types::Standard qw( Num ); ttie my @N, Num, ( 1, 2, 3, 3.14159 ); Now any attempt to add a non-numeric value to @N will die. DESCRIPTION This module exports a single function: `ttie`. `ttie` ties a variable to a type constraint, ensuring that whatever values stored in the variable will conform to the type constraint. If the type constraint has coercions, these will be used if necessary to ensure values assigned to the variable conform. use Type::Tie; use Types::Standard qw( Int Num ); ttie my $count, Int->plus_coercions(Num, 'int $_'), 0; $count++; # ok $count = 2; # ok $count = 3.14159; # ok, coerced to 3 $count = "Monkey!"; # dies While the examples in documentation (and the test suite) show type constraints from Types::Standard, but any type constraint objects supporting the Type::API interfaces should work. This includes: * Moose::Meta::TypeConstraint / MooseX::Types * Mouse::Meta::TypeConstraint / MouseX::Types * Specio * Type::Tiny BUGS Please report any bugs to . SUPPORT IRC: support is available through in the *#moops* channel on irc.perl.org . SEE ALSO Type::API, Type::Utils, Moose::Manual::Types, MooseX::Lexical::Types. AUTHOR Toby Inkster . COPYRIGHT AND LICENCE This software is copyright (c) 2013-2014, 2018-2019 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. DISCLAIMER OF WARRANTIES THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. SIGNATURE000644001750001750 403713434770141 13247 0ustar00taitai000000000000Type-Tie-0.014This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.81. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 5300bdf3878abfe27e5ae493dcff2fbe4ae601ec COPYRIGHT SHA1 fcc0855cf164ac1fe3b59e6c6aee83afc2624e37 CREDITS SHA1 a5e12f7e711959190701c627cc101cb82852ac03 Changes SHA1 5b1cad94d8f72b6ff61d8a5c689bcd6371c191e9 INSTALL SHA1 529a6c89bb1ec1ab70f21730c345dcbda3871ed8 LICENSE SHA1 8d17f6e6368329946a834926cc89e690e23ab3e4 MANIFEST SHA1 fcb30530980fd8074115fe0f97c415a0145de817 META.json SHA1 1eaccb872183f9d43fedd1eb8514dd4199f2f430 META.yml SHA1 e41bc95507fadfb17441bcc2beaeb7a0cbcd0ee4 Makefile.PL SHA1 2e1faec8acb1e6f5f3b223a21b65dc86a67a4501 README SHA1 079ab0087c7894144458db7bca7ce8fd630845ac dist.ini SHA1 4754192769e5e58ab22885db87112674df5a7dda doap.ttl SHA1 8b3c5d366a0a716096617c9e14a100c1948fd159 inc/Test/Fatal.pm SHA1 95d4da14025622f3a45f5e9b75b7b6860148f415 inc/Test/Requires.pm SHA1 e7088f7483bdffb64be359be205927c3d6639ffe inc/Try/Tiny.pm SHA1 1fb813ad146505d17a6d60fa198878f03f3b407a lib/Type/Nano.pm SHA1 e1e6c3f3d9edfc0b3919c375ad2bbeeb6848cebd lib/Type/Tie.pm SHA1 09948df533b09d64d790a3f85a5acc120337f9b1 t/01basic.t SHA1 6fda1c1994bb03279aefb8234b23bd0b97623962 t/02moosextypes.t SHA1 a8ae739960586707c973931499cf3d5218b7ec0e t/03prototypicalweirdness.t SHA1 155bff27dfde069079a5b9f050a20b1508ae210d t/04nots.t SHA1 03e7e2d966333947cd7f3450005dd5db30506c39 t/05typetiny.t SHA1 d2d588b514d35ea27e2bc87b7c69491a542cdc49 t/06tn-moo.t -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQRVJKj/4+s6z4WzNujOv4Eoaip9OQUCXHPwYQAKCRDOv4Eoaip9 OTomAJ9VSq2ZiLk61sdy0FtMCFqqyuzIuQCfYdsaw4ERsIDP1AI646nqpef5ykc= =vBKX -----END PGP SIGNATURE----- dist.ini000644001750001750 7713434770140 13366 0ustar00taitai000000000000Type-Tie-0.014;; class = 'Dist::Inkt::Profile::TOBYINK' ;; name = 'Type-Tie' doap.ttl000644001750001750 3011013434770141 13442 0ustar00taitai000000000000Type-Tie-0.014@prefix dc: . @prefix doap: . @prefix doap-changeset: . @prefix doap-deps: . @prefix foaf: . @prefix rdfs: . @prefix xsd: . dc:title "the same terms as the perl 5 programming language system itself". a doap:Project; dc:contributor ; doap-deps:runtime-recommendation [ doap-deps:on "Hash::FieldHash"^^doap-deps:CpanId ]; doap-deps:runtime-requirement [ doap-deps:on "perl 5.008005"^^doap-deps:CpanId ], [ doap-deps:on "Exporter::Tiny 0.026"^^doap-deps:CpanId; ]; doap-deps:runtime-suggestion [ doap-deps:on "Types::Standard 0.004"^^doap-deps:CpanId; ]; doap-deps:test-requirement [ doap-deps:on "Test::More 0.96"^^doap-deps:CpanId ]; doap-deps:test-suggestion [ doap-deps:on "Test::Fatal"^^doap-deps:CpanId ], [ doap-deps:on "Test::Requires"^^doap-deps:CpanId ], [ doap-deps:on "Types::Standard 0.004"^^doap-deps:CpanId; ], [ doap-deps:on "MooseX::Types::Moose"^^doap-deps:CpanId; ]; doap:bug-database ; doap:created "2013-05-05"^^xsd:date; doap:developer ; doap:download-page ; doap:homepage ; doap:license ; doap:maintainer ; doap:name "Type-Tie"; doap:programming-language "Perl"; doap:release , , , , , , , , , , , , , ; doap:repository [ a doap:GitRepository; doap:browse ; ]; doap:shortdesc "tie a variable to a type constraint". a doap:Version; rdfs:label "Initial release"; dc:identifier "Type-Tie-0.001"^^xsd:string; dc:issued "2013-05-05"^^xsd:date; doap-changeset:released-by ; doap:file-release ; doap:revision "0.001"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.002"^^xsd:string; dc:issued "2013-06-22"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "Support Type::API."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.002"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.003"^^xsd:string; dc:issued "2013-09-04"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Implement SPLICE as part of the tied array interface."; ], [ a doap-changeset:Packaging; rdfs:label "Convert to Dist::Inkt."; ], [ a doap-changeset:Packaging; rdfs:label "Fix link to source code repository."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.003"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.004"^^xsd:string; dc:issued "2013-09-06"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "Use compiled checks and coercions when possible."; ], [ a doap-changeset:Change; rdfs:label "Rename the undocumented `store_value` method to `coerce_and_check_value`."; ], [ a doap-changeset:Bugfix; rdfs:label "Fix weird bug in Perl < 5.14."; ], [ a doap-changeset:Tests; rdfs:label "Add a test case for using Type::Tie with MooseX::Types::Moose."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.004"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.005"^^xsd:string; dc:issued "2013-09-30"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Update; rdfs:label "Use Exporter::Tiny instead of Exporter::TypeTiny."; ], [ a doap-changeset:Change; rdfs:label "Stop using base.pm."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.005"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.006"^^xsd:string; dc:issued "2013-10-04"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "Make Hash::FieldHash optional for Perl >= v5.9.4; use Hash::Util::FieldHash if Hash::FieldHash is unavailable."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.006"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.007"^^xsd:string; dc:issued "2014-02-17"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Change ttie prototype from ([\\$@%]$;@) to ([\\$@%]@)."; doap-changeset:thanks ; ], [ a doap-changeset:Packaging; rdfs:label "Include my TODO list."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.007"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.008"^^xsd:string; dc:issued "2014-07-14"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Packaging; rdfs:label "Types::Standard and MooseX::Types::Moose are now just listed as 'suggested' for testing. (They were 'required' and 'recommended' respectively.)"; ], [ a doap-changeset:Tests; rdfs:label "Include a test case with a simple local implementation of Type::API."; ], [ a doap-changeset:Change; rdfs:label "Type::Tie now passes through the type constraint's error message rather than generating its own. It will still generate its own error message if the type constraint object fails to provide a get_message method."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.008"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.009"^^xsd:string; dc:issued "2014-09-17"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Packaging; rdfs:label "Repackage with newer version of Dist::Inkt to fix META.json error."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.009"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.010"^^xsd:string; dc:issued "2018-06-26"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Packaging; rdfs:label "Bundle copies of Test::Requires, Try::Tiny, and Test::Fatal in inc."; ], [ a doap-changeset:Packaging; rdfs:label "Bundle Type::Nano for testing."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.010"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.011"^^xsd:string; dc:issued "2018-06-26"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "Type::Nano does overloading."; ], [ a doap-changeset:Documentation; rdfs:label "Improvements to Type::Nano documentation."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.011"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.012"^^xsd:string; dc:issued "2019-01-02"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Tests; rdfs:label "Check that Type::Nano type constraints work with Moo."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.012"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.013"^^xsd:string; dc:issued "2019-01-06"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Documentation; rdfs:label "Clarify rationale and use of Type::Nano."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.013"^^xsd:string. a doap:Version; dc:identifier "Type-Tie-0.014"^^xsd:string; dc:issued "2019-02-25"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Make Type::Nano overloading work on Perl 5.8."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.014"^^xsd:string. a foaf:Person; foaf:name "Graham Knop"; foaf:nick "HAARG"; foaf:page . a foaf:Person; foaf:mbox ; foaf:name "Toby Inkster"; foaf:nick "TOBYINK"; foaf:page . 01basic.t000644001750001750 267113434770140 13636 0ustar00taitai000000000000Type-Tie-0.014/t=pod =encoding utf-8 =head1 PURPOSE Test that Type::Tie compiles and seems to work. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2013-2014, 2018-2019 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use warnings; use Test::More; use Test::Fatal; use Type::Tie; use Type::Nano qw( Int Num ); ttie my $count, Int, 0; $count++; is($count, 1); $count = 2; is($count, 2); like( exception { $count = "Monkey!" }, qr{^Value "Monkey!" did not pass type constraint Int}, ); ttie my @numbers, Int, 1, 2, 3; unshift @numbers, 0; $numbers[4] = 4; push @numbers, scalar @numbers; is_deeply( \@numbers, [ 0..5 ], ); like( exception { push @numbers, 1, 2, 3, "Bad", 4 }, qr{^Value "Bad" did not pass type constraint Int}, ); like( exception { unshift @numbers, 1, 2, 3, "Bad", 4 }, qr{^Value "Bad" did not pass type constraint Int}, ); like( exception { $numbers[2] .= "Bad" }, qr{^Value "2Bad" did not pass type constraint Int}, ); is_deeply( \@numbers, [ 0..5 ], ); ttie my %stuff, Int, foo => 1; $stuff{bar} = 2; is_deeply( \%stuff, { foo => 1, bar => 2 }, ); like( exception { $stuff{baz} = undef }, qr{^Undef did not pass type constraint Int}, ); delete $stuff{bar}; is_deeply( \%stuff, { foo => 1 }, ); done_testing; 02moosextypes.t000644001750001750 304313434770140 15147 0ustar00taitai000000000000Type-Tie-0.014/t=pod =encoding utf-8 =head1 PURPOSE Test that Type::Tie seems to work with L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2013-2014, 2018-2019 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use warnings; use Test::More; use Test::Fatal; use Test::Requires 'MooseX::Types::Moose'; use Type::Tie; use MooseX::Types::Moose qw( Int Num ); use Moose::Util::TypeConstraints; my $Rounded = Int->create_child_type; coerce($Rounded, from Num, via { int($_) }); ttie my $count, $Rounded, 0; $count++; is($count, 1); $count = 2; is($count, 2); $count = 3.14159; is($count, 3); like( exception { $count = "Monkey!" }, qr{^Validation failed}, ); ttie my @numbers, $Rounded, 1, 2, 3.14159; unshift @numbers, 0.1; $numbers[4] = 4.4; push @numbers, scalar @numbers; is_deeply( \@numbers, [ 0..5 ], ); like( exception { push @numbers, 1, 2.2, 3, "Bad", 4 }, qr{^Validation failed}, ); like( exception { unshift @numbers, 1, 2.2, 3, "Bad", 4 }, qr{^Validation failed}, ); like( exception { $numbers[2] .= "Bad" }, qr{^Validation failed}, ); is_deeply( \@numbers, [ 0..5 ], ); ttie my %stuff, Int, foo => 1; $stuff{bar} = 2; is_deeply( \%stuff, { foo => 1, bar => 2 }, ); like( exception { $stuff{baz} = undef }, qr{^Validation failed}, ); delete $stuff{bar}; is_deeply( \%stuff, { foo => 1 }, ); done_testing; 03prototypicalweirdness.t000644001750001750 117413434770140 17231 0ustar00taitai000000000000Type-Tie-0.014/t=pod =encoding utf-8 =head1 PURPOSE Test that C prototype works. Test case suggested by Graham Knop (HAARG). =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2014, 2018-2019 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use warnings; use Test::More; use Test::Requires 'Types::Standard'; use Type::Tie; use Types::Standard qw( ArrayRef Num ); ttie my $foo, ArrayRef[Num], [1,2,3]; is_deeply( $foo, [1..3], ); done_testing; 04nots.t000644001750001750 425613434770140 13544 0ustar00taitai000000000000Type-Tie-0.014/t=pod =encoding utf-8 =head1 PURPOSE Test that Type::Tie works with a home-made type constraint system conforming to L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2013-2014, 2018-2019 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use warnings; use Test::More; use Test::Fatal; use Type::Tie; use constant Int => do { package Local::Type::Int; sub DOES { return 1 if $_[1] eq "Type::API::Constraint"; return 1 if $_[1] eq "Type::API::Constraint::Coercible"; shift->SUPER::DOES(@_); } sub check { defined($_[1]) && $_[1] =~ /\A-?[0-9]+\z/; } sub get_message { defined($_[1]) ? "Value \"$_[1]\" does not meet type constraint Int" : "Undef does not meet type constraint Int" } my $x; bless \$x; }; use constant Rounded => do { package Local::Type::Rounded; our @ISA = 'Local::Type::Int'; sub has_coercion { 1; } sub coerce { defined($_[1]) && !ref($_[1]) && $_[1] =~ /\A[Ee0-9.-]+\z/ ? int($_[1]) : $_[1]; } my $x; bless \$x; }; ttie my $count, Rounded, 0; $count++; is($count, 1); $count = 2; is($count, 2); $count = 3.14159; is($count, 3); like( exception { $count = "Monkey!" }, qr{^Value "Monkey!" does not meet type constraint Int}, ); ttie my @numbers, Rounded, 1, 2, 3.14159; unshift @numbers, 0.1; $numbers[4] = 4.4; push @numbers, scalar @numbers; is_deeply( \@numbers, [ 0..5 ], ); like( exception { push @numbers, 1, 2.2, 3, "Bad", 4 }, qr{^Value "Bad" does not meet type constraint Int}, ); like( exception { unshift @numbers, 1, 2.2, 3, "Bad", 4 }, qr{^Value "Bad" does not meet type constraint Int}, ); like( exception { $numbers[2] .= "Bad" }, qr{^Value "2Bad" does not meet type constraint Int}, ); is_deeply( \@numbers, [ 0..5 ], ); ttie my %stuff, Int, foo => 1; $stuff{bar} = 2; is_deeply( \%stuff, { foo => 1, bar => 2 }, ); like( exception { $stuff{baz} = undef }, qr{^Undef does not meet type constraint Int}, ); delete $stuff{bar}; is_deeply( \%stuff, { foo => 1 }, ); done_testing; 05typetiny.t000644001750001750 311013434770140 14433 0ustar00taitai000000000000Type-Tie-0.014/t=pod =encoding utf-8 =head1 PURPOSE Test that Type::Tie seems to work with L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2013-2014, 2018-2019 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use warnings; use Test::More; use Test::Requires 'Types::Standard'; use Test::Fatal; use Type::Tie; use Types::Standard qw( Int Num ); ttie my $count, Int->plus_coercions(Num, 'int($_)'), 0; $count++; is($count, 1); $count = 2; is($count, 2); $count = 3.14159; is($count, 3); like( exception { $count = "Monkey!" }, qr{^Value "Monkey!" did not pass type constraint}, ); ttie my @numbers, Int->plus_coercions(Num, 'int($_)'), 1, 2, 3.14159; unshift @numbers, 0.1; $numbers[4] = 4.4; push @numbers, scalar @numbers; is_deeply( \@numbers, [ 0..5 ], ); like( exception { push @numbers, 1, 2.2, 3, "Bad", 4 }, qr{^Value "Bad" did not pass type constraint}, ); like( exception { unshift @numbers, 1, 2.2, 3, "Bad", 4 }, qr{^Value "Bad" did not pass type constraint}, ); like( exception { $numbers[2] .= "Bad" }, qr{^Value "2Bad" did not pass type constraint}, ); is_deeply( \@numbers, [ 0..5 ], ); ttie my %stuff, Int, foo => 1; $stuff{bar} = 2; is_deeply( \%stuff, { foo => 1, bar => 2 }, ); like( exception { $stuff{baz} = undef }, qr{^Undef did not pass type constraint}, ); delete $stuff{bar}; is_deeply( \%stuff, { foo => 1 }, ); done_testing; 06tn-moo.t000644001750001750 151013434770140 13762 0ustar00taitai000000000000Type-Tie-0.014/t=pod =encoding utf-8 =head1 PURPOSE Test that Type::Nano can be used with L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2019 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut use strict; use warnings; use Test::More; use Test::Requires 'Moo'; use Test::Fatal; { package My::Class; use Moo; use Type::Nano qw( Int ); has attr => (is => 'rw', isa => Int); } my $e1 = exception { My::Class->new(attr => undef) }; like $e1, qr/did not pass type constraint/; my $obj = My::Class->new(attr => 1); $obj->attr(2); is $obj->attr, 2; my $e2 = exception { $obj->attr('hello world') }; like $e2, qr/did not pass type constraint/; done_testing; Fatal.pm000644001750001750 245513434770140 15041 0ustar00taitai000000000000Type-Tie-0.014/inc/Test#line 1 use strict; use warnings; package Test::Fatal; { $Test::Fatal::VERSION = '0.010'; } # ABSTRACT: incredibly simple helpers for testing code with exceptions use Carp (); use Try::Tiny 0.07; use base 'Exporter'; our @EXPORT = qw(exception); our @EXPORT_OK = qw(exception success dies_ok lives_ok); sub exception (&) { my $code = shift; return try { $code->(); return undef; } catch { return $_ if $_; my $problem = defined $_ ? 'false' : 'undef'; Carp::confess("$problem exception caught by Test::Fatal::exception"); }; } sub success (&;@) { my $code = shift; return finally( sub { return if @_; # <-- only run on success $code->(); }, @_ ); } my $Tester; # Signature should match that of Test::Exception sub dies_ok (&;$) { my $code = shift; my $name = shift; require Test::Builder; $Tester ||= Test::Builder->new; my $ok = $Tester->ok( exception( \&$code ), $name ); $ok or $Tester->diag( "expected an exception but none was raised" ); return $ok; } sub lives_ok (&;$) { my $code = shift; my $name = shift; require Test::Builder; $Tester ||= Test::Builder->new; my $ok = $Tester->ok( !exception( \&$code ), $name ); $ok or $Tester->diag( "expected return but an exception was raised" ); return $ok; } 1; __END__ #line 212 Requires.pm000644001750001750 343313434770140 15606 0ustar00taitai000000000000Type-Tie-0.014/inc/Test#line 1 package Test::Requires; use strict; use warnings; our $VERSION = '0.06'; use base 'Test::Builder::Module'; use 5.006000; sub import { my $class = shift; my $caller = caller(0); # export methods { no strict 'refs'; *{"$caller\::test_requires"} = \&test_requires; } # test arguments if (@_ == 1 && ref $_[0] && ref $_[0] eq 'HASH') { while (my ($mod, $ver) = each %{$_[0]}) { test_requires($mod, $ver, $caller); } } else { for my $mod (@_) { test_requires($mod, undef, $caller); } } } sub test_requires { my ( $mod, $ver, $caller ) = @_; return if $mod eq __PACKAGE__; if (@_ != 3) { $caller = caller(0); } $ver ||= ''; eval qq{package $caller; use $mod $ver}; ## no critic. if (my $e = $@) { my $skip_all = sub { my $builder = __PACKAGE__->builder; if (not defined $builder->has_plan) { $builder->skip_all(@_); } elsif ($builder->has_plan eq 'no_plan') { $builder->skip(@_); if ( $builder->can('parent') && $builder->parent ) { die bless {} => 'Test::Builder::Exception'; } exit 0; } else { for (1..$builder->has_plan) { $builder->skip(@_); } if ( $builder->can('parent') && $builder->parent ) { die bless {} => 'Test::Builder::Exception'; } exit 0; } }; if ( $e =~ /^Can't locate/ ) { $skip_all->("Test requires module '$mod' but it's not found"); } else { $skip_all->("$e"); } } } 1; __END__ #line 128 Tiny.pm000644001750001750 4332513434770140 14615 0ustar00taitai000000000000Type-Tie-0.014/inc/Trypackage Try::Tiny; BEGIN { $Try::Tiny::AUTHORITY = 'cpan:NUFFIN'; } $Try::Tiny::VERSION = '0.21'; use 5.006; # ABSTRACT: minimal try/catch with proper preservation of $@ use strict; use warnings; use Exporter (); our @ISA = qw( Exporter ); our @EXPORT = our @EXPORT_OK = qw(try catch finally); use Carp; $Carp::Internal{+__PACKAGE__}++; BEGIN { eval "use Sub::Name; 1" or *{subname} = sub {1} } # Need to prototype as @ not $$ because of the way Perl evaluates the prototype. # Keeping it at $$ means you only ever get 1 sub because we need to eval in a list # context & not a scalar one sub try (&;@) { my ( $try, @code_refs ) = @_; # we need to save this here, the eval block will be in scalar context due # to $failed my $wantarray = wantarray; # work around perl bug by explicitly initializing these, due to the likelyhood # this will be used in global destruction (perl rt#119311) my ( $catch, @finally ) = (); # find labeled blocks in the argument list. # catch and finally tag the blocks by blessing a scalar reference to them. foreach my $code_ref (@code_refs) { if ( ref($code_ref) eq 'Try::Tiny::Catch' ) { croak 'A try() may not be followed by multiple catch() blocks' if $catch; $catch = ${$code_ref}; } elsif ( ref($code_ref) eq 'Try::Tiny::Finally' ) { push @finally, ${$code_ref}; } else { croak( 'try() encountered an unexpected argument (' . ( defined $code_ref ? $code_ref : 'undef' ) . ') - perhaps a missing semi-colon before or' ); } } # FIXME consider using local $SIG{__DIE__} to accumulate all errors. It's # not perfect, but we could provide a list of additional errors for # $catch->(); # name the blocks if we have Sub::Name installed my $caller = caller; subname("${caller}::try {...} " => $try); subname("${caller}::catch {...} " => $catch) if $catch; subname("${caller}::finally {...} " => $_) foreach @finally; # save the value of $@ so we can set $@ back to it in the beginning of the eval # and restore $@ after the eval finishes my $prev_error = $@; my ( @ret, $error ); # failed will be true if the eval dies, because 1 will not be returned # from the eval body my $failed = not eval { $@ = $prev_error; # evaluate the try block in the correct context if ( $wantarray ) { @ret = $try->(); } elsif ( defined $wantarray ) { $ret[0] = $try->(); } else { $try->(); }; return 1; # properly set $fail to false }; # preserve the current error and reset the original value of $@ $error = $@; $@ = $prev_error; # set up a scope guard to invoke the finally block at the end my @guards = map { Try::Tiny::ScopeGuard->_new($_, $failed ? $error : ()) } @finally; # at this point $failed contains a true value if the eval died, even if some # destructor overwrote $@ as the eval was unwinding. if ( $failed ) { # if we got an error, invoke the catch block. if ( $catch ) { # This works like given($error), but is backwards compatible and # sets $_ in the dynamic scope for the body of C<$catch> for ($error) { return $catch->($error); } # in case when() was used without an explicit return, the C # loop will be aborted and there's no useful return value } return; } else { # no failure, $@ is back to what it was, everything is fine return $wantarray ? @ret : $ret[0]; } } sub catch (&;@) { my ( $block, @rest ) = @_; croak 'Useless bare catch()' unless wantarray; return ( bless(\$block, 'Try::Tiny::Catch'), @rest, ); } sub finally (&;@) { my ( $block, @rest ) = @_; croak 'Useless bare finally()' unless wantarray; return ( bless(\$block, 'Try::Tiny::Finally'), @rest, ); } { package # hide from PAUSE Try::Tiny::ScopeGuard; use constant UNSTABLE_DOLLARAT => ($] < '5.013002') ? 1 : 0; sub _new { shift; bless [ @_ ]; } sub DESTROY { my ($code, @args) = @{ $_[0] }; local $@ if UNSTABLE_DOLLARAT; eval { $code->(@args); 1; } or do { warn "Execution of finally() block $code resulted in an exception, which " . '*CAN NOT BE PROPAGATED* due to fundamental limitations of Perl. ' . 'Your program will continue as if this event never took place. ' . "Original exception text follows:\n\n" . (defined $@ ? $@ : '$@ left undefined...') . "\n" ; } } } __PACKAGE__ __END__ =pod =encoding UTF-8 =head1 NAME Try::Tiny - minimal try/catch with proper preservation of $@ =head1 VERSION version 0.21 =head1 SYNOPSIS You can use Try::Tiny's C and C to expect and handle exceptional conditions, avoiding quirks in Perl and common mistakes: # handle errors with a catch handler try { die "foo"; } catch { warn "caught error: $_"; # not $@ }; You can also use it like a standalone C to catch and ignore any error conditions. Obviously, this is an extreme measure not to be undertaken lightly: # just silence errors try { die "foo"; }; =head1 DESCRIPTION This module provides bare bones C/C/C statements that are designed to minimize common mistakes with eval blocks, and NOTHING else. This is unlike L which provides a nice syntax and avoids adding another call stack layer, and supports calling C from the C block to return from the parent subroutine. These extra features come at a cost of a few dependencies, namely L and L which are occasionally problematic, and the additional catch filtering uses L type constraints which may not be desirable either. The main focus of this module is to provide simple and reliable error handling for those having a hard time installing L, but who still want to write correct C blocks without 5 lines of boilerplate each time. It's designed to work as correctly as possible in light of the various pathological edge cases (see L) and to be compatible with any style of error values (simple strings, references, objects, overloaded objects, etc). If the C block dies, it returns the value of the last statement executed in the C block, if there is one. Otherwise, it returns C in scalar context or the empty list in list context. The following examples all assign C<"bar"> to C<$x>: my $x = try { die "foo" } catch { "bar" }; my $x = try { die "foo" } || { "bar" }; my $x = (try { die "foo" }) // { "bar" }; my $x = eval { die "foo" } || "bar"; You can add C blocks, yielding the following: my $x; try { die 'foo' } finally { $x = 'bar' }; try { die 'foo' } catch { warn "Got a die: $_" } finally { $x = 'bar' }; C blocks are always executed making them suitable for cleanup code which cannot be handled using local. You can add as many C blocks to a given C block as you like. Note that adding a C block without a preceding C block suppresses any errors. This behaviour is consistent with using a standalone C, but it is not consistent with C/C patterns found in other programming languages, such as Java, Python, Javascript or C#. If you learnt the C/C pattern from one of these languages, watch out for this. =head1 EXPORTS All functions are exported by default using L. If you need to rename the C, C or C keyword consider using L to get L's flexibility. =over 4 =item try (&;@) Takes one mandatory C subroutine, an optional C subroutine and C subroutine. The mandatory subroutine is evaluated in the context of an C block. If no error occurred the value from the first block is returned, preserving list/scalar context. If there was an error and the second subroutine was given it will be invoked with the error in C<$_> (localized) and as that block's first and only argument. C<$@> does B contain the error. Inside the C block it has the same value it had before the C block was executed. Note that the error may be false, but if that happens the C block will still be invoked. Once all execution is finished then the C block, if given, will execute. =item catch (&;@) Intended to be used in the second argument position of C. Returns a reference to the subroutine it was given but blessed as C which allows try to decode correctly what to do with this code reference. catch { ... } Inside the C block the caught error is stored in C<$_>, while previous value of C<$@> is still available for use. This value may or may not be meaningful depending on what happened before the C, but it might be a good idea to preserve it in an error stack. For code that captures C<$@> when throwing new errors (i.e. L), you'll need to do: local $@ = $_; =item finally (&;@) try { ... } catch { ... } finally { ... }; Or try { ... } finally { ... }; Or even try { ... } finally { ... } catch { ... }; Intended to be the second or third element of C. C blocks are always executed in the event of a successful C or if C is run. This allows you to locate cleanup code which cannot be done via C e.g. closing a file handle. When invoked, the C block is passed the error that was caught. If no error was caught, it is passed nothing. (Note that the C block does not localize C<$_> with the error, since unlike in a C block, there is no way to know if C<$_ == undef> implies that there were no errors.) In other words, the following code does just what you would expect: try { die_sometimes(); } catch { # ...code run in case of error } finally { if (@_) { print "The try block died with: @_\n"; } else { print "The try block ran without error.\n"; } }; B block>. C will not do anything about handling possible errors coming from code located in these blocks. Furthermore B blocks are not trappable and are unable to influence the execution of your program>. This is due to limitation of C-based scope guards, which C is implemented on top of. This may change in a future version of Try::Tiny. In the same way C blesses the code reference this subroutine does the same except it bless them as C. =back =head1 BACKGROUND There are a number of issues with C. =head2 Clobbering $@ When you run an C block and it succeeds, C<$@> will be cleared, potentially clobbering an error that is currently being caught. This causes action at a distance, clearing previous errors your caller may have not yet handled. C<$@> must be properly localized before invoking C in order to avoid this issue. More specifically, C<$@> is clobbered at the beginning of the C, which also makes it impossible to capture the previous error before you die (for instance when making exception objects with error stacks). For this reason C will actually set C<$@> to its previous value (the one available before entering the C block) in the beginning of the C block. =head2 Localizing $@ silently masks errors Inside an C block, C behaves sort of like: sub die { $@ = $_[0]; return_undef_from_eval(); } This means that if you were polite and localized C<$@> you can't die in that scope, or your error will be discarded (printing "Something's wrong" instead). The workaround is very ugly: my $error = do { local $@; eval { ... }; $@; }; ... die $error; =head2 $@ might not be a true value This code is wrong: if ( $@ ) { ... } because due to the previous caveats it may have been unset. C<$@> could also be an overloaded error object that evaluates to false, but that's asking for trouble anyway. The classic failure mode is: sub Object::DESTROY { eval { ... } } eval { my $obj = Object->new; die "foo"; }; if ( $@ ) { } In this case since C is not localizing C<$@> but still uses C, it will set C<$@> to C<"">. The destructor is called when the stack is unwound, after C sets C<$@> to C<"foo at Foo.pm line 42\n">, so by the time C is evaluated it has been cleared by C in the destructor. The workaround for this is even uglier than the previous ones. Even though we can't save the value of C<$@> from code that doesn't localize, we can at least be sure the C was aborted due to an error: my $failed = not eval { ... return 1; }; This is because an C that caught a C will always return a false value. =head1 SHINY SYNTAX Using Perl 5.10 you can use L. The C block is invoked in a topicalizer context (like a C block), but note that you can't return a useful value from C using the C blocks without an explicit C. This is somewhat similar to Perl 6's C blocks. You can use it to concisely match errors: try { require Foo; } catch { when (/^Can't locate .*?\.pm in \@INC/) { } # ignore default { die $_ } }; =head1 CAVEATS =over 4 =item * C<@_> is not available within the C block, so you need to copy your arglist. In case you want to work with argument values directly via C<@_> aliasing (i.e. allow C<$_[1] = "foo">), you need to pass C<@_> by reference: sub foo { my ( $self, @args ) = @_; try { $self->bar(@args) } } or sub bar_in_place { my $self = shift; my $args = \@_; try { $_ = $self->bar($_) for @$args } } =item * C returns from the C block, not from the parent sub (note that this is also how C works, but not how L works): sub parent_sub { try { die; } catch { return; }; say "this text WILL be displayed, even though an exception is thrown"; } Instead, you should capture the return value: sub parent_sub { my $success = try { die; 1; }; return unless $success; say "This text WILL NEVER appear!"; } # OR sub parent_sub_with_catch { my $success = try { die; 1; } catch { # do something with $_ return undef; #see note }; return unless $success; say "This text WILL NEVER appear!"; } Note that if you have a C block, it must return C for this to work, since if a C block exists, its return value is returned in place of C when an exception is thrown. =item * C introduces another caller stack frame. L is not used. L will not report this when using full stack traces, though, because C<%Carp::Internal> is used. This lack of magic is considered a feature. =item * The value of C<$_> in the C block is not guaranteed to be the value of the exception thrown (C<$@>) in the C block. There is no safe way to ensure this, since C may be used unhygenically in destructors. The only guarantee is that the C will be called if an exception is thrown. =item * The return value of the C block is not ignored, so if testing the result of the expression for truth on success, be sure to return a false value from the C block: my $obj = try { MightFail->new; } catch { ... return; # avoid returning a true value; }; return unless $obj; =item * C<$SIG{__DIE__}> is still in effect. Though it can be argued that C<$SIG{__DIE__}> should be disabled inside of C blocks, since it isn't people have grown to rely on it. Therefore in the interests of compatibility, C does not disable C<$SIG{__DIE__}> for the scope of the error throwing code. =item * Lexical C<$_> may override the one set by C. For example Perl 5.10's C form uses a lexical C<$_>, creating some confusing behavior: given ($foo) { when (...) { try { ... } catch { warn $_; # will print $foo, not the error warn $_[0]; # instead, get the error like this } } } Note that this behavior was changed once again in L. However, since the entirety of lexical C<$_> is now L, it is unclear whether the new version 18 behavior is final. =back =head1 SEE ALSO =over 4 =item L Much more feature complete, more convenient semantics, but at the cost of implementation complexity. =item L Automatic error throwing for builtin functions and more. Also designed to work well with C/C. =item L A lightweight role for rolling your own exception classes. =item L Exception object implementation with a C statement. Does not localize C<$@>. =item L Provides a C statement, but properly calling C is your responsibility. The C keyword pushes C<$@> onto an error stack, avoiding some of the issues with C<$@>, but you still need to localize to prevent clobbering. =back =head1 LIGHTNING TALK I gave a lightning talk about this module, you can see the slides (Firefox only): L Or read the source: L =head1 VERSION CONTROL L =head1 AUTHORS =over 4 =item * Yuval Kogman =item * Jesse Luehrs =back =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by Yuval Kogman. This is free software, licensed under: The MIT (X11) License =cut Nano.pm000644001750001750 2325413434770140 14724 0ustar00taitai000000000000Type-Tie-0.014/lib/Typeuse 5.008001; use strict; use warnings; use Exporter::Tiny (); use Scalar::Util (); package Type::Nano; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.014'; our @ISA = qw( Exporter::Tiny ); our @EXPORT_OK = qw( Any Defined Undef Ref ArrayRef HashRef CodeRef Object Str Bool Num Int Object class_type role_type duck_type union intersection enum type ); # Built-in type constraints # our %TYPES; sub Any () { $TYPES{Any} ||= __PACKAGE__->new( name => 'Any', constraint => sub { !!1 }, ); } sub Defined () { $TYPES{Defined} ||= __PACKAGE__->new( name => 'Defined', parent => Any, constraint => sub { defined $_ }, ); } sub Undef () { $TYPES{Undef} ||= __PACKAGE__->new( name => 'Undef', parent => Any, constraint => sub { !defined $_ }, ); } sub Ref () { $TYPES{Ref} ||= __PACKAGE__->new( name => 'Ref', parent => Defined, constraint => sub { ref $_ }, ); } sub ArrayRef () { $TYPES{ArrayRef} ||= __PACKAGE__->new( name => 'ArrayRef', parent => Ref, constraint => sub { ref $_ eq 'ARRAY' }, ); } sub HashRef () { $TYPES{HashRef} ||= __PACKAGE__->new( name => 'HashRef', parent => Ref, constraint => sub { ref $_ eq 'HASH' }, ); } sub CodeRef () { $TYPES{CodeRef} ||= __PACKAGE__->new( name => 'CodeRef', parent => Ref, constraint => sub { ref $_ eq 'CODE' }, ); } sub Object () { $TYPES{Object} ||= __PACKAGE__->new( name => 'Object', parent => Ref, constraint => sub { Scalar::Util::blessed($_) }, ); } sub Bool () { $TYPES{Bool} ||= __PACKAGE__->new( name => 'Bool', parent => Any, constraint => sub { !defined($_) or (!ref($_) and { 1 => 1, 0 => 1, '' => 1 }->{$_}) }, ); } sub Str () { $TYPES{Str} ||= __PACKAGE__->new( name => 'Str', parent => Defined, constraint => sub { !ref $_ }, ); } sub Num () { $TYPES{Num} ||= __PACKAGE__->new( name => 'Num', parent => Str, constraint => sub { Scalar::Util::looks_like_number($_) }, ); } sub Int () { $TYPES{Int} ||= __PACKAGE__->new( name => 'Int', parent => Num, constraint => sub { /\A-?[0-9]+\z/ }, ); } sub class_type ($) { my $class = shift; $TYPES{CLASS}{$class} ||= __PACKAGE__->new( name => $class, parent => Object, constraint => sub { $_->isa($class) }, class => $class, ); } sub role_type ($) { my $role = shift; $TYPES{ROLE}{$role} ||= __PACKAGE__->new( name => $role, parent => Object, constraint => sub { my $meth = $_->can('DOES') || $_->can('isa'); $_->$meth($role) }, role => $role, ); } sub duck_type { my $name = ref($_[0]) ? '__ANON__' : shift; my @methods = sort( ref($_[0]) ? @{+shift} : @_ ); my $methods = join "|", @methods; $TYPES{DUCK}{$methods} ||= __PACKAGE__->new( name => $name, parent => Object, constraint => sub { my $obj = $_; $obj->can($_)||return !!0 for @methods; !!1 }, methods => \@methods, ); } sub enum { my $name = ref($_[0]) ? '__ANON__' : shift; my @values = sort( ref($_[0]) ? @{+shift} : @_ ); my $values = join "|", map quotemeta, @values; my $regexp = qr/\A(?:$values)\z/; $TYPES{ENUM}{$values} ||= __PACKAGE__->new( name => $name, parent => Str, constraint => sub { $_ =~ $regexp }, values => \@values, ); } sub union { my $name = ref($_[0]) ? '__ANON__' : shift; my @types = ref($_[0]) ? @{+shift} : @_; __PACKAGE__->new( name => $name, constraint => sub { my $val = $_; $_->check($val) && return !!1 for @types; !!0 }, types => \@types, ); } sub intersection { my $name = ref($_[0]) ? '__ANON__' : shift; my @types = ref($_[0]) ? @{+shift} : @_; __PACKAGE__->new( name => $name, constraint => sub { my $val = $_; $_->check($val) || return !!0 for @types; !!1 }, types => \@types, ); } sub type { my $name = ref($_[0]) ? '__ANON__' : shift; my $coderef = shift; __PACKAGE__->new( name => $name, constraint => $coderef, ); } # OO interface # sub DOES { my $proto = shift; my ($role) = @_; return !!1 if { 'Type::API::Constraint' => 1, 'Type::API::Constraint::Constructor' => 1, }->{$role}; "UNIVERSAL"->can("DOES") ? $proto->SUPER::DOES(@_) : $proto->isa(@_); } sub new { # Type::API::Constraint::Constructor my $class = ref($_[0]) ? ref(shift) : shift; my $self = bless { @_ == 1 ? %{+shift} : @_ } => $class; $self->{constraint} ||= sub { !!1 }; unless ($self->{name}) { require Carp; Carp::croak("Requires both `name` and `constraint`"); } $self; } sub check { # Type::API::Constraint my $self = shift; my ($value) = @_; if ($self->{parent}) { return unless $self->{parent}->check($value); } local $_ = $value; $self->{constraint}->($value); } sub get_message { # Type::API::Constraint my $self = shift; my ($value) = @_; require B; !defined($value) ? sprintf("Undef did not pass type constraint %s", $self->{name}) : ref($value) ? sprintf("Reference %s did not pass type constraint %s", $value, $self->{name}) : sprintf("Value %s did not pass type constraint %s", B::perlstring($value), $self->{name}); } # Overloading # { my $nil = sub {}; sub _install_overloads { no strict 'refs'; no warnings 'redefine', 'once'; if ($] < 5.010) { require overload; push @_, fallback => 1; goto \&overload::OVERLOAD; }; my $class = shift; *{$class . '::(('} = sub {}; *{$class . '::()'} = sub {}; *{$class . '::()'} = do { my $x = 1; \$x }; while (@_) { my $f = shift; #*{$class . '::(' . $f} = $nil; # cargo culting overload.pm #*{$class . '::(' . $f} = shift; *{$class . '::(' . $f} = ref $_[0] ? shift : do { my $m = shift; sub { shift->$m(@_) } }; } } } __PACKAGE__ ->_install_overloads( 'bool' => sub { 1 }, '""' => sub { shift->{name} }, '&{}' => sub { my $self = shift; sub { my ($value) = @_; $self->check($value) or do { require Carp; Carp::croak($self->get_message($value)); }; }; }, ); 1; __END__ =pod =encoding utf-8 =head1 NAME Type::Nano - simple type constraint library for testing =head1 SYNOPSIS use Type::Nano qw(Int); Int->check("42"); # true =head1 RATIONALE This is a really basic implementation of L for testing modules that make use of type constraints, such as L. I'll stress that this module is I intended for use in testing. It was created to eliminate Type::Tie's testing dependency on L. If your code supports Type::Nano, then your code should also B support L, L, L, and L with no extra effort. (Of course, some of those libraries do have some more features you may want to make extra effort to use! Inlining, for example.) Type::Nano is not recommended for use in regular application code. L while bigger than Type::Nano, will be I faster at runtime, and offers better integration with Moo, Moose, Mouse, and a wide variety of other tools. Use that instead. All that having been said, L is compatible with: L, L, L (e.g. you can use Type::Tiny's implementation of C and Type::Nano's implementation of C, and combine them as C<< ArrayRef[Int] >>), L, and L. =head1 DESCRIPTION =head2 Object-Oriented Interface =head3 Constructor =over =item C<< Type::Nano->new(%parameters) >> The constructor supports named parameters called C (a string), C (a coderef expected to return a boolean), and C (a blessed Type::Nano object). Any other parameters passed to the constructor will be stored in the blessed hashred returned, but are ignored by Type::Nano. =back =head3 Methods Types support the following methods: =over =item C<< $type->check($value) >> Checks the value against the constraint; returns a boolean. =item C<< $type->get_message($failing_value) >> Returns an error message. Does not check the value. =back Types overload C<< &{} >> to do something like: $type->check($value) or croak($type->get_message($value)) =head2 Exports This module optionally exports the following type constraints: =over =item * Any =item * Defined =item * Undef =item * Ref =item * ArrayRef =item * HashRef =item * CodeRef =item * Object =item * Str =item * Bool =item * Num =item * Int =back It also optionally exports the following functions for creating new type constraints: =over =item * C<< type $name, $coderef >> or C<< type $coderef >> =item * C<< class_type $class >> =item * C<< role_type $role >> =item * C<< duck_type $name, \@methods >> or C<< duck_type \@methods >> =item * C<< enum $name, \@values >> or C<< enum \@values >> =item * C<< union $name, \@types >> or C<< union \@types >> =item * C<< intersection $name, \@types >> or C<< intersection \@types >> =back =head1 BUGS Please report any bugs to L. =head1 SUPPORT B<< IRC: >> support is available through in the I<< #moops >> channel on L. =head1 SEE ALSO L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2018-2019 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 DISCLAIMER OF WARRANTIES THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. Tie.pm000644001750001750 1541413434770140 14551 0ustar00taitai000000000000Type-Tie-0.014/lib/Typeuse 5.008005; use strict; use warnings; use Carp (); use Exporter::Tiny (); use Tie::Array (); use Tie::Hash (); use Tie::Scalar (); ++$Carp::CarpInternal{"Type::Tie::$_"} for qw( BASE SCALAR ARRAY HASH ); BEGIN { package Type::Tie; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.014'; our @ISA = qw( Exporter::Tiny ); our @EXPORT = qw( ttie ); sub ttie (\[$@%]@)#>&%*/&<%\$[]^!@;@) { my ($ref, $type, @vals) = @_; if (ref($ref) eq "HASH") { tie(%$ref, "Type::Tie::HASH", $type); %$ref = @vals if @vals; } elsif (ref($ref) eq "ARRAY") { tie(@$ref, "Type::Tie::ARRAY", $type); @$ref = @vals if @vals; } else { tie($$ref, "Type::Tie::SCALAR", $type); $$ref = $vals[-1] if @vals; } return $ref; } }; BEGIN { package Type::Tie::BASE; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.014'; BEGIN { my $impl; $impl ||= eval { require Hash::FieldHash; 'Hash::FieldHash' }; $impl ||= do { require Hash::Util::FieldHash; 'Hash::Util::FieldHash' }; $impl->import('fieldhash'); }; fieldhash(my %TYPE); fieldhash(my %COERCE); fieldhash(my %CHECK); sub _set_type { my $self = shift; my $type = $_[0]; $TYPE{$self} = $type; if ($type->isa('Type::Tiny')) { $CHECK{$self} = $type->compiled_check; $COERCE{$self} = undef; $COERCE{$self} = $type->coercion->compiled_coercion if $type->has_coercion; } else { $CHECK{$self} = $type->can('compiled_check') ? $type->compiled_check : sub { $type->check($_[0]) }; $COERCE{$self} = undef; $COERCE{$self} = sub { $type->coerce($_[0]) } if $type->can("has_coercion") && $type->can("coerce") && $type->has_coercion; } } sub type { my $self = shift; $TYPE{$self}; } sub _dd { my $value = @_ ? $_[0] : $_; !defined $value ? 'Undef' : !ref $value ? sprintf('Value %s', B::perlstring($value)) : do { require Data::Dumper; local $Data::Dumper::Indent = 0; local $Data::Dumper::Useqq = 1; local $Data::Dumper::Terse = 1; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Maxdepth = 2; Data::Dumper::Dumper($value) } } sub coerce_and_check_value { my $self = shift; my $check = $CHECK{$self}; my $coerce = $COERCE{$self}; my @vals = map { my $val = $coerce ? $coerce->($_) : $_; if (not $check->($val)) { my $type = $TYPE{$self}; Carp::croak( $type && $type->can('get_message') ? $type->get_message($val) : sprintf("%s does not meet type constraint %s", _dd($_), $type||'Unknown') ); } $val; } (my @cp = @_); # need to copy @_ for Perl < 5.14 wantarray ? @vals : $vals[0]; } }; BEGIN { package Type::Tie::ARRAY; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.014'; our @ISA = qw( Tie::StdArray Type::Tie::BASE ); sub TIEARRAY { my $class = shift; my $self = $class->SUPER::TIEARRAY; $self->_set_type($_[0]); return $self; } sub STORE { my $self = shift; $self->SUPER::STORE($_[0], $self->coerce_and_check_value($_[1])); } sub PUSH { my $self = shift; $self->SUPER::PUSH( $self->coerce_and_check_value(@_) ); } sub UNSHIFT { my $self = shift; $self->SUPER::UNSHIFT( $self->coerce_and_check_value(@_) ); } sub SPLICE { my $self = shift; my ($start, $len, @rest) = @_; $self->SUPER::SPLICE($start, $len, $self->coerce_and_check_value(@rest) ); } }; BEGIN { package Type::Tie::HASH; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.014'; our @ISA = qw( Tie::StdHash Type::Tie::BASE ); sub TIEHASH { my $class = shift; my $self = $class->SUPER::TIEHASH; $self->_set_type($_[0]); return $self; } sub STORE { my $self = shift; $self->SUPER::STORE($_[0], $self->coerce_and_check_value($_[1])); } }; BEGIN { package Type::Tie::SCALAR; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.014'; our @ISA = qw( Tie::StdScalar Type::Tie::BASE ); sub TIESCALAR { my $class = shift; my $self = $class->SUPER::TIESCALAR; $self->_set_type($_[0]); return $self; } sub STORE { my $self = shift; $self->SUPER::STORE( $self->coerce_and_check_value($_[0]) ); } }; 1; __END__ =pod =encoding utf-8 =head1 NAME Type::Tie - tie a variable to a type constraint =head1 SYNOPSIS Type::Tie is a response to this sort of problem... use strict; use warnings; { package Local::Testing; use Moose; has numbers => ( is => "ro", isa => "ArrayRef[Num]" ); } # Nice list of numbers. my @N = ( 1, 2, 3, 3.14159 ); # Create an object with a reference to that list. my $object = Local::Testing->new(numbers => \@N); # Everything OK so far... # Now watch this! push @N, "Monkey!"; print $object->dump; # Houston, we have a problem! Just declare C<< @N >> like this: use Type::Tie; use Types::Standard qw( Num ); ttie my @N, Num, ( 1, 2, 3, 3.14159 ); Now any attempt to add a non-numeric value to C<< @N >> will die. =head1 DESCRIPTION This module exports a single function: C. C ties a variable to a type constraint, ensuring that whatever values stored in the variable will conform to the type constraint. If the type constraint has coercions, these will be used if necessary to ensure values assigned to the variable conform. use Type::Tie; use Types::Standard qw( Int Num ); ttie my $count, Int->plus_coercions(Num, 'int $_'), 0; $count++; # ok $count = 2; # ok $count = 3.14159; # ok, coerced to 3 $count = "Monkey!"; # dies While the examples in documentation (and the test suite) show type constraints from L, but any type constraint objects supporting the L interfaces should work. This includes: =over =item * L / L =item * L / L =item * L =item * L =back =begin trustme =item ttie =end trustme =head1 BUGS Please report any bugs to L. =head1 SUPPORT B<< IRC: >> support is available through in the I<< #moops >> channel on L. =head1 SEE ALSO L, L, L, L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2013-2014, 2018-2019 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 DISCLAIMER OF WARRANTIES THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.