Data-Validate-Type-v1.6.0/000077500000000000000000000000001306441476500152355ustar00rootroot00000000000000Data-Validate-Type-v1.6.0/.githooksrc000066400000000000000000000010001306441476500174010ustar00rootroot00000000000000force_plugins = PerlCompile, PerlCritic, ValidatePODFormat, BlockNOCOMMIT, PrependTicketID, RequireCommitMessage, ValidateChangelogFormat, VersionTagsRequireChangelog project_prefixes = GH extract_ticket_id_from_branch = /^($project_prefixes\d+)/ normalize_branch_ticket_id = s/^(.*?)(\d+)$/\U$1-$2/ extract_ticket_id_from_commit = /^\(($project_prefixes-\d+)\) / [PrependTicketID] commit_prefix_format = /($ticket_id) / [PerlCompile] lib_paths = ./lib/ [VersionTagsRequireChangelog] changelog_path = Changes Data-Validate-Type-v1.6.0/.gitignore000066400000000000000000000000131306441476500172170ustar00rootroot00000000000000/cover_db/ Data-Validate-Type-v1.6.0/.perlcriticrc000066400000000000000000000011011306441476500177140ustar00rootroot00000000000000# Change default severity to harsh. severity = harsh # Use only core PerlCritic policies. # This prevents tests from failing if the tester / installer has non-standard # additional PerlCritic policies. theme = core # Don't require /x on small regexes. [RegularExpressions::RequireExtendedFormatting] minimum_regex_length_to_complain_about = 20 # Allow private subroutines that start with an underscore followed by at least # three uppercase characters, which are subroutines coming from Params::Util. [Subroutines::ProtectPrivateSubs] private_name_regex = _(?![A-Z]{3,})\w+ Data-Validate-Type-v1.6.0/.travis.yml000066400000000000000000000003061306441476500173450ustar00rootroot00000000000000language: perl perl: - "5.24" - "5.22" - "5.16" - "5.10" before_install: cpanm -n Devel::Cover::Report::Coveralls script: perl Build.PL && ./Build build && cover -test -report coveralls Data-Validate-Type-v1.6.0/Build.PL000066400000000000000000000035311306441476500165330ustar00rootroot00000000000000use 5.006; use strict; use warnings; use Module::Build; my $class = Module::Build->subclass( code => q| # Override 'test' to support running extended tests in the xt/ # directory. sub ACTION_test { my ( $self ) = @_; $self->recursive_test_files(1); $self->test_files( 't', 'xt' ) if $ENV{'RELEASE_TESTING'}; return $self->SUPER::ACTION_test(); } # Force running extended tests when testing the distribution. sub ACTION_disttest { my ( $self ) = @_; local $ENV{ RELEASE_TESTING } = 1; return $self->SUPER::ACTION_disttest(); } |, ); my $builder = $class->new( module_name => 'Data::Validate::Type', license => 'Perl_5', dist_author => q{Guillaume Aubert }, dist_version_from => 'lib/Data/Validate/Type.pm', build_requires => { 'Test::Exception' => 0, 'Test::FailWarnings' => 0, 'Test::More' => 0.94, # Required for subtest(). }, requires => { 'perl' => 5.006, 'Carp' => 0, 'Data::Dump' => 0, 'Exporter' => 0, 'Scalar::Util' => 1.18, # Recent 'looks_like_number'. }, add_to_cleanup => [ 'Data-Validate-Type-*', ], create_makefile_pl => 'traditional', recursive_test_files => 1, configure_requires => { 'Module::Build' => 0, }, meta_merge => { resources => { repository => 'https://github.com/guillaumeaubert/Data-Validate-Type', homepage => 'https://metacpan.org/release/Data-Validate-Type', bugtracker => 'https://github.com/guillaumeaubert/Data-Validate-Type/issues', }, no_index => { file => [ 't/LocalTest.pm', ], package => [ 'LocalTest', 'LocalTestParent', ], }, }, ); $builder->create_build_script(); Data-Validate-Type-v1.6.0/Changes000066400000000000000000000034731306441476500165370ustar00rootroot00000000000000Revision history for Data-Validate-Type v1.6.0 2017-03-21 - Relicensed under Perl 5 terms. - Cleaned up dependencies. Thank you, Justin Cook! v1.5.1 2014-06-13 - Fixed typo in documentation. v1.5.0 2014-04-29 - Added is_regex(), assert_regex(), and filter_regex(). v1.4.3 2014-04-20 - Fixed "package version matches dist version" for CPANTS. - Fixed license declared in meta files. - Switched README to Markdown. - General cleanup. v1.4.2 2013-05-01 - Fixed missing prerequisite. v1.4.1 2013-05-01 - Moved release tests to xt/, added new release tests. - Added Test::FailWarnings to all tests. - Moved request tracker from RT to GitHub. - Changed links from Search CPAN to MetaCPAN. - Updated no_index meta information. - Added information on how to contribute examples. v1.4.0 2012-11-24 - Refactored uses of Params::Util, which didn't work with Devel::Cover in taint mode. v1.3.1 2012-09-22 - Moved repository to GitHub. v1.3.0 2012-09-08 - Re-licensed as GPLv3, to allow inclusion in Fedora. v1.2.0 2012-07-27 - Added ability to validate individual elements in arrayrefs (element_validate_type). v1.1.2 2012-05-15 - Excluded non-core PerlCritic policies for tests. v1.1.1 2012-04-02 - Fixed issue in Perl 5.10 with strings passed to assert_number() in specific contexts. v1.1.0 2012-03-29 - Added is_instance(), assert_instance() and filter_instance(). v1.0.2 2012-03-09 - Fixed issue in Perl 5.8 with strings passed to assert_number() in specific contexts. v1.0.1 2012-03-07 - Refactored to use Data::Dump. - Fixed synopsis. v1.0.0 2012-03-06 - First public release. Data-Validate-Type-v1.6.0/LICENSE000066400000000000000000000436541306441476500162560ustar00rootroot00000000000000This software is copyright (c) 2012-2017 by Guillaume Aubert. This code is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself. Terms of the Perl 5 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) 2012-2017 by Guillaume Aubert. 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) 2012-2017 by Guillaume Aubert. 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 Data-Validate-Type-v1.6.0/MANIFEST000066400000000000000000000011111306441476500163600ustar00rootroot00000000000000.githooksrc .gitignore .perlcriticrc .travis.yml Build.PL Changes LICENSE MANIFEST MANIFEST.SKIP META.json META.yml Makefile.PL README.md examples/examples.txt ignore.txt lib/Data/Validate/Type.pm t/00-load.t t/10-string.t t/15-arrayref.t t/20-hashref.t t/25-coderef.t t/30-number.t t/35-instance.t t/36-instance-inheritance.t t/40-regex.t t/90-export-all.t t/91-export-boolean_functions.t t/92-export-assertions.t t/93-export-filters.t t/LocalTest.pm xt/changes.t xt/kwalitee.t xt/manifest.t xt/module_versions.t xt/mojibake.t xt/perlcritic.t xt/pod-coverage.t xt/pod.t xt/unix_eol.t Data-Validate-Type-v1.6.0/MANIFEST.SKIP000066400000000000000000000000231306441476500171260ustar00rootroot00000000000000^MYMETA.yml$ ^.git Data-Validate-Type-v1.6.0/META.json000066400000000000000000000031331306441476500166560ustar00rootroot00000000000000{ "abstract" : "Data type validation functions.", "author" : [ "Guillaume Aubert " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4205", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Data-Validate-Type", "no_index" : { "file" : [ "t/LocalTest.pm" ], "package" : [ "LocalTest", "LocalTestParent" ] }, "prereqs" : { "build" : { "requires" : { "Test::Exception" : "0", "Test::FailWarnings" : "0", "Test::More" : "0.94" } }, "configure" : { "requires" : { "Module::Build" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Data::Dump" : "0", "Exporter" : "0", "Scalar::Util" : "1.18", "perl" : "5.006" } } }, "provides" : { "Data::Validate::Type" : { "file" : "lib/Data/Validate/Type.pm", "version" : "v1.6.0" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/guillaumeaubert/Data-Validate-Type/issues" }, "homepage" : "https://metacpan.org/release/Data-Validate-Type", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "https://github.com/guillaumeaubert/Data-Validate-Type" } }, "version" : "v1.6.0" } Data-Validate-Type-v1.6.0/META.yml000066400000000000000000000017521306441476500165130ustar00rootroot00000000000000--- abstract: 'Data type validation functions.' author: - 'Guillaume Aubert ' build_requires: Test::Exception: '0' Test::FailWarnings: '0' Test::More: '0.94' configure_requires: Module::Build: '0' dynamic_config: 1 generated_by: 'Module::Build version 0.4205, CPAN::Meta::Converter version 2.140640' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Data-Validate-Type no_index: file: - t/LocalTest.pm package: - LocalTest - LocalTestParent provides: Data::Validate::Type: file: lib/Data/Validate/Type.pm version: v1.6.0 requires: Carp: '0' Data::Dump: '0' Exporter: '0' Scalar::Util: '1.18' perl: '5.006' resources: bugtracker: https://github.com/guillaumeaubert/Data-Validate-Type/issues homepage: https://metacpan.org/release/Data-Validate-Type license: http://dev.perl.org/licenses/ repository: https://github.com/guillaumeaubert/Data-Validate-Type version: v1.6.0 Data-Validate-Type-v1.6.0/Makefile.PL000066400000000000000000000012401306441476500172040ustar00rootroot00000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.4205 require 5.006; use ExtUtils::MakeMaker; WriteMakefile ( 'test' => { 'TESTS' => 't/*.t' }, 'NAME' => 'Data::Validate::Type', 'EXE_FILES' => [], 'INSTALLDIRS' => 'site', 'VERSION_FROM' => 'lib/Data/Validate/Type.pm', 'PL_FILES' => {}, 'PREREQ_PM' => { 'Scalar::Util' => '1.18', 'Test::More' => '0.94', 'Test::Exception' => 0, 'Carp' => 0, 'Exporter' => 0, 'Test::FailWarnings' => 0, 'Data::Dump' => 0 } ) ; Data-Validate-Type-v1.6.0/README.md000066400000000000000000000034331306441476500165170ustar00rootroot00000000000000Data-Validate-Type ================== [![Build Status](https://travis-ci.org/guillaumeaubert/Data-Validate-Type.svg?branch=master)](https://travis-ci.org/guillaumeaubert/Data-Validate-Type) [![Coverage Status](https://coveralls.io/repos/guillaumeaubert/Data-Validate-Type/badge.svg?branch=master)](https://coveralls.io/r/guillaumeaubert/Data-Validate-Type?branch=master) [![CPAN](https://img.shields.io/cpan/v/Data-Validate-Type.svg)](https://metacpan.org/release/Data-Validate-Type) [![License](https://img.shields.io/badge/license-Perl%205-blue.svg)](http://dev.perl.org/licenses/) Data::Validate::Type is a public interface encapsulating Params::Util to offer data type validation functions that pass PerlCritic. INSTALLATION ------------ To install this module, run the following commands: perl Build.PL ./Build ./Build test ./Build install SUPPORT AND DOCUMENTATION ------------------------- After installing, you can find documentation for this module with the perldoc command. perldoc Data::Type::Validate You can also look for information at: * [GitHub (report bugs here)] (https://github.com/guillaumeaubert/Data-Validate-Type/issues) * [AnnoCPAN, Annotated CPAN documentation] (http://annocpan.org/dist/Data-Validate-Type) * [CPAN Ratings] (http://cpanratings.perl.org/d/Data-Validate-Type) * [MetaCPAN] (https://metacpan.org/release/Data-Validate-Type) LICENSE AND COPYRIGHT --------------------- Copyright (C) 2012-2017 Guillaume Aubert. This code is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself. 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 LICENSE file for more details. Data-Validate-Type-v1.6.0/examples/000077500000000000000000000000001306441476500170535ustar00rootroot00000000000000Data-Validate-Type-v1.6.0/examples/examples.txt000066400000000000000000000007631306441476500214400ustar00rootroot00000000000000To see examples for this distribution, it is recommended you read the test scripts included under ./t, which cover the basic usage of the modules. If you have any example scripts that use the distribution in interesting ways or make good use of the features available, please feel free to submit one (preferably with a pull request on GitHub). Important: note that any script you submit will be bundled into the distribution with the same license as the distribution itself. Thank you, Guillaume Data-Validate-Type-v1.6.0/ignore.txt000066400000000000000000000002001306441476500172510ustar00rootroot00000000000000blib* Makefile Makefile.old Build Build.bat _build* pm_to_blib* *.tar.gz .lwpcookies cover_db pod2htm*.tmp Data-Validate-Type-* Data-Validate-Type-v1.6.0/lib/000077500000000000000000000000001306441476500160035ustar00rootroot00000000000000Data-Validate-Type-v1.6.0/lib/Data/000077500000000000000000000000001306441476500166545ustar00rootroot00000000000000Data-Validate-Type-v1.6.0/lib/Data/Validate/000077500000000000000000000000001306441476500204055ustar00rootroot00000000000000Data-Validate-Type-v1.6.0/lib/Data/Validate/Type.pm000066400000000000000000000475231306441476500216770ustar00rootroot00000000000000package Data::Validate::Type; use warnings; use strict; use base 'Exporter'; use Carp; use Data::Dump qw(); use Scalar::Util qw(); my @boolean_functions_list = qw( is_string is_arrayref is_hashref is_coderef is_number is_instance is_regex ); my @assertion_functions_list = qw( assert_string assert_arrayref assert_hashref assert_coderef assert_number assert_instance assert_regex ); my @filtering_functions_list = qw( filter_string filter_arrayref filter_hashref filter_coderef filter_number filter_instance filter_regex ); our @EXPORT_OK = ( @boolean_functions_list, @assertion_functions_list, @filtering_functions_list, ); our %EXPORT_TAGS = ( boolean_tests => \@boolean_functions_list, assertions => \@assertion_functions_list, filters => \@filtering_functions_list, all => [ @boolean_functions_list, @assertion_functions_list, @filtering_functions_list, ], ); =head1 NAME Data::Validate::Type - Data type validation functions. =head1 VERSION Version 1.6.0 =cut our $VERSION = '1.6.0'; =head1 SYNOPSIS # Call with explicit package name. use Data::Validate::Type; if ( Data::Validate::Type::is_string( 'test' ) ) { # ... } # Import specific functions. use Data::Validate::Type qw( is_string ); if ( is_string( 'test' ) ) { # ... } # Import functions for a given paradigm. use Data::Validate::Type qw( :boolean_tests ); if ( is_string( 'test' ) ) { # ... } =head1 DESCRIPTION L is a wonderful module, but suffers from a few drawbacks: =over 4 =item * Function names start with an underscore, which is usually used to indicate private functions. =item * Function names are uppercase, which is usually used to indicate file handles or constants. =item * Function names don't pass PerlCritic's validation, making them problematic to import. =item * Functions use by default the convention that collection that collections need to not be empty to be valid (see _ARRAY0/_ARRAY for example), which is counter-intuitive. =item * In Pure Perl mode, the functions are created via eval, which causes issues for L in taint mode. =back Those drawbacks are purely cosmetic and don't affect the usefulness of the functions, except for the last one. This module used to encapsulate L, but I had to refactor it out to fix the issues with L. Please note that I prefer long function names that are descriptive, to arcane short ones. This increases readability, and the bulk of the typing can be spared with the use of a good IDE like Padre. Also, this is work in progress - There is more functions that should be added here, if you need one in particular feel free to contact me. =head1 BOOLEAN TEST FUNCTIONS Functions in this group return a boolean to indicate whether the parameters passed match the test(s) specified by the functions or not. All the boolean functions can be imported at once in your namespace with the following line: use Data::Validate::Type qw( :boolean_tests ); =head2 is_string() Return a boolean indicating if the variable passed is a string. my $is_string = Data::Validate::Type::is_string( $variable ); Note: 0 and '' (empty string) are valid strings. Parameters: =over 4 =item * allow_empty Boolean, default 1. Allow the string to be empty or not. =back =cut sub is_string { my ( $variable, %args ) = @_; # Check parameters. my $allow_empty = delete( $args{'allow_empty'} ); $allow_empty = 1 unless defined( $allow_empty ); croak 'Arguments not recognized: ' . Data::Dump::dump( %args ) unless scalar( keys %args ) == 0; # Check variable. return 0 if !defined( $variable ) || ref( $variable ); # Check length if we don't allow empty strings. return 0 if !$allow_empty && length( $variable ) == 0; return 1; } =head2 is_arrayref() Return a boolean indicating if the variable passed is an arrayref that can be dereferenced into an array. my $is_arrayref = Data::Validate::Type::is_arrayref( $variable ); my $is_arrayref = Data::Validate::Type::is_arrayref( $variable, allow_empty => 1, no_blessing => 0, ); # Check if the variable is an arrayref of hashrefs. my $is_arrayref = Data::Validate::Type::is_arrayref( $variable, allow_empty => 1, no_blessing => 0, element_validate_type => sub { return Data::Validate::Type::is_hashref( $_[0] ); }, ); Parameters: =over 4 =item * allow_empty Boolean, default 1. Allow the array to be empty or not. =item * no_blessing Boolean, default 0. Require that the variable is not blessed. =item * element_validate_type None by default. Set it to a coderef to validate the elements in the array. The coderef will be passed the element to validate as first parameter, and it must return a boolean indicating whether the element was valid or not. =back =cut sub is_arrayref { my ( $variable, %args ) = @_; # Check parameters. my $allow_empty = delete( $args{'allow_empty'} ); $allow_empty = 1 unless defined( $allow_empty ); my $no_blessing = delete( $args{'no_blessing'} ) || 0; my $element_validate_type = delete( $args{'element_validate_type'} ); croak '"element_validate_type" must be a coderef' if defined( $element_validate_type ) && !is_coderef( $element_validate_type ); croak 'Arguments not recognized: ' . Data::Dump::dump( %args ) unless scalar( keys %args ) == 0; # Check variable. return 0 if !defined( $variable ) || !ref( $variable ); if ( $no_blessing ) { # The variable must be a standard arrayref. return 0 if ref( $variable ) ne 'ARRAY'; } else { # Check that the variable is either an array or allows # dereferencing as one. return 0 if ! ( ( Scalar::Util::reftype( $variable ) eq 'ARRAY' ) || overload::Method( $variable, '@{}' ) ); } # Check size of the array if we require a non-empty array. return 0 if !$allow_empty && scalar( @$variable ) == 0; # If we have an element validator specified, now that we know that we have # an array, it's a good time to test the individual elements. if ( defined( $element_validate_type ) ) { foreach my $element ( @$variable ) { return 0 if !$element_validate_type->( $element ); } } return 1; } =head2 is_hashref() Return a boolean indicating if the variable passed is a hashref that can be dereferenced into a hash. my $is_hashref = Data::Validate::Type::is_hashref( $variable ); my $is_hashref = Data::Validate::Type::is_hashref( $variable, allow_empty => 1, no_blessing => 0, ); Parameters: =over 4 =item * allow_empty Boolean, default 1. Allow the array to be empty or not. =item * no_blessing Boolean, default 0. Require that the variable is not blessed. =back =cut sub is_hashref { my ( $variable, %args ) = @_; # Check parameters. my $allow_empty = delete( $args{'allow_empty'} ); $allow_empty = 1 unless defined( $allow_empty ); my $no_blessing = delete( $args{'no_blessing'} ) || 0; croak 'Arguments not recognized: ' . Data::Dump::dump( %args ) unless scalar( keys %args ) == 0; # Check variable. return 0 if !defined( $variable ) || !ref( $variable ); if ( $no_blessing ) { # The variable must be a standard hashref. return 0 if ref( $variable ) ne 'HASH'; } else { # Check that the variable is either a hashref or allows dereferencing # as one. return 0 if ! ( ( Scalar::Util::reftype( $variable ) eq 'HASH' ) || overload::Method( $variable, '%{}' ) ); } # If we don't allow empty hashes, check keys. return 0 if !$allow_empty && scalar( keys %$variable ) == 0; return 1; } =head2 is_coderef() Return a boolean indicating if the variable passed is an coderef that can be dereferenced into a block of code. my $is_coderef = Data::Validate::Type::is_coderef( $variable ); =cut sub is_coderef { my ( $variable, %args ) = @_; # Check parameters. croak 'Arguments not recognized: ' . Data::Dump::dump( %args ) unless scalar( keys %args ) == 0; # Check variable. return 0 if !defined( $variable ) || !ref( $variable ); return 0 if ref( $variable ) ne 'CODE'; return 1; } =head2 is_number() Return a boolean indicating if the variable passed is a number. my $is_number = Data::Validate::Type::is_number( $variable ); my $is_number = Data::Validate::Type::is_number( $variable, positive => 1, ); my $is_number = Data::Validate::Type::is_number( $variable, strictly_positive => 1, ); Parameters: =over 4 =item * strictly_positive Boolean, default 0. Set to 1 to check for a strictly positive number. =item * positive Boolean, default 0. Set to 1 to check for a positive number. =back =cut sub is_number { my ( $variable, %args ) = @_; # Check parameters. my $positive = delete( $args{'positive'} ) || 0; my $strictly_positive = delete( $args{'strictly_positive'} ) || 0; croak 'Arguments not recognized: ' . Data::Dump::dump( %args ) unless scalar( keys %args ) == 0; # Check variable. return 0 if !defined( $variable ) || ref( $variable ); # Requires Scalar::Util v1.18 or higher. return 0 if !Scalar::Util::looks_like_number( $variable ); # Check extra restrictions. return 0 if $positive && $variable < 0; return 0 if $strictly_positive && $variable <= 0; return 1; } =head2 is_instance() Return a boolean indicating if the variable is an instance of the given class. Note that this handles inheritance properly, so it will return true if the variable is an instance of a subclass of the class given. my $is_instance = Data::Validate::Type::is_instance( $variable, class => $class, ); Parameters: =over 4 =item * class Required, the name of the class to check the variable against. =back =cut sub is_instance { my ( $variable, %args ) = @_; # Check parameters. my $class = delete( $args{'class'} ); croak 'A class argument is required' if !defined( $class ) || $class eq ''; croak 'Arguments not recognized: ' . Data::Dump::dump( %args ) unless scalar( keys %args ) == 0; # Check variable. return 0 if !defined( $variable ) || !Scalar::Util::blessed( $variable ); # Test that the object is a member if the class. return 0 if !$variable->isa( $class ); return 1; } =head2 is_regex() Return a boolean indicating if the variable is a regular expression. my $is_regex = Data::Validate::Type::is_regex( $variable ); =cut sub is_regex { my ( $variable ) = @_; # Check variable. return defined( $variable ) && ( ref( $variable ) eq 'Regexp' ) ? 1 : 0; } =head1 ASSERTION-BASED FUNCTIONS Functions in this group do not return anything, but will die when the parameters passed don't match the test(s) specified by the functions. All the assertion test functions can be imported at once in your namespace with the following line: use Data::Validate::Type qw( :assertions ); =head2 assert_string() Die unless the variable passed is a string. Data::Validate::Type::assert_string( $variable ); Note: 0 and '' (empty string) are valid strings. Parameters: =over 4 =item * allow_empty Boolean, default 1. Allow the string to be empty or not. =back =cut sub assert_string { my ( $variable, %args ) = @_; croak 'Not a string' unless is_string( $variable, %args ); return; } =head2 assert_arrayref() Die unless the variable passed is an arrayref that can be dereferenced into an array. Data::Validate::Type::assert_arrayref( $variable ); Data::Validate::Type::assert_arrayref( $variable, allow_empty => 1, no_blessing => 0, ); # Require the variable to be an arrayref of hashrefs. Data::Validate::Type::assert_arrayref( $variable, allow_empty => 1, no_blessing => 0, element_validate_type => sub { return Data::Validate::Type::is_hashref( $_[0] ); }, ); Parameters: =over 4 =item * allow_empty Boolean, default 1. Allow the array to be empty or not. =item * no_blessing Boolean, default 0. Require that the variable is not blessed. =item * element_validate_type None by default. Set it to a coderef to validate the elements in the array. The coderef will be passed the element to validate as first parameter, and it must return a boolean indicating whether the element was valid or not. =back =cut sub assert_arrayref { my ( $variable, %args ) = @_; croak 'Not an arrayref' unless is_arrayref( $variable, %args ); return; } =head2 assert_hashref() Die unless the variable passed is a hashref that can be dereferenced into a hash. Data::Validate::Type::assert_hashref( $variable ); Data::Validate::Type::assert_hashref( $variable, allow_empty => 1, no_blessing => 0, ); Parameters: =over 4 =item * allow_empty Boolean, default 1. Allow the array to be empty or not. =item * no_blessing Boolean, default 0. Require that the variable is not blessed. =back =cut sub assert_hashref { my ( $variable, %args ) = @_; croak 'Not a hashref' unless is_hashref( $variable, %args ); return; } =head2 assert_coderef() Die unless the variable passed is an coderef that can be dereferenced into a block of code. Data::Validate::Type::assert_coderef( $variable ); =cut sub assert_coderef { my ( $variable, %args ) = @_; croak 'Not a coderef' unless is_coderef( $variable, %args ); return; } =head2 assert_number() Die unless the variable passed is a number. Data::Validate::Type::assert_number( $variable ); Data::Validate::Type::assert_number( $variable, positive => 1, ); Data::Validate::Type::assert_number( $variable, strictly_positive => 1, ); Parameters: =over 4 =item * strictly_positive Boolean, default 0. Set to 1 to check for a strictly positive number. =item * positive Boolean, default 0. Set to 1 to check for a positive number. =back =cut sub assert_number { my ( $variable, %args ) = @_; croak 'Not a number' unless is_number( $variable, %args ); return; } =head2 assert_instance() Die unless the variable is an instance of the given class. Note that this handles inheritance properly, so it will not die if the variable is an instance of a subclass of the class given. Data::Validate::Type::assert_instance( $variable, class => $class, ); Parameters: =over 4 =item * class Required, the name of the class to check the variable against. =back =cut sub assert_instance { my ( $variable, %args ) = @_; croak 'Not an instance of the class' unless is_instance( $variable, %args ); return; } =head2 assert_regex() Die unless the variable is a regular expression. Data::Validate::Type::assert_regex( $variable ); =cut sub assert_regex { my ( $variable ) = @_; croak 'Not a regular expression' unless is_regex( $variable ); return; } =head1 FILTERING FUNCTIONS Functions in this group return the variable tested against when it matches the test(s) specified by the functions. All the filtering functions can be imported at once in your namespace with the following line: use Data::Validate::Type qw( :filters ); =head2 filter_string() Return the variable passed if it is a string, otherwise return undef. Data::Validate::Type::filter_string( $variable ); Note: 0 and '' (empty string) are valid strings. Parameters: =over 4 =item * allow_empty Boolean, default 1. Allow the string to be empty or not. =back =cut sub filter_string { my ( $variable, %args ) = @_; return is_string( $variable, %args ) ? $variable : undef; } =head2 filter_arrayref() Return the variable passed if it is an arrayref that can be dereferenced into an array, otherwise undef. Data::Validate::Type::filter_arrayref( $variable ); Data::Validate::Type::filter_arrayref( $variable, allow_empty => 1, no_blessing => 0, ); # Only return the variable if it is an arrayref of hashrefs. Data::Validate::Type::filter_arrayref( $variable, allow_empty => 1, no_blessing => 0, element_validate_type => sub { return Data::Validate::Type::is_hashref( $_[0] ); }, ); Parameters: =over 4 =item * allow_empty Boolean, default 1. Allow the array to be empty or not. =item * no_blessing Boolean, default 0. Require that the variable is not blessed. =item * element_validate_type None by default. Set it to a coderef to validate the elements in the array. The coderef will be passed the element to validate as first parameter, and it must return a boolean indicating whether the element was valid or not. =back =cut sub filter_arrayref { my ( $variable, %args ) = @_; return is_arrayref( $variable, %args ) ? $variable : undef; } =head2 filter_hashref() Return the variable passed if it is a hashref that can be dereferenced into a hash, otherwise return undef. Data::Validate::Type::filter_hashref( $variable ); Data::Validate::Type::filter_hashref( $variable, allow_empty => 1, no_blessing => 0, ); Parameters: =over 4 =item * allow_empty Boolean, default 1. Allow the array to be empty or not. =item * no_blessing Boolean, default 0. Require that the variable is not blessed. =back =cut sub filter_hashref { my ( $variable, %args ) = @_; return is_hashref( $variable, %args ) ? $variable : undef; } =head2 filter_coderef() Return the variable passed if it is a coderef that can be dereferenced into a block of code, otherwise return undef. Data::Validate::Type::filter_coderef( $variable ); =cut sub filter_coderef { my ( $variable, %args ) = @_; return is_coderef( $variable, %args ) ? $variable : undef; } =head2 filter_number() Return the variable passed if it is a number, otherwise return undef. Data::Validate::Type::filter_number( $variable ); Data::Validate::Type::filter_number( $variable, positive => 1, ); Data::Validate::Type::filter_number( $variable, strictly_positive => 1, ); Parameters: =over 4 =item * strictly_positive Boolean, default 0. Set to 1 to check for a strictly positive number. =item * positive Boolean, default 0. Set to 1 to check for a positive number. =back =cut sub filter_number { my ( $variable, %args ) = @_; return is_number( $variable, %args ) ? $variable : undef; } =head2 filter_instance() Return the variable passed if it is an instance of the given class. Note that this handles inheritance properly, so it will return the variable if it is an instance of a subclass of the class given. Data::Validate::Type::filter_instance( $variable, class => $class, ); Parameters: =over 4 =item * class Required, the name of the class to check the variable against. =back =cut sub filter_instance { my ( $variable, %args ) = @_; return is_instance( $variable, %args ) ? $variable : undef; } =head2 filter_regex() Return the variable passed if it is a regular expression. Data::Validate::Type::filter_regex( $variable ); =cut sub filter_regex { my ( $variable ) = @_; return is_regex( $variable ) ? $variable : undef; } =head1 BUGS Please report any bugs or feature requests through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Data::Validate::Type You can also look for information at: =over 4 =item * GitHub (report bugs there) L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * MetaCPAN L =back =head1 AUTHOR L, C<< >>. =head1 ACKNOWLEDGEMENTS Thanks to Adam Kennedy for writing L. This module started as an encapsulation for Params::Util and I learnt quite a bit from it. =head1 COPYRIGHT & LICENSE Copyright 2012-2017 Guillaume Aubert. This code is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself. 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 LICENSE file for more details. =cut 1; Data-Validate-Type-v1.6.0/t/000077500000000000000000000000001306441476500155005ustar00rootroot00000000000000Data-Validate-Type-v1.6.0/t/00-load.t000066400000000000000000000003361306441476500170230ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::FailWarnings; use Test::More tests => 1; BEGIN { use_ok( 'Data::Validate::Type' ); } diag( "Testing Data::Validate::Type $Data::Validate::Type::VERSION, Perl $], $^X" ); Data-Validate-Type-v1.6.0/t/10-string.t000066400000000000000000000040001306441476500174030ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::FailWarnings; use Test::More tests => 3; use lib 't/'; use LocalTest; my $tests = [ { 'function_name' => 'is_string', 'function_type' => 'boolean', }, { 'function_name' => 'assert_string', 'function_type' => 'assert', }, { 'function_name' => 'filter_string', 'function_type' => 'filter', }, ]; foreach my $test ( @$tests ) { my $function_name = delete( $test->{'function_name'} ); my $function_type = delete( $test->{'function_type'} ); subtest( "Test function $function_name (type $function_type).", sub { plan( tests => 3 ); subtest( 'Test without arguments.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, pass_tests => [ qw( empty_string zero one string strictly_positive_integer strictly_negative_integer strictly_positive_float strictly_negative_float ) ], ); } ); subtest( 'Test with allow_empty=1.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { allow_empty => 1, }, pass_tests => [ qw( empty_string zero one string strictly_positive_integer strictly_negative_integer strictly_positive_float strictly_negative_float ) ], ); } ); subtest( 'Test with allow_empty=0.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { allow_empty => 0, }, pass_tests => [ qw( zero one string strictly_positive_integer strictly_negative_integer strictly_positive_float strictly_negative_float ) ], ); } ); } ); } Data-Validate-Type-v1.6.0/t/15-arrayref.t000066400000000000000000000062631306441476500177320ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Data::Validate::Type; use Test::FailWarnings; use Test::More tests => 3; use lib 't/'; use LocalTest; my $tests = [ { 'function_name' => 'is_arrayref', 'function_type' => 'boolean', }, { 'function_name' => 'assert_arrayref', 'function_type' => 'assert', }, { 'function_name' => 'filter_arrayref', 'function_type' => 'filter', }, ]; foreach my $test ( @$tests ) { my $function_name = delete( $test->{'function_name'} ); my $function_type = delete( $test->{'function_type'} ); subtest( "Test function $function_name (type $function_type).", sub { plan( tests => 6 ); subtest ( 'Test without arguments.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, pass_tests => [ qw( empty_arrayref non_empty_arrayref blessed_arrayref arrayref_of_hashrefs arrayref_of_mixed_data ) ], ); } ); subtest ( 'Test with allow_empty=1.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { allow_empty => 1, }, pass_tests => [ qw( empty_arrayref non_empty_arrayref blessed_arrayref arrayref_of_hashrefs arrayref_of_mixed_data ) ], ); } ); subtest( 'Test with allow_empty=0.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { allow_empty => 0, }, pass_tests => [ qw( non_empty_arrayref blessed_arrayref arrayref_of_hashrefs arrayref_of_mixed_data ) ], ); } ); subtest( 'Test with no_blessing=1.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { no_blessing => 1, }, pass_tests => [ qw( empty_arrayref non_empty_arrayref arrayref_of_hashrefs arrayref_of_mixed_data ) ], ); } ); subtest( 'Test with no_blessing=0.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { no_blessing => 0, }, pass_tests => [ qw( empty_arrayref non_empty_arrayref blessed_arrayref arrayref_of_hashrefs arrayref_of_mixed_data ) ], ); } ); subtest( 'Test element_validate_type with a hashref.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { element_validate_type => sub { return Data::Validate::Type::is_hashref( $_[0] ); }, }, pass_tests => [ qw( empty_arrayref arrayref_of_hashrefs ) ], ); } ); } ); } Data-Validate-Type-v1.6.0/t/20-hashref.t000066400000000000000000000046071306441476500175330ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::FailWarnings; use Test::More tests => 3; use lib 't/'; use LocalTest; my $tests = [ { 'function_name' => 'is_hashref', 'function_type' => 'boolean', }, { 'function_name' => 'assert_hashref', 'function_type' => 'assert', }, { 'function_name' => 'filter_hashref', 'function_type' => 'filter', }, ]; foreach my $test ( @$tests ) { my $function_name = delete( $test->{'function_name'} ); my $function_type = delete( $test->{'function_type'} ); subtest( "Test function $function_name (type $function_type).", sub { plan( tests => 5 ); subtest ( 'Test without arguments.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, pass_tests => [ qw( empty_hashref non_empty_hashref blessed_hashref ) ], ); } ); subtest ( 'Test with allow_empty=1.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { allow_empty => 1, }, pass_tests => [ qw( empty_hashref non_empty_hashref blessed_hashref ) ], ); } ); subtest( 'Test with allow_empty=0.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { allow_empty => 0, }, pass_tests => [ qw( non_empty_hashref blessed_hashref ) ], ); } ); subtest( 'Test with no_blessing=1.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { no_blessing => 1, }, pass_tests => [ qw( empty_hashref non_empty_hashref ) ], ); } ); subtest( 'Test with no_blessing=0.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { no_blessing => 0, }, pass_tests => [ qw( empty_hashref non_empty_hashref blessed_hashref ) ], ); } ); } ); } Data-Validate-Type-v1.6.0/t/25-coderef.t000066400000000000000000000016001306441476500175150ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::FailWarnings; use Test::More tests => 3; use lib 't/'; use LocalTest; my $tests = [ { 'function_name' => 'is_coderef', 'function_type' => 'boolean', }, { 'function_name' => 'assert_coderef', 'function_type' => 'assert', }, { 'function_name' => 'filter_coderef', 'function_type' => 'filter', }, ]; foreach my $test ( @$tests ) { my $function_name = delete( $test->{'function_name'} ); my $function_type = delete( $test->{'function_type'} ); subtest( "Test function $function_name (type $function_type).", sub { plan( tests => 1 ); subtest( 'Test without arguments.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, pass_tests => [ qw( unnamed_subroutine ) ], ); } ); } ); } Data-Validate-Type-v1.6.0/t/30-number.t000066400000000000000000000053261306441476500174030ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::FailWarnings; use Test::More tests => 3; use lib 't/'; use LocalTest; my $tests = [ { 'function_name' => 'is_number', 'function_type' => 'boolean', }, { 'function_name' => 'assert_number', 'function_type' => 'assert', }, { 'function_name' => 'filter_number', 'function_type' => 'filter', }, ]; foreach my $test ( @$tests ) { my $function_name = delete( $test->{'function_name'} ); my $function_type = delete( $test->{'function_type'} ); subtest( "Test function $function_name (type $function_type).", sub { plan( tests => 5 ); subtest ( 'Test without arguments.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, pass_tests => [ qw( zero one strictly_positive_integer strictly_negative_integer strictly_positive_float strictly_negative_float ) ], ); } ); subtest ( 'Test with positive=1.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { positive => 1, }, pass_tests => [ qw( zero one strictly_positive_integer strictly_positive_float ) ], ); } ); subtest( 'Test with positive=0.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { positive => 0, }, pass_tests => [ qw( zero one strictly_positive_integer strictly_negative_integer strictly_positive_float strictly_negative_float ) ], ); } ); subtest( 'Test with strictly_positive=1.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { strictly_positive => 1, }, pass_tests => [ qw( one strictly_positive_integer strictly_positive_float ) ], ); } ); subtest( 'Test with strictly_positive=0.', sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, function_args => { strictly_positive => 0, }, pass_tests => [ qw( zero one strictly_positive_integer strictly_negative_integer strictly_positive_float strictly_negative_float ) ], ); } ); } ); } Data-Validate-Type-v1.6.0/t/35-instance.t000066400000000000000000000045111306441476500177170ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::Exception; use Test::FailWarnings; use Test::More tests => 5; use lib 't/'; use LocalTest; # Make sure the class argument is required. subtest ( 'The class argument cannot be undef.', sub { plan( tests => 2 ); dies_ok( sub { Data::Validate::Type::is_instance( {} ); }, 'is_instance() croaks.', ); like( $@, qr/A class argument is required/, 'The error message indicates that class is a required argument.', ); } ); subtest ( 'The class argument cannot be an empty string.', sub { plan( tests => 2 ); dies_ok( sub { Data::Validate::Type::is_instance( {}, class => '' ); }, 'is_instance() croaks.', ); like( $@, qr/A class argument is required/, 'The error message indicates that class is a required argument.', ); } ); # Regular tests. my $tests = [ { 'function_name' => 'is_instance', 'function_type' => 'boolean', }, { 'function_name' => 'assert_instance', 'function_type' => 'assert', }, { 'function_name' => 'filter_instance', 'function_type' => 'filter', }, ]; foreach my $test ( @$tests ) { my $function_name = delete( $test->{'function_name'} ); my $function_type = delete( $test->{'function_type'} ); subtest( "Test function $function_name (type $function_type).", sub { plan( tests => 3 ); subtest( 'Test without arguments.', sub { LocalTest::ok_run_tests( function_name => $function_name, function_args => { class => 'InvalidClass', }, type => $function_type, pass_tests => [], ); } ); subtest( 'Test with class=TestArrayBless.', sub { LocalTest::ok_run_tests( function_name => $function_name, function_args => { class => 'TestArrayBless', }, type => $function_type, pass_tests => [ qw( blessed_arrayref ) ], ); } ); subtest( 'Test with class=TestHashBless.', sub { LocalTest::ok_run_tests( function_name => $function_name, function_args => { class => 'TestHashBless', }, type => $function_type, pass_tests => [ qw( blessed_hashref ) ], ); } ); } ); } Data-Validate-Type-v1.6.0/t/36-instance-inheritance.t000066400000000000000000000012531306441476500222070ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Data::Validate::Type; use Test::FailWarnings; use Test::More tests => 2; my $variable = LocalTestChild->new(); ok( Data::Validate::Type::is_instance( $variable, class => 'LocalTestChild', ), 'The variable is an instance of its class.', ); ok( Data::Validate::Type::is_instance( $variable, class => 'LocalTestParent', ), 'The variable is an instance of its parent class.', ); package LocalTestParent; use strict; use warnings; sub new { return bless( {}, 'LocalTestParent' ); } 1; package LocalTestChild; use strict; use warnings; use base 'LocalTestParent'; sub new { return bless( {}, 'LocalTestChild' ); } 1; Data-Validate-Type-v1.6.0/t/40-regex.t000066400000000000000000000014161306441476500172220ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::FailWarnings; use Test::More tests => 3; use lib 't/'; use LocalTest; my $tests = [ { 'function_name' => 'is_regex', 'function_type' => 'boolean', }, { 'function_name' => 'assert_regex', 'function_type' => 'assert', }, { 'function_name' => 'filter_regex', 'function_type' => 'filter', }, ]; foreach my $test ( @$tests ) { my $function_name = delete( $test->{'function_name'} ); my $function_type = delete( $test->{'function_type'} ); subtest( "Test function $function_name (type $function_type).", sub { LocalTest::ok_run_tests( function_name => $function_name, type => $function_type, pass_tests => [ qw( empty_regex regex ) ], ); } ); } Data-Validate-Type-v1.6.0/t/90-export-all.t000066400000000000000000000013551306441476500202060ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::FailWarnings; use Test::More; my $expect_exported = { is_string => 1, is_arrayref => 1, is_hashref => 1, is_coderef => 1, is_number => 1, assert_string => 1, assert_arrayref => 1, assert_hashref => 1, assert_coderef => 1, assert_number => 1, filter_string => 1, filter_arrayref => 1, filter_hashref => 1, filter_coderef => 1, filter_number => 1, }; plan( tests => scalar( keys %$expect_exported ) + 1 ); use_ok( 'Data::Validate::Type', ':all' ); while ( my ( $function, $exported ) = each( %$expect_exported ) ) { is( defined( &$function ) ? 1 : 0, $exported, "Function $function " . ( $exported ? "is" : "isn't") . " imported.", ); } Data-Validate-Type-v1.6.0/t/91-export-boolean_functions.t000066400000000000000000000013671306441476500231510ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::FailWarnings; use Test::More; my $expect_exported = { is_string => 1, is_arrayref => 1, is_hashref => 1, is_coderef => 1, is_number => 1, assert_string => 0, assert_arrayref => 0, assert_hashref => 0, assert_coderef => 0, assert_number => 0, filter_string => 0, filter_arrayref => 0, filter_hashref => 0, filter_coderef => 0, filter_number => 0, }; plan( tests => scalar( keys %$expect_exported ) + 1 ); use_ok( 'Data::Validate::Type', ':boolean_tests' ); while ( my ( $function, $exported ) = each( %$expect_exported ) ) { is( defined( &$function ) ? 1 : 0, $exported, "Function $function " . ( $exported ? "is" : "isn't") . " imported.", ); } Data-Validate-Type-v1.6.0/t/92-export-assertions.t000066400000000000000000000013641306441476500216320ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::FailWarnings; use Test::More; my $expect_exported = { is_string => 0, is_arrayref => 0, is_hashref => 0, is_coderef => 0, is_number => 0, assert_string => 1, assert_arrayref => 1, assert_hashref => 1, assert_coderef => 1, assert_number => 1, filter_string => 0, filter_arrayref => 0, filter_hashref => 0, filter_coderef => 0, filter_number => 0, }; plan( tests => scalar( keys %$expect_exported ) + 1 ); use_ok( 'Data::Validate::Type', ':assertions' ); while ( my ( $function, $exported ) = each( %$expect_exported ) ) { is( defined( &$function ) ? 1 : 0, $exported, "Function $function " . ( $exported ? "is" : "isn't") . " imported.", ); } Data-Validate-Type-v1.6.0/t/93-export-filters.t000066400000000000000000000013611306441476500211060ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::FailWarnings; use Test::More; my $expect_exported = { is_string => 0, is_arrayref => 0, is_hashref => 0, is_coderef => 0, is_number => 0, assert_string => 0, assert_arrayref => 0, assert_hashref => 0, assert_coderef => 0, assert_number => 0, filter_string => 1, filter_arrayref => 1, filter_hashref => 1, filter_coderef => 1, filter_number => 1, }; plan( tests => scalar( keys %$expect_exported ) + 1 ); use_ok( 'Data::Validate::Type', ':filters' ); while ( my ( $function, $exported ) = each( %$expect_exported ) ) { is( defined( &$function ) ? 1 : 0, $exported, "Function $function " . ( $exported ? "is" : "isn't") . " imported.", ); } Data-Validate-Type-v1.6.0/t/LocalTest.pm000066400000000000000000000151221306441476500177310ustar00rootroot00000000000000package LocalTest; use strict; use warnings; use Carp; use Data::Dump; use Data::Validate::Type; use Test::Exception; use Test::More; =head1 NAME LocalTest - Test data and functions for L. =head1 VERSION Version 1.6.0 =cut our $VERSION = '1.6.0'; =head1 SYNOPSIS my $tests = LocalTest::get_tests(); =head1 DESCRIPTION =cut my $test_data = [ { key => 'undef', data => undef, }, { key => 'empty_hashref', data => {}, }, { key => 'non_empty_hashref', data => { foo => 1 }, }, { key => 'unnamed_subroutine', data => sub () { 1 }, }, { key => 'empty_arrayref', data => [], }, { key => 'non_empty_arrayref', data => [ 1, 2, 3 ], }, { key => 'empty_string_ref', data => \"", }, { key => 'string_ref', data => \"foo", }, { key => 'empty_string', data => '', }, { key => 'zero', data => 0, }, { key => 'one', data => 1, }, { key => 'string', data => 'a test string', }, { key => 'blessed_arrayref', data => bless( [ 1, 2, 3 ], 'TestArrayBless', ), }, { key => 'blessed_hashref', data => bless( { 'key' => 'value' }, 'TestHashBless', ), }, { key => 'strictly_positive_integer', data => 10, }, { key => 'strictly_negative_integer', data => -10, }, { key => 'strictly_positive_float', data => 10.12345678, }, { key => 'strictly_negative_float', data => -10.12345678, }, { key => 'arrayref_of_hashrefs', data => [ {}, { test => 1, }, bless( { 'key' => 'value', }, 'TestHashBless', ), ], }, { key => 'arrayref_of_mixed_data', data => [ {}, { test => 1, }, [], ], }, { key => 'regex', data => qr/test/, }, { key => 'empty_regex', data => qr/test/, }, ]; =head1 FUNCTIONS =head2 get_tests() Return the test cases available. my $tests = LocalTest::get_tests(); =cut sub get_tests { return $test_data; } =head2 ok_run_tests() Run the tests for a given function and type. LocalTest::ok_run_tests( function_name => 'is_string', type => 'boolean', function_args => { allow_empty => 1, }, pass_tests => [ qw( empty_string zero one string strictly_positive_integer strictly_negative_integer strictly_positive_float strictly_negative_float ) ], ); Parameters: =over 4 =item * function_name The name of the function to test. Must be a valid function of C. =item * type The type of the function. Accepted values are 'boolean', 'assert', and 'filter'. It is important to set this properly, otherwise the test function won't know how to evaluate the output of the function tested. =item * function_args A hashref of arguments to pass to the function to test when executing the calls to it. =item * pass_tests The arrayref of test cases that the function to test is expected to pass. See C for a list of all the test cases available. By extension, all the test cases not listed in this list are expected to fail. =back =cut sub ok_run_tests { my ( %args ) = @_; my $function_name = delete( $args{'function_name'} ); my $function_args = delete( $args{'function_args'} ) || {}; my $type = delete( $args{'type'} ); my $pass_tests = delete( $args{'pass_tests'} ); # Verify parameters. croak "The argument 'function_name' must be defined" if !defined( $function_name ) || $function_name eq ''; croak "The argument 'type' must be defined" if !defined( $type ) || $type eq ''; croak "The argument 'type' is not valid" if $type !~ /^(?:boolean|assert|filter)$/; croak "The argument 'pass_tests' must be defined" if !defined( $pass_tests ); my $function = $Data::Validate::Type::{$function_name}; my $tests = LocalTest::get_tests(); unless ( Test::More->builder()->has_plan() ) { plan( defined( $tests ) && scalar( @$tests ) != 0 ? ( tests => scalar( @$tests ) ) : ( skip_all => 'No test cases found, cannot run tests.' ) ); } foreach my $test ( @$tests ) { my $data = $test->{'data'}; my $key = $test->{'key'}; my $expected_success = scalar( grep { $_ eq $key } @$pass_tests ) != 0 ? 1 : 0; if ( $type eq 'boolean' ) { is( $function->( $data, %$function_args ), $expected_success, "$function_name( " . Data::Dump::dump( $data ) . ' ) returns ' . ( $expected_success ? 'true' : 'false' ) . '.', ) || diag( "Failed test '$key'." ); } elsif ( $type eq 'assert' ) { if ( $expected_success ) { lives_ok( sub { $function->( $data, %$function_args ); }, "$function_name( " . Data::Dump::dump( $data ) . ' )', ) || diag( "Failed test '$key'." ); } else { dies_ok( sub { $function->( $data, %$function_args ); }, "$function_name( " . Data::Dump::dump( $data ) . ' )', ) || diag( "Failed test '$key'." ); } } elsif ( $type eq 'filter' ) { is_deeply( $function->( $data, %$function_args ), $expected_success ? $data : undef, "$function_name( " . Data::Dump::dump( $data ) . ' )', ) || diag( "Failed test '$key'." ); } } return; } =head1 AUTHOR Guillaume Aubert, C<< >>. =head1 BUGS Please report any bugs or feature requests through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc LocalTest You can also look for information at: =over 4 =item * GitHub (report bugs there) L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * MetaCPAN L =back =head1 COPYRIGHT & LICENSE Copyright 2012-2017 Guillaume Aubert. This code is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself. 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 LICENSE file for more details. =cut 1; Data-Validate-Type-v1.6.0/xt/000077500000000000000000000000001306441476500156705ustar00rootroot00000000000000Data-Validate-Type-v1.6.0/xt/changes.t000066400000000000000000000004041306441476500174630ustar00rootroot00000000000000#!perl use strict; use warnings; use Test::More; # Load test module. eval { require Test::CPAN::Changes; }; plan( skip_all => 'Test::CPAN::Changes is required to check Changes file.' ) if $@; # Check the Changes file. Test::CPAN::Changes::changes_ok(); Data-Validate-Type-v1.6.0/xt/kwalitee.t000066400000000000000000000006101306441476500176570ustar00rootroot00000000000000#!perl use strict; use warnings; use Test::More; # Load module. eval { require Test::Kwalitee::Extra; }; plan( skip_all => 'Test::Kwalitee::Extra required to evaluate code' ) if $@; # Run extra tests. Test::Kwalitee::Extra->import( qw( :optional ) ); # Clean up the additional file Test::Kwalitee::Extra generates. END { unlink 'Debian_CPANTS.txt' if -e 'Debian_CPANTS.txt'; } Data-Validate-Type-v1.6.0/xt/manifest.t000066400000000000000000000004651306441476500176700ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::More; # Load Test::CheckManifest. my $min_version = '0.9'; eval "use Test::CheckManifest $min_version"; plan( skip_all => "Test::CheckManifest $min_version required" ) if $@; # Verify files against manifest. ok_manifest( { exclude => [ '/.git/' ], } ); Data-Validate-Type-v1.6.0/xt/module_versions.t000066400000000000000000000005411306441476500212720ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::More; # Load Test::Dist::VersionSync. my $min_version = '1.0.0'; eval "use Test::Dist::VersionSync $min_version"; plan( skip_all => "Test::Dist::VersionSync $min_version required." ) if $@; # Check that all the module versions in the distribution are the same. Test::Dist::VersionSync::ok_versions(); Data-Validate-Type-v1.6.0/xt/mojibake.t000066400000000000000000000004771306441476500176460ustar00rootroot00000000000000#!perl =head1 PURPOSE Check Perl files for encoding issues. =cut use strict; use warnings; use Test::More; # Load module. eval { require Test::Mojibake; }; plan( skip_all => 'Test::Mojibake required for source encoding testing' ) if $@; # Test encoding for all files. Test::Mojibake::all_files_encoding_ok(); Data-Validate-Type-v1.6.0/xt/perlcritic.t000066400000000000000000000004241306441476500202150ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::More; # Load Test::Perl::Critic. eval { require Test::Perl::Critic; }; plan( skip_all => 'Test::Perl::Critic required.' ) if $@; # Run PerlCritic. Test::Perl::Critic->import( -profile => '.perlcriticrc' ); all_critic_ok(); Data-Validate-Type-v1.6.0/xt/pod-coverage.t000066400000000000000000000011521306441476500204270ustar00rootroot00000000000000#!perl use strict; use warnings; use Test::More; # Load Test::Pod::Coverage. my $min_tpc_version = '1.08'; eval "use Test::Pod::Coverage $min_tpc_version"; plan( skip_all => "Test::Pod::Coverage $min_tpc_version required for testing POD coverage." ) if $@; # Test::Pod::Coverage doesn't require a minimum Pod::Coverage version, # but older versions don't recognize some common documentation styles my $min_pc_version = '0.18'; eval "use Pod::Coverage $min_pc_version"; plan skip_all => "Pod::Coverage $min_pc_version required for testing POD coverage." if $@; # Test POD coverage. all_pod_coverage_ok(); Data-Validate-Type-v1.6.0/xt/pod.t000066400000000000000000000003501306441476500166350ustar00rootroot00000000000000#!perl -T use strict; use warnings; use Test::More; # Load Test::Pod. my $min_version = '1.22'; eval "use Test::Pod $min_version"; plan( skip_all => "Test::Pod $min_version required." ) if $@; # Check POD. all_pod_files_ok(); Data-Validate-Type-v1.6.0/xt/unix_eol.t000066400000000000000000000004171306441476500177010ustar00rootroot00000000000000#!perl use strict; use warnings; use Test::More; # Load the test module. eval { require Test::EOL; }; plan( skip_all => 'Test::EOL is required to check line endings.' ) if $@; # Check the line endings. Test::EOL::all_perl_files_ok( { trailing_whitespace => 0 } );