CONTRIBUTING000644001750001750 531712317646524 14261 0ustar00taitai000000000000Scalar-Does-0.202NAME CONTRIBUTING DESCRIPTION If you're reading this document, that means you might be thinking about helping me out with this project. Thanks! Here's some ways you could help out: * Bug reports Found a bug? Great! (Well, not so great I suppose.) The place to report them is . Don't e-mail me about it, as your e-mail is more than likely to get lost amongst the spam. An example script clearly demonstrating the bug (preferably written using Test::More) would be greatly appreciated. * Patches If you've found a bug and written a fix for it, even better! Generally speaking you should check out the latest copy of the code from the source repository rather than using the CPAN distribution. The file META.yml should contain a link to the source repository. If not, then try or submit a bug report. (As far as I'm concerned the lack of a link is a bug.) Many of my distributions are also mirrored at . To submit the patch, do a pull request on GitHub or Bitbucket, or attach a diff file to a bug report. Unless otherwise stated, I'll assume that your contributions are licensed under the same terms as the rest of the project. (If using git, feel free to work in a branch. For Mercurial, I'd prefer bookmarks within the default branch.) * Documentation If there's anything unclear in the documentation, please submit this as a bug report or patch as above. Non-toy example scripts that I can bundle would also be appreciated. * Translation Translations of documentation would be welcome. For translations of error messages and other strings embedded in the code, check with me first. Sometimes the English strings may not in a stable state, so it would be a waste of time translating them. Coding Style I tend to write using something approximating the Allman style, using tabs for indentation and Unix-style line breaks. * * I nominally encode all source files as UTF-8, though in practice most of them use a 7-bit-safe ASCII-compatible subset of UTF-8. AUTHOR Toby Inkster . COPYRIGHT AND LICENCE Copyright (c) 2012-2013 by Toby Inkster. CONTRIBUTING.pod is licensed under the Creative Commons Attribution-ShareAlike 2.0 UK: England & Wales License. To view a copy of this license, visit . COPYRIGHT000644001750001750 326712317646525 13725 0ustar00taitai000000000000Scalar-Does-0.202Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: Scalar-Does Upstream-Contact: Toby Inkster (TOBYINK) Source: https://metacpan.org/release/Scalar-Does Files: README lib/IO/Detect.pm lib/Scalar/Does.pm lib/Scalar/Does/MooseTypes.pm t/01basic.t t/02does.t t/03moosey.t t/04cleanliness.t t/05custom.t t/06constants.t t/07makerole.t t/08mooselike.t t/09warnings.t t/10underscore.t t/11givenwhen.t t/iod-01basic.t t/iod-03filenames.t t/iod-04fileuris.t t/iod-05ducktype.t t/iod-11ioall.t t/iod-12pathclass.t Copyright: This software is copyright (c) 2012-2014 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: CONTRIBUTING INSTALL IO-Detect-Changes.txt LICENSE Makefile.PL NEWS TODO Copyright: Unknown License: Unknown Files: Changes META.json META.yml doap.ttl t/iod-02filehandles.t Copyright: Copyright 2014 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/iod-06asfh.t Copyright: This software is copyright (c) 2013-2014 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/iod-13pathtiny.t Copyright: This software is copyright (c) 2014 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 License: Artistic-1.0 This software is Copyright (c) 2014 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) 2014 by the copyright holder(s). This is free software, licensed under: The GNU General Public License, Version 1, February 1989 CREDITS000644001750001750 26512317646520 13420 0ustar00taitai000000000000Scalar-Does-0.202Maintainer: - Toby Inkster (TOBYINK) Contributor: - Piers Cawley (PDCAWLEY) Thanks: - DAMI - Jon Jensen Changes000644001750001750 1025212317646520 13730 0ustar00taitai000000000000Scalar-Does-0.202Scalar-Does =========== Created: 2012-08-01 Home page: Bug tracker: Maintainer: Toby Inkster (TOBYINK) 0.202 2014-04-05 [ Bug Fixes ] - Make t/iod-02filehandles.t clean up after itself. Fixes RT#91497. Jon Jensen++ Piers Cawley++ 0.201 2013-09-30 [ Packaging ] - Use Dist::Inkt. [ Other ] - Updated: Use Exporter::Tiny instead of Exporter::TypeTiny. 0.200 2013-05-24 [ Documentation ] - Document relationship with Type::Tiny. [ Packaging ] - Skip tests involving given/when, smart match, and lexical $_ in Perl >= 5.17. [ Other ] - Updated: Deprecate Scalar::Does::MooseTypes. - Updated: Use Exporter::TypeTiny instead of Sub::Exporter. - Updated: Use Type::Tiny and Types::Standard to perform type checking for built-in Scalar::Does roles, and also Scalar::Does::MooseTypes roles. 0.102 2013-03-10 [ Bug Fixes ] - Scalar::Util version in lib/Scalar/Does.pm and meta/makefile.pret should match. 0.101 2013-03-08 [ Documentation ] - Show how IO::Detect's constants can be used with Scalar::Does's does() function. [ Other ] - IO::Detect now performs the same namespace::clean trickery as Scalar::Does to fake lexical subs. - Improve test suite cleanliness; use Test::Requires, etc. - does($class, $overloaded_operation) no longer returns true. does($instance, $overloaded_operation) still works of course! - use lexical::underscore instead of directly mucking around with PadWalker. 0.100 2013-03-07 [ Packaging ] - Merge IO-Detect distribution into Scalar-Does. - The IO-Detect-Changes.txt file lists changes to the IO-Detect distribution prior to merge. [ Other ] - Updated: New test case for IO::Detect/Path::Tiny interaction. 0.012 2013-01-11 [ Documentation ] - Copyright 2013. 0.011_01 2012-12-15 [ Bug Fixes ] - Attempt to fix some problems CPAN smoke tests are reporting in 09warnings.t. 0.010 2012-12-05 [ Documentation ] - Add documentation for test suite. [ Other ] - Updated: Perl 5.17 has changed the behaviour of UNIVERSAL::can($pkg, 'can'), so that it is no longer useful for detecting whether a package is loaded. Changed Scalar::Does::MooseLike to avoid this idiom. Fixes RT#81622. DAMI++ 0.009 2012-11-05 Gunpowder, treason and plot [ Bug Fixes ] - Skip test '10underscore.t' on Perl 5.008 as it doesn't support lexical $_. - use if $] < 5.010, 'UNIVERSAL::DOES'. [ Packaging ] - Requires UNIVERSAL::DOES in Perl < 5.010. 0.008 2012-10-27 [ Documentation ] - Remove references to Object-DOES in documentation. - Revise documentation about Role::Tiny/Moo::Role's lack of DOES; it is now implemented. [ Other ] - INCOMPATIBLE CHANGE: single-argument does($role) and overloads($role) now check $_. DAMI++ 0.007 2012-10-23 Skyfall [ Bug Fixes ] - Fix warning on does(undef, $role) when $^W is true. Fixes RT#80121. DAMI++ 0.006 2012-10-07 [ Packaging ] - Fix failing test case in Perl 5.8. 0.005 2012-10-05 [ Documentation ] - Correct inaccurate information about Moo type constraints. 0.004 2012-10-03 [ Documentation ] - Better document interaction with Role::Tiny and Moo. [ Other ] - Added: Scalar::Does::MooseTypes. - Added: make_role function for creating anonymous roles. 0.003 2012-09-19 [ Bug Fixes ] - Ensure t/99smartmatch.t is skipped properly on Perl < 5.10.1. 0.002 2012-09-19 [ Bug Fixes ] - Correctly determine Regexp role. [ Documentation ] - Better documentation for interaction with Moose roles and type constraints. - Clarify that does($thing, '0+') is not the same as looks_like_number. - Document relationship with Object::DOES. - Minor improvements. [ Packaging ] - Improved test suite with 100% Devel::Cover coverage. [ Other ] - Added: Export constants for pre-defined roles. - Added: Export looks_like_number. 0.001 2012-09-02 Initial release INSTALL000644001750001750 166512317646515 13462 0ustar00taitai000000000000Scalar-Does-0.202 Installing Scalar-Does should be straightforward. INSTALLATION WITH CPANMINUS If you have cpanm, you only need one line: % cpanm Scalar::Does 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 Scalar::Does INSTALLATION WITH THE CPAN SHELL Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Scalar::Does 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 Scalar-Does: % 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 IO-Detect-Changes.txt000644001750001750 115712317646515 16251 0ustar00taitai000000000000Scalar-Does-0.202IO-Detect ========= Created: 2012-07-09 Home page: Bug tracker: Maintainer: Toby Inkster 0.005 2012-09-05 - (Addition) as_filehandle function. - Perl 5.8 compatibility. 0.004 2012-07-11 - (Packaging) Require version 1.24 of Scalar::Util. 0.003 2012-07-10 - (Bugfix) Re-implementation of IO::Detect::_oneline. 0.002 2012-07-09 - (Addition) Export configurable ducktype function. - (Bugfix) Add space between two words in qw() list. 0.001 2012-07-09 # Initial release LICENSE000644001750001750 4365312317646516 13462 0ustar00taitai000000000000Scalar-Does-0.202This software is copyright (c) 2014 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) 2014 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, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2014 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 105412317646525 13553 0ustar00taitai000000000000Scalar-Does-0.202CONTRIBUTING COPYRIGHT CREDITS Changes INSTALL IO-Detect-Changes.txt LICENSE MANIFEST META.json META.yml Makefile.PL NEWS README SIGNATURE TODO dist.ini doap.ttl lib/IO/Detect.pm lib/Scalar/Does.pm lib/Scalar/Does/MooseTypes.pm t/01basic.t t/02does.t t/03moosey.t t/04cleanliness.t t/05custom.t t/06constants.t t/07makerole.t t/08mooselike.t t/09warnings.t t/10underscore.t t/11givenwhen.t t/iod-01basic.t t/iod-02filehandles.t t/iod-03filenames.t t/iod-04fileuris.t t/iod-05ducktype.t t/iod-06asfh.t t/iod-11ioall.t t/iod-12pathclass.t t/iod-13pathtiny.t META.json000644001750001750 464312317646524 14051 0ustar00taitai000000000000Scalar-Does-0.202{ "abstract" : "like ref() but useful", "author" : [ "Toby Inkster (TOBYINK) " ], "dynamic_config" : 1, "generated_by" : "Dist::Inkt::Profile::TOBYINK version 0.015, CPAN::Meta::Converter version 2.120921", "keywords" : [], "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Scalar-Does", "no_index" : { "directory" : [ "eg", "examples", "inc", "t", "xt" ] }, "optional_features" : {}, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17" } }, "runtime" : { "requires" : { "Exporter::Tiny" : "0.026", "Scalar::Util" : "1.24", "Type::Tiny" : "0.004", "URI::file" : "0", "lexical::underscore" : "0", "namespace::clean" : "0.19" } }, "test" : { "requires" : { "Test::More" : "0.96", "Test::NoWarnings" : "0", "Test::Requires" : "0.06", "URI" : "0" } } }, "provides" : { "IO::Detect" : { "file" : "lib/IO/Detect.pm", "version" : "0.202" }, "IO::Detect::SmartMatcher" : { "file" : "lib/IO/Detect.pm", "version" : "0.202" }, "Scalar::Does" : { "file" : "lib/Scalar/Does.pm", "version" : "0.202" }, "Scalar::Does::MooseTypes" : { "file" : "lib/Scalar/Does/MooseTypes.pm", "version" : "0.202" }, "Scalar::Does::RoleChecker" : { "file" : "lib/Scalar/Does.pm", "version" : "0.202" } }, "release_status" : "stable", "resources" : { "X_identifier" : "http://purl.org/NET/cpan-uri/dist/Scalar-Does/project", "bugtracker" : { "web" : "http://rt.cpan.org/Dist/Display.html?Queue=Scalar-Does" }, "homepage" : "https://metacpan.org/release/Scalar-Does", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/tobyink/p5-scalar-does.git", "web" : "https://github.com/tobyink/p5-scalar-does" } }, "version" : "0.202", "x_contributors" : [ "Piers Cawley (PDCAWLEY) " ] } META.yml000644001750001750 270112317646524 13672 0ustar00taitai000000000000Scalar-Does-0.202--- abstract: 'like ref() but useful' author: - 'Toby Inkster (TOBYINK) ' build_requires: Test::More: 0.96 Test::NoWarnings: 0 Test::Requires: 0.06 URI: 0 configure_requires: ExtUtils::MakeMaker: 6.17 dynamic_config: 1 generated_by: 'Dist::Inkt::Profile::TOBYINK version 0.015, CPAN::Meta::Converter version 2.120921' keywords: [] license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Scalar-Does no_index: directory: - eg - examples - inc - t - xt optional_features: {} provides: IO::Detect: file: lib/IO/Detect.pm version: 0.202 IO::Detect::SmartMatcher: file: lib/IO/Detect.pm version: 0.202 Scalar::Does: file: lib/Scalar/Does.pm version: 0.202 Scalar::Does::MooseTypes: file: lib/Scalar/Does/MooseTypes.pm version: 0.202 Scalar::Does::RoleChecker: file: lib/Scalar/Does.pm version: 0.202 requires: Exporter::Tiny: 0.026 Scalar::Util: 1.24 Type::Tiny: 0.004 URI::file: 0 lexical::underscore: 0 namespace::clean: 0.19 resources: X_identifier: http://purl.org/NET/cpan-uri/dist/Scalar-Does/project bugtracker: http://rt.cpan.org/Dist/Display.html?Queue=Scalar-Does homepage: https://metacpan.org/release/Scalar-Does license: http://dev.perl.org/licenses/ repository: git://github.com/tobyink/p5-scalar-does.git version: 0.202 x_contributors: - 'Piers Cawley (PDCAWLEY) ' Makefile.PL000644001750001750 1337412317646524 14423 0ustar00taitai000000000000Scalar-Does-0.202use strict; use ExtUtils::MakeMaker 6.17; my $EUMM = eval( $ExtUtils::MakeMaker::VERSION ); my $meta = { "abstract" => "like ref() but useful", "author" => ["Toby Inkster (TOBYINK) "], "dynamic_config" => 1, "generated_by" => "Dist::Inkt::Profile::TOBYINK version 0.015, CPAN::Meta::Converter version 2.120921", "keywords" => [], "license" => ["perl_5"], "meta-spec" => { url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec", version => 2, }, "name" => "Scalar-Does", "no_index" => { directory => ["eg", "examples", "inc", "t", "xt"] }, "prereqs" => { configure => { requires => { "ExtUtils::MakeMaker" => 6.17 } }, runtime => { requires => { "Exporter::Tiny" => 0.026, "lexical::underscore" => 0, "namespace::clean" => 0.19, "Scalar::Util" => 1.24, "Type::Tiny" => 0.004, "URI::file" => 0, }, }, test => { requires => { "Test::More" => 0.96, "Test::NoWarnings" => 0, "Test::Requires" => 0.06, "URI" => 0, }, }, }, "provides" => { "IO::Detect" => { file => "lib/IO/Detect.pm", version => 0.202 }, "IO::Detect::SmartMatcher" => { file => "lib/IO/Detect.pm", version => 0.202 }, "Scalar::Does" => { file => "lib/Scalar/Does.pm", version => 0.202 }, "Scalar::Does::MooseTypes" => { file => "lib/Scalar/Does/MooseTypes.pm", version => 0.202 }, "Scalar::Does::RoleChecker" => { file => "lib/Scalar/Does.pm", version => 0.202 }, }, "release_status" => "stable", "resources" => { bugtracker => { web => "http://rt.cpan.org/Dist/Display.html?Queue=Scalar-Does" }, homepage => "https://metacpan.org/release/Scalar-Does", license => ["http://dev.perl.org/licenses/"], repository => { type => "git", url => "git://github.com/tobyink/p5-scalar-does.git", web => "https://github.com/tobyink/p5-scalar-does", }, X_identifier => "http://purl.org/NET/cpan-uri/dist/Scalar-Does/project", }, "version" => 0.202, "x_contributors" => ["Piers Cawley (PDCAWLEY) "], }; my %dynamic_config; do { $meta->{prereqs}{runtime}{requires}{'UNIVERSAL::DOES'} = 0 if $] < 5.010000; }; my %WriteMakefileArgs = ( ABSTRACT => $meta->{abstract}, AUTHOR => ($EUMM >= 6.5702 ? $meta->{author} : $meta->{author}[0]), DISTNAME => $meta->{name}, VERSION => $meta->{version}, EXE_FILES => [ map $_->{file}, values %{ $meta->{x_provides_scripts} || {} } ], NAME => do { my $n = $meta->{name}; $n =~ s/-/::/g; $n }, test => { TESTS => "t/*.t" }, %dynamic_config, ); $WriteMakefileArgs{LICENSE} = $meta->{license}[0] if $EUMM >= 6.3001; sub deps { my %r; for my $stage (@_) { for my $dep (keys %{$meta->{prereqs}{$stage}{requires}}) { next if $dep eq 'perl'; my $ver = $meta->{prereqs}{$stage}{requires}{$dep}; $r{$dep} = $ver if !exists($r{$dep}) || $ver >= $r{$dep}; } } \%r; } my ($build_requires, $configure_requires, $runtime_requires, $test_requires); if ($EUMM >= 6.6303) { $WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build'); $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{TEST_REQUIRES} ||= deps('test'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime'); } elsif ($EUMM >= 6.5503) { $WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build', 'test'); $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime'); } elsif ($EUMM >= 6.52) { $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime', 'build', 'test'); } else { $WriteMakefileArgs{PREREQ_PM} ||= deps('configure', 'build', 'test', 'runtime'); } { my ($minperl) = reverse sort( grep defined && /^[0-9]+(\.[0-9]+)?$/, map $meta->{prereqs}{$_}{requires}{perl}, qw( configure build runtime ) ); if (defined($minperl)) { die "Installing $meta->{name} requires Perl >= $minperl" unless $] >= $minperl; $WriteMakefileArgs{MIN_PERL_VERSION} ||= $minperl if $EUMM >= 6.48; } } sub FixMakefile { return unless -d 'inc'; my $file = shift; local *MAKEFILE; open MAKEFILE, "< $file" or die "FixMakefile: Couldn't open $file: $!; bailing out"; my $makefile = do { local $/; }; close MAKEFILE or die $!; $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; open MAKEFILE, "> $file" or die "FixMakefile: Couldn't open $file: $!; bailing out"; print MAKEFILE $makefile or die $!; close MAKEFILE or die $!; } my $mm = WriteMakefile(%WriteMakefileArgs); FixMakefile($mm->{FIRST_MAKEFILE} || 'Makefile'); exit(0); NEWS000644001750001750 7612317646515 13063 0ustar00taitai000000000000Scalar-Does-0.2022013-03-07: - Merged IO-Detect distribution into Scalar-Does. README000644001750001750 2230112317646515 13317 0ustar00taitai000000000000Scalar-Does-0.202NAME Scalar::Does - like ref() but useful SYNOPSIS use Scalar::Does qw( -constants ); my $object = bless {}, 'Some::Class'; does($object, 'Some::Class'); # true does($object, '%{}'); # true does($object, HASH); # true does($object, ARRAY); # false DESCRIPTION It has long been noted that Perl would benefit from a `does()` built-in. A check that `ref($thing) eq 'ARRAY'` doesn't allow you to accept an object that uses overloading to provide an array-like interface. Functions `does($scalar, $role)` Checks if a scalar is capable of performing the given role. The following (case-sensitive) roles are predefined: * SCALAR or ${} Checks if the scalar can be used as a scalar reference. Note: this role does not check whether a scalar is a scalar (which is obviously true) but whether it is a reference to another scalar. * ARRAY or @{} Checks if the scalar can be used as an array reference. * HASH or %{} Checks if the scalar can be used as a hash reference. * CODE or &{} Checks if the scalar can be used as a code reference. * GLOB or *{} Checks if the scalar can be used as a glob reference. * REF Checks if the scalar can be used as a ref reference (i.e. a reference to another reference). * LVALUE Checks if the scalar is a reference to a special lvalue (e.g. the result of `substr` or `splice`). * IO or <> Uses IO::Detect to check if the scalar is a filehandle or file-handle-like object. (The `<>` check is slightly looser, allowing objects which overload `<>`, though overloading `<>` well can be a little tricky.) * VSTRING Checks if the scalar is a vstring reference. * FORMAT Checks if the scalar is a format reference. * Regexp or qr Checks if the scalar can be used as a quoted regular expression. * bool Checks if the scalar can be used as a boolean. (It's pretty rare for this to not be true.) * "" Checks if the scalar can be used as a string. (It's pretty rare for this to not be true.) * 0+ Checks if the scalar can be used as a number. (It's pretty rare for this to not be true.) Note that this is far looser than `looks_like_number` from Scalar::Util. For example, an unblessed arrayref can be used as a number (it numifies to its reference address); the string "Hello World" can be used as a number (it numifies to 0). * ~~ Checks if the scalar can be used on the right hand side of a smart match. If the given *role* is blessed, and provides a `check` method, then `does` delegates to that. Otherwise, if the scalar being tested is blessed, then `$scalar->DOES($role)` is called, and `does` returns true if the method call returned true. If the scalar being tested looks like a Perl class name, then `$scalar->DOES($role)` is also called, and the string "0E0" is returned for success, which evaluates to 0 in a numeric context but true in a boolean context. `does($role)` Called with a single argument, tests $_. Yes, this works with lexical $_. given ($object) { when(does ARRAY) { ... } when(does HASH) { ... } } Note: in Scalar::Does 0.007 and below the single-argument form of `does` returned a curried coderef. This was changed in Scalar::Does 0.008. `overloads($scalar, $role)` A function `overloads` (which just checks overloading) is also available. `overloads($role)` Called with a single argument, tests $_. Yes, this works with lexical $_. Note: in Scalar::Does 0.007 and below the single-argument form of `overloads` returned a curried coderef. This was changed in Scalar::Does 0.008. `blessed($scalar)`, `reftype($scalar)`, `looks_like_number($scalar)` For convenience, this module can also re-export these functions from Scalar::Util. `looks_like_number` is generally more useful than `does($scalar, q[0+])`. `make_role $name, where { BLOCK }` Returns an anonymous role object which can be used as a parameter to `does`. The block is arbitrary code which should check whether $_[0] does the role. `where { BLOCK }` Syntactic sugar for `make_role`. Compatible with the `where` function from Moose::Util::TypeConstraints, so don't worry about conflicts. Constants The following constants may be exported for convenience: `SCALAR` `ARRAY` `HASH` `CODE` `GLOB` `REF` `LVALUE` `IO` `VSTRING` `FORMAT` `REGEXP` `BOOLEAN` `STRING` `NUMBER` `SMARTMATCH` Export By default, only `does` is exported. This module uses Exporter::Tiny, so functions can be renamed: use Scalar::Does does => { -as => 'performs_role' }; Scalar::Does also plays some tricks with namespace::clean to ensure that any functions it exports to your namespace are cleaned up when you're finished with them. This ensures that if you're writing object-oriented code `does` and `overloads` will not be left hanging around as methods of your classes. Moose::Object provides a `does` method, and you should be able to use Scalar::Does without interfering with that. You can import the constants (plus `does`) using: use Scalar::Does -constants; The `make_role` and `where` functions can be exported like this: use Scalar::Does -make; Or list specific functions/constants that you wish to import: use Scalar::Does qw( does ARRAY HASH STRING NUMBER ); Custom Role Checks use Scalar::Does custom => { -as => 'does_array', -role => 'ARRAY' }, custom => { -as => 'does_hash', -role => 'HASH' }; does_array($thing); does_hash($thing); BUGS Please report any bugs to . SEE ALSO Scalar::Util. . Relationship to Moose roles Scalar::Does is not dependent on Moose, and its role-checking is not specific to Moose's idea of roles, but it does work well with Moose roles. Moose::Object overrides `DOES`, so Moose objects and Moose roles should "just work" with Scalar::Does. { package Transport; use Moose::Role; } { package Train; use Moose; with qw(Transport); } my $thomas = Train->new; does($thomas, 'Train'); # true does($thomas, 'Transport'); # true does($thomas, Transport->meta); # not yet supported! Mouse::Object should be compatible enough to work as well. See also: Moose::Role, Moose::Object, UNIVERSAL. Relationship to Moose type constraints Moose::Meta::TypeConstraint objects, plus the constants exported by MooseX::Types libraries all provide a `check` method, so again, should "just work" with Scalar::Does. Type constraint strings are not supported however. use Moose::Util::TypeConstraints qw(find_type_constraint); use MooseX::Types qw(Int); use Scalar::Does qw(does); my $int = find_type_constraint("Int"); does( "123", $int ); # true does( "123", Int ); # true does( "123", "Int" ); # false Mouse::Meta::TypeConstraints and MouseX::Types should be compatible enough to work as well. See also: Moose::Meta::TypeConstraint, Moose::Util::TypeConstraints, MooseX::Types, Scalar::Does::MooseTypes. Relationship to Type::Tiny type constraints Types built with Type::Tiny and Type::Library can be used exactly as Moose type constraint objects above. use Types::Standard qw(Int); use Scalar::Does qw(does); does(123, Int); # true In fact, Type::Tiny and related libraries are used extensively in the internals of Scalar::Does 0.200+. See also: Type::Tiny, Types::Standard. Relationship to Role::Tiny and Moo roles Roles using Role::Tiny 1.002000 and above provide a `DOES` method, so should work with Scalar::Does just like Moose roles. Prior to that release, Role::Tiny did not provide `DOES`. Moo's role system is based on Role::Tiny. See also: Role::Tiny, Moo::Role. AUTHOR Toby Inkster . COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 600012317646525 13702 0ustar00taitai000000000000Scalar-Does-0.202This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.70. 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 294505f858f11dd062e9916e3f50d88210a9ef54 CONTRIBUTING SHA1 d003c6d498221bd030a63ea718750a3ff7d19408 COPYRIGHT SHA1 c4660a1b84ee3d336d2c034e6691ca31828a1c9e CREDITS SHA1 c1a76f9a80c038db6600bb1199dfd6f2089b411e Changes SHA1 b34513aeed923d3e7227421ddeb76fb5d944ffa2 INSTALL SHA1 f596e25feab3c59ca095da6b8864876a623bb953 IO-Detect-Changes.txt SHA1 47870123f373f5185d6893cb98bf06a8a05510aa LICENSE SHA1 3a1d363224835b40a6b3e470ad3a8cac4a1542c0 MANIFEST SHA1 525839ece893bee3558e483ecd2877a8c01c437a META.json SHA1 2b7f6b0cd9a611ee8d14f1eb4b6da90f67b60aa1 META.yml SHA1 d94d2dfcfa3595ee0bc8507c753496df9af510d9 Makefile.PL SHA1 4dc2ac6d2ecfdd04f010a8c3ae257819487acf0a NEWS SHA1 9a526f62996c5309296a5dc904e6a3d6e9487f0f README SHA1 2b923a21dec40d781654d7549de880213c28ac6b TODO SHA1 8ba37a05ff536406f270324bbdb5e032c39acba4 dist.ini SHA1 e0c50a8cfc091d6a4f885efdcc18f73dc58535d2 doap.ttl SHA1 5da67fbc203be75e2b665aa0e13f3cfaf3a2746f lib/IO/Detect.pm SHA1 92c4eecb5178e40215a1e3efcfa533a900cdc53d lib/Scalar/Does.pm SHA1 f688f150ede9f42eac6782980c9e364f5f525b8f lib/Scalar/Does/MooseTypes.pm SHA1 ba72c241739742035b3baf706cd706942bc8dc99 t/01basic.t SHA1 5e899f9f5b9800bf347b10e602f76699f069a984 t/02does.t SHA1 488b72bd854f0eeb32e4be5a0bee16e1ed85040f t/03moosey.t SHA1 2488d4d2137cc7c26825f8cfe76e60bf96816f77 t/04cleanliness.t SHA1 d9a8927022b6ade4efb228b584227ad44a461572 t/05custom.t SHA1 4b4fd762e485a7fd0ab2e89779f414fef911b97b t/06constants.t SHA1 21e0113370f8c7d7072dc78d430669d2e0ce716f t/07makerole.t SHA1 2c1d93dde6f547e62826906fe8d35e199646e94a t/08mooselike.t SHA1 73a3edb8d9b8e124fbafb14bbfbb12aa672df855 t/09warnings.t SHA1 92a13307dd3cb4f983504b274c8f535b43075523 t/10underscore.t SHA1 ad0782019415a2c5978edbfcc227b92b88b15197 t/11givenwhen.t SHA1 22486bf048b47dc13dc9665e70cc5cd78bd0c054 t/iod-01basic.t SHA1 b87bfa7523f379652ecef9d778a9d286fba7eb59 t/iod-02filehandles.t SHA1 bdb5e1f2bea582092efafc9a9fc8b9a8472cc4c5 t/iod-03filenames.t SHA1 9fc46fdfc99eb27854a1c96d691b47b1492c8eef t/iod-04fileuris.t SHA1 9522999b73950bb401ac03b0ab540454d9bb71a9 t/iod-05ducktype.t SHA1 af629aecb2f4c1295f33dc6562e5043fa17c6c75 t/iod-06asfh.t SHA1 a401b4c05acf56ec05841666aa509804c6fabc1b t/iod-11ioall.t SHA1 a8eb39dbe3dbedb79a679c32d24f0a632f7f498f t/iod-12pathclass.t SHA1 7c0b1b13360de44b368c9d461a8e22fab47e6bcd t/iod-13pathtiny.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) iEYEARECAAYFAlM/TVUACgkQzr+BKGoqfTn/fACfbKe8gV46bHFfTwej59rFaQXe n5YAn04Cq97/IRmAO3/i7GEO5aiyltud =3NU1 -----END PGP SIGNATURE----- TODO000644001750001750 17512317646515 13074 0ustar00taitai000000000000Scalar-Does-0.202Improve test suite coverage for Scalar::Does::MooseTypes. (Scalar::Does itself has 100% coverage according to Devel::Cover.) dist.ini000644001750001750 10212317646515 14036 0ustar00taitai000000000000Scalar-Does-0.202;; class = 'Dist::Inkt::Profile::TOBYINK' ;; name = 'Scalar-Does' doap.ttl000644001750001750 4633012317646524 14117 0ustar00taitai000000000000Scalar-Does-0.202@prefix cpan-uri: . @prefix dc: . @prefix doap: . @prefix doap-bugs: . @prefix doap-changeset: . @prefix doap-deps: . @prefix foaf: . @prefix rdfs: . @prefix xsd: . dc:title "the same terms as the perl 5 programming language system itself". dc:contributor ; doap:release . a doap:Version; dc:identifier "IO-Detect-0.005"^^xsd:string; doap-changeset:released-by ; doap:file-release ; doap:revision "0.005"^^xsd:string. a doap:Project; dc:contributor ; doap-deps:runtime-requirement [ doap-deps:on "namespace::clean 0.19"^^doap-deps:CpanId; ], [ doap-deps:on "URI::file"^^doap-deps:CpanId ], [ doap-deps:on "Scalar::Util 1.24"^^doap-deps:CpanId ], [ doap-deps:on "Type::Tiny 0.004"^^doap-deps:CpanId ], [ doap-deps:on "lexical::underscore"^^doap-deps:CpanId; ], [ doap-deps:on "Exporter::Tiny 0.026"^^doap-deps:CpanId; ]; doap-deps:test-requirement [ doap-deps:on "Test::NoWarnings 0"^^doap-deps:CpanId ], [ doap-deps:on "Test::Requires 0.06"^^doap-deps:CpanId; ], [ doap-deps:on "Test::More 0.96"^^doap-deps:CpanId ], [ doap-deps:on "URI"^^doap-deps:CpanId ]; doap:bug-database ; doap:created "2012-08-01"^^xsd:date; doap:developer ; doap:download-page ; doap:homepage ; doap:license ; doap:maintainer ; doap:name "Scalar-Does"; doap:programming-language "Perl"; doap:release , , , , , , , , , , , , , , , , , ; doap:repository [ a doap:GitRepository; doap:browse ; ]; doap:shortdesc "like ref() but useful". a doap:Version; rdfs:label "Initial release"; dc:identifier "Scalar-Does-0.001"^^xsd:string; dc:issued "2012-09-02"^^xsd:date; doap-changeset:released-by ; doap:file-release ; doap:revision "0.001"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.002"^^xsd:string; dc:issued "2012-09-19"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "Export constants for pre-defined roles."; ], [ a doap-changeset:Documentation; rdfs:label "Better documentation for interaction with Moose roles and type constraints."; ], [ a doap-changeset:Documentation; rdfs:label "Document relationship with Object::DOES."; ], [ a doap-changeset:Documentation; rdfs:label "Minor improvements."; ], [ a doap-changeset:Addition; rdfs:label "Export looks_like_number."; ], [ a doap-changeset:Documentation; rdfs:label "Clarify that does($thing, '0+') is not the same as looks_like_number."; ], [ a doap-changeset:Bugfix; rdfs:label "Correctly determine Regexp role."; ], [ a doap-changeset:Packaging; rdfs:label "Improved test suite with 100% Devel::Cover coverage."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.002"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.003"^^xsd:string; dc:issued "2012-09-19"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Ensure t/99smartmatch.t is skipped properly on Perl < 5.10.1."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.003"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.004"^^xsd:string; dc:issued "2012-10-03"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Addition; rdfs:label "Scalar::Does::MooseTypes."; ], [ a doap-changeset:Documentation; rdfs:label "Better document interaction with Role::Tiny and Moo."; ], [ a doap-changeset:Addition; rdfs:label "make_role function for creating anonymous roles."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.004"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.005"^^xsd:string; dc:issued "2012-10-05"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Documentation; rdfs:label "Correct inaccurate information about Moo type constraints."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.005"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.006"^^xsd:string; dc:issued "2012-10-07"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Packaging; rdfs:label "Fix failing test case in Perl 5.8."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.006"^^xsd:string. a doap:Version; rdfs:label "Skyfall"; dc:identifier "Scalar-Does-0.007"^^xsd:string; dc:issued "2012-10-23"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Fix warning on does(undef, $role) when $^W is true."; doap-changeset:fixes ; doap-changeset:thanks ; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.007"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.008"^^xsd:string; dc:issued "2012-10-27"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Documentation; rdfs:label "Revise documentation about Role::Tiny/Moo::Role's lack of DOES; it is now implemented."; ], [ a doap-changeset:Change; rdfs:label "INCOMPATIBLE CHANGE: single-argument does($role) and overloads($role) now check $_."; doap-changeset:thanks ; rdfs:comment "I've gone through the reverse dependencies on metacpan, and don't think anything should break."; rdfs:seeAlso ; ], [ a doap-changeset:Documentation, doap-changeset:Removal; rdfs:label "Remove references to Object-DOES in documentation."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.008"^^xsd:string. a doap:Version; rdfs:label "Gunpowder, treason and plot"; dc:identifier "Scalar-Does-0.009"^^xsd:string; dc:issued "2012-11-05"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Skip test '10underscore.t' on Perl 5.008 as it doesn't support lexical $_."; ], [ a doap-changeset:Packaging; rdfs:label "Requires UNIVERSAL::DOES in Perl < 5.010."; ], [ a doap-changeset:Bugfix; rdfs:label "use if $] < 5.010, 'UNIVERSAL::DOES'."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.009"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.010"^^xsd:string; dc:issued "2012-12-05"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Documentation; rdfs:label "Add documentation for test suite."; ], [ a doap-changeset:Update; rdfs:label "Perl 5.17 has changed the behaviour of UNIVERSAL::can($pkg, 'can'), so that it is no longer useful for detecting whether a package is loaded. Changed Scalar::Does::MooseLike to avoid this idiom."; doap-changeset:fixes ; doap-changeset:thanks ; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.010"^^xsd:string. a cpan-uri:DeveloperRelease, doap:Version; dc:identifier "Scalar-Does-0.011_01"^^xsd:string; dc:issued "2012-12-15"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Attempt to fix some problems CPAN smoke tests are reporting in 09warnings.t."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.011_01"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.012"^^xsd:string; dc:issued "2013-01-11"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Documentation; rdfs:label "Copyright 2013."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.012"^^xsd:string; rdfs:comment "No functional changes since 0.011_01.". a doap:Version; dc:identifier "Scalar-Does-0.100"^^xsd:string; dc:issued "2013-03-07"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Packaging; rdfs:label "Merge IO-Detect distribution into Scalar-Does."; ], [ a doap-changeset:Packaging; rdfs:label "The IO-Detect-Changes.txt file lists changes to the IO-Detect distribution prior to merge."; ]; doap-changeset:versus ; ], [ doap-changeset:item [ a doap-changeset:Update; rdfs:label "New test case for IO::Detect/Path::Tiny interaction."; ]; doap-changeset:versus ; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.100"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.101"^^xsd:string; dc:issued "2013-03-08"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Change; rdfs:label "use lexical::underscore instead of directly mucking around with PadWalker."; ], [ a doap-changeset:Documentation; rdfs:label "Show how IO::Detect's constants can be used with Scalar::Does's does() function."; ], [ a doap-changeset:Change; rdfs:label "IO::Detect now performs the same namespace::clean trickery as Scalar::Does to fake lexical subs."; ], [ a doap-changeset:Change; rdfs:label "does($class, $overloaded_operation) no longer returns true. does($instance, $overloaded_operation) still works of course!"; ], [ a doap-changeset:Change; rdfs:label "Improve test suite cleanliness; use Test::Requires, etc."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.101"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.102"^^xsd:string; dc:issued "2013-03-10"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Scalar::Util version in lib/Scalar/Does.pm and meta/makefile.pret should match."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.102"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.200"^^xsd:string; dc:issued "2013-05-24"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Update; rdfs:label "Use Type::Tiny and Types::Standard to perform type checking for built-in Scalar::Does roles, and also Scalar::Does::MooseTypes roles."; ], [ a doap-changeset:Update; rdfs:label "Deprecate Scalar::Does::MooseTypes."; ], [ a doap-changeset:Update; rdfs:label "Use Exporter::TypeTiny instead of Sub::Exporter."; ], [ a doap-changeset:Documentation; rdfs:label "Document relationship with Type::Tiny."; ], [ a doap-changeset:Packaging; rdfs:label "Skip tests involving given/when, smart match, and lexical $_ in Perl >= 5.17."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.200"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.201"^^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:Packaging; rdfs:label "Use Dist::Inkt."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.201"^^xsd:string. a doap:Version; dc:identifier "Scalar-Does-0.202"^^xsd:string; dc:issued "2014-04-05"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Bugfix; rdfs:label "Make t/iod-02filehandles.t clean up after itself."; doap-changeset:blame ; doap-changeset:fixes ; doap-changeset:thanks ; rdfs:seeAlso ; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.202"^^xsd:string. a foaf:Person; foaf:nick "DAMI"; foaf:page . a foaf:Person; foaf:name "Piers Cawley"; foaf:nick "PDCAWLEY"; foaf:page . a foaf:Person; foaf:mbox ; foaf:name "Toby Inkster"; foaf:nick "TOBYINK"; foaf:page . a doap-bugs:Issue; doap-bugs:id "80121"^^xsd:string; doap-bugs:page . a doap-bugs:Issue; doap-bugs:id "80434"^^xsd:string; doap-bugs:page . a doap-bugs:Issue; doap-bugs:id "81622"^^xsd:string; doap-bugs:page . a doap-bugs:Issue; doap-bugs:id "91497"^^xsd:string; doap-bugs:page . foaf:mbox ; foaf:name "Jon Jensen". 01basic.t000644001750001750 76412317646515 14262 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check Scalar::Does loads. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 tests => 1; BEGIN { use_ok('Scalar::Does') }; my $policy_is_to_do_these_in_xt = q{ use Test::Pod; use Test::Pod::Coverage; }; 02does.t000644001750001750 574012317646515 14153 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Test various scalars and roles to check we get expected results. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 Scalar::Does; { package Local::Does::Array; use overload '@{}' => 'array'; sub new { bless +{ array=>[] }, pop }; sub array { return shift->{array} }; sub DOES { return 1 if $_[1] eq 'Monkey'; shift->SUPER::DOES(@_) } } { package Local::Does::Not; sub new { bless +{ array=>[] }, pop }; sub can { return if $_[1] eq 'DOES'; shift->SUPER::can(@_) } sub DOES { +die } } { package Cruddy::Role; sub new { bless +{ array=>[] }, pop }; } { package Permissive::Role; sub new { bless +{ array=>[] }, pop }; sub check { 1 } } my %tests = ( undef => [ undef, does => [qw( 0+ "" bool )], doesnt => [qw( SCALAR @{} Regexp CODE &{} Foo::Bar UNIVERSAL )], ], ARRAY => [ [], does => [qw( ARRAY @{} )], doesnt => [qw( HASH %{} )], ], HASH => [ +{}, does => [qw( HASH %{} )], doesnt => [qw( ARRAY @{} )], ], SCALAR => [ \"Hello World", does => [qw( SCALAR ${} )], doesnt => [qw( ARRAY HASH @{} %{} CODE Regexp Foo::Bar UNIVERSAL )], ], CODE => [ sub { 1 }, does => [qw( CODE &{} )], doesnt => [qw( SCALAR @{} UNIVERSAL )], ], Blessed_CODE => [ bless(sub { 1 } => 'Foo::Bar'), does => [qw( CODE &{} Foo::Bar UNIVERSAL )], doesnt => [qw( SCALAR @{} Regexp )], ], Overloaded_Object => [ Local::Does::Array->new, does => [qw( ARRAY @{} HASH %{} Local::Does::Array UNIVERSAL Monkey )], doesnt => [qw( CODE bool "" Gorilla )], ], Overloaded_Class => [ 'Local::Does::Array', does => [qw( bool "" Local::Does::Array UNIVERSAL Monkey )], doesnt => [qw( CODE Gorilla HASH %{} ARRAY @{} )], ], STDOUT => [ \*STDOUT, does => [qw( IO <> GLOB *{} )], doesnt => [qw( SCALAR @{} Regexp CODE &{} Foo::Bar UNIVERSAL )], ], Lvalue => [ \(substr($INC[0], 0, 1)), does => [qw( LVALUE )], doesnt => [qw( SCALAR @{} Regexp CODE &{} Foo::Bar UNIVERSAL IO GLOB )], ], Object_without_DOES_method => [ Local::Does::Not->new, does => [qw( HASH )], doesnt => [qw( Local::Does::Not )], ], Class_without_DOES_method => [ 'Local::Does::Not', does => [qw( )], doesnt => [qw( Local::Does::Not HASH )], ], ); my @uncheck = ( Cruddy::Role->new, [], 'FlibbleSocks', ); my @check = ( Permissive::Role->new, ); foreach my $name (sort keys %tests) { my ($value, %cases) = @{ $tests{$name} }; foreach my $tc (@{ $cases{does} }) { ok(does($value, $tc), "$name does $tc"); } foreach my $tc (@{ $cases{doesnt} }) { ok(!does($value, $tc), "$name doesn't $tc"); } ok( does($value, $_), "$name does $_") for @check; ok(!does($value, $_), "$name doesn't do uncheckable role $_") for @uncheck; } done_testing(); 03moosey.t000644001750001750 256712317646515 14541 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Test that Scalar::Does works with L roles. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 "Moose", "MooseX::Types::Moose"; use Scalar::Does; use MooseX::Types::Moose -all; ok( does(12, Num), '12 does Num', ); ok( !does('12b', Num), "12b doesn't Num", ); my $union = Num | ArrayRef[Num]; ok( does(12, $union), '12 does custom type', ); ok( does([qw(1 2 3)], $union), '[1,2,3] does custom type', ); ok( !does([qw(a b c)], $union), '[a,b,c] doesn\'t custom type', ); ok( !does(+{}, $union), 'hashref doesn\'t custom type', ); { package Local::Foo; use Moose::Role; } { package Local::Bar; use Moose; with 'Local::Foo'; } { package MyLib; use MooseX::Types -declare => ['IsBar', 'DoesFoo']; role_type DoesFoo, { role => 'Local::Foo' }; class_type IsBar, { class => 'Local::Bar' }; } my $obj = Local::Bar->new; ok(does $obj, Any); ok(does $obj, Object); ok(does $obj, 'UNIVERSAL'); ok(does $obj, 'Moose::Object'); ok(does $obj, 'Local::Foo'); ok(does $obj, 'Local::Bar'); ok(does $obj, MyLib::IsBar); ok(does $obj, MyLib::DoesFoo); done_testing(); 04cleanliness.t000644001750001750 126612317646515 15522 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check that functions installed by Scalar::Does are removed by L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 tests => 2; { package Local::Foo; use Scalar::Does; sub check_does { my ($class, $thing, $role) = @_; does($thing, $role); } } ok( !Local::Foo->can('does'), "does is cleaned up", ); ok( Local::Foo->check_does( [] => 'ARRAY' ), "does still works", ); 05custom.t000644001750001750 132012317646515 14524 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Make sure Scalar::Does can export custom role checkers, and that they work OK. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 tests => 5; use Scalar::Does custom => { -role => 'ARRAY', -as => 'does_array' }, custom => { -role => 'HASH', -as => 'does_hash' }; ok does_array( +[] ); ok !does_array( +{} ); ok !does_hash( +[] ); ok does_hash( +{} ); ok not eval q{ use Scalar::Does custom => { -as => 'foo' } }; 06constants.t000644001750001750 162712317646515 15241 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check that Scalar::Does exports constants for built-in roles, and that they work. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 Scalar::Does -constants; my $var = "Hello world"; ok does(\$var, SCALAR); ok does([], ARRAY); ok does(+{}, HASH); ok does(sub {0}, CODE); ok does(\*STDOUT, GLOB); ok does(\(\"Hello"), REF); ok does(\(substr($var,0,1)), LVALUE); ok does(\*STDOUT, IO); ok does(qr{x}, REGEXP); ok does(1, BOOLEAN); ok does(1, STRING); ok does(1, NUMBER); ok does(1, SMARTMATCH); if ($] >= 5.012) { ok does(\v1.2.3, VSTRING); } else { pass( "VSTRING test skipped on older Perls" ); } done_testing; 07makerole.t000644001750001750 170212317646515 15017 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check that Scalar::Does exports C and C, and that these can be used to make custom roles which work. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 tests => 11; use Scalar::Does does => -make; my $positive = make_role 'Positive Integer', where { no warnings 'numeric'; $_[0] > 0 }; can_ok $positive => 'check'; is("$positive", "Positive Integer"); ok does($positive->name, q[""]); ok does($positive->code, q[&{}]); ok does("1", $positive); ok does("1hello", $positive); ok !does("-1", $positive); ok !does("", $positive); ok not eval { make_role(); }; my $name = make_role qr{^Toby$}i; ok does("TOBY", $name); ok !does("TOBIAS", $name); 08mooselike.t000644001750001750 321212317646515 15206 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Test Scalar::Does::MooseTypes. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 Scalar::Does qw(does); use Scalar::Does::MooseTypes -constants; my $var = "Hello world"; ok does(\$var, ScalarRef); ok does([], ArrayRef); ok does(+{}, HashRef); ok does(sub {0}, CodeRef); ok does(\*STDOUT, GlobRef); ok does(\(\"Hello"), Ref); ok does(\*STDOUT, FileHandle); ok does(qr{x}, RegexpRef); ok does(1, Str); ok does(1, Num); ok does(1, Int); ok does(1, Defined); ok does(1, Value); ok does(undef, Undef); ok does(undef, Item); ok does(undef, Any); ok does('Scalar::Does', ClassName); ok does('Scalar::Does', RoleName); ok does(undef, Bool); ok does('', Bool); ok does(0, Bool); ok does(1, Bool); ok !does(7, Bool); ok does(\(\"Hello"), ScalarRef); ok !does([], Str); ok !does([], Num); ok !does([], Int); ok does("4x4", Str); ok !does("4x4", Num); ok !does("4.2", Int); ok !does(undef, Str); ok !does(undef, Num); ok !does(undef, Int); ok !does(undef, Defined); ok !does(undef, Value); { package Local::Class1; use strict; } { no warnings 'once'; $Local::Class2::VERSION = 0.001; @Local::Class3::ISA = qw(UNIVERSAL); @Local::Dummy1::FOO = qw(UNIVERSAL); } { package Local::Class4; sub XYZ () { 1 } } ok !does(undef, ClassName); ok !does([], ClassName); ok does("Local::Class$_", ClassName) for 2..4; ok !does("Local::Dummy1", ClassName); done_testing; 09warnings.t000644001750001750 155112317646515 15054 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check that Scalar::Does doesn't issue any unexpected warnings, even under C<< $^W >>. =head1 SEE ALSO L. =head1 THANKS Laurent Dami initially reported this issue and gave a good demonstration of it. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 "List::MoreUtils"; BEGIN { plan skip_all => 'pure Perl List::MoreUtils generates warning under -w' unless List::MoreUtils::_XScompiled(); }; use Test::NoWarnings; $^W = 1; require Scalar::Does; Scalar::Does::does(undef, 'ARRAY'); done_testing(1); 10underscore.t000644001750001750 172712317646515 15372 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Tests that the one-argument forms of C and C work with lexical C<< $_ >>, using C<< my $_ >>. =head1 SEE ALSO L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 "v5.10.0"; BEGIN { plan skip_all => "skipping lexical \$_ test in Perl >= 5.17" if $] >= 5.017; }; use Scalar::Does -constants, 'overloads'; $_ = []; ok does ARRAY; ok not does HASH; { my $_ = {}; ok does HASH; ok not does ARRAY; } { my $_ = do { package Local::Overloader; use overload '%{}' => sub { +{} }; bless []; }; ok does ARRAY; ok does HASH; ok not overloads '@{}'; ok overloads '%{}'; } done_testing; 11givenwhen.t000644001750001750 156212317646515 15211 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Tests that the one-argument form of C works with lexical C<< $_ >>, using a Perl 5.10 C block. In Perl 5.17.x and above, C no longer uses lexical C<< $_ >> but this test should continue to work. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 "v5.10.1"; BEGIN { plan skip_all => "skipping given/when test in Perl >= 5.17" if $] >= 5.017; }; use feature qw(switch); use Scalar::Does -constants; plan tests => 2; my $array = []; ok does $array, ARRAY; given ($array) { when ( does(HASH) ) { fail() } when ( does(ARRAY) ) { pass() } } iod-01basic.t000644001750001750 73712317646515 15033 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check IO::Detect loads. This file originally formed part of the IO-Detect test suite. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 tests => 1; BEGIN { use_ok('IO::Detect') }; iod-02filehandles.t000644001750001750 505112317646515 16243 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check IO::Detect can detect filehandle-like things. This file originally formed part of the IO-Detect test suite. =head1 AUTHOR Greg Bacon =head1 SEE ALSO L. =cut # These tests are largely stolen from Greg Bacon's answer to the following StackOverflow question... # http://stackoverflow.com/questions/3214647/what-is-the-best-way-to-determine-if-a-scalar-holds-a-filehandle # use strict; use warnings; use Test::More; use FileHandle; use IO::File; use IO::Socket::INET; use File::Temp qw/tempdir/; use IO::Detect qw( is_filehandle FileHandle ); plan skip_all => "only works on Linux" unless $^O =~ /linux/i; my $SLEEP = 5; my $tmpdir = tempdir( CLEANUP => 1 ); my $FIFO = "$tmpdir/myfifo"; my $pid = fork; die "$0: fork" unless defined $pid; if ($pid == 0) { system("mknod", $FIFO, "p") == 0 or die "$0: mknod failed"; open my $fh, ">", $FIFO; sleep $SLEEP; exit 0; } else { sleep 1 while !-e $FIFO; } my @handles = ( [0, "1", 1], [0, "hashref", {}], [0, "arrayref", []], [0, "globref", \*INC], [1, "in-memory", do {{ my $buf; open my $fh, "<", \$buf; $fh }}], [1, "FH1 glob", do {{ open FH1, "<", "/dev/null"; *FH1 }}], [1, "FH2 globref", do {{ open FH2, "<", "/dev/null"; \*FH2 }}], # [1, "FH3 string", do {{ open FH3, "<", "/dev/null"; "FH3" }}], [1, "STDIN glob", \*STDIN], [1, "plain read", do {{ open my $fh, "<", "/dev/null"; $fh }}], [1, "plain write", do {{ open my $fh, ">", "/dev/null"; $fh }}], [1, "FH read", FileHandle->new("< /dev/null")], [1, "FH write", FileHandle->new("> /dev/null")], [1, "I::F read", IO::File->new("< /dev/null")], [1, "I::F write", IO::File->new("> /dev/null")], [1, "pipe read", do {{ open my $fh, "sleep $SLEEP |"; $fh }}], [1, "pipe write", do {{ open my $fh, "| sleep $SLEEP"; $fh }}], [1, "FIFO read", do {{ open my $fh, "<", $FIFO; $fh }}], [1, "socket", IO::Socket::INET->new(LocalAddr => sprintf('localhost:%d', 10000 + rand 20000))], ); foreach (@handles) { my ($truth, $label, $fh) = @$_; if ($truth) { ok is_filehandle($fh), "positive for $label" } else { ok !is_filehandle($fh), "negitive for $label" } } if ($] >= 5.010 and $] < 5.017) { foreach (@handles) { my ($truth, $label, $fh) = @$_; my $eval = $truth ? q[ ok($fh ~~ FileHandle, "smart match positive for $label") ] : q[ ok(not($fh ~~ FileHandle), "smart match negitive for $label") ]; eval "use IO::Detect -smartmatch; $eval"; } } done_testing(); iod-03filenames.t000644001750001750 251712317646515 15735 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check IO::Detect can detect filename-like things. This file originally formed part of the IO-Detect test suite. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 IO::Detect qw( is_filename FileName ); my @filenames = qw( 0 /dev/null readme.txt README C:\Windows\Notepad.exe C:\Windows\ ); { package Local::Stringifier; use overload q[""], sub { $_[0][0] }; sub new { bless \@_, shift } } push @filenames, Local::Stringifier->new(__FILE__); ok !is_filename([]), 'is_filename ARRAY'; ok !is_filename(undef), 'is_filename undef'; ok !is_filename(''), 'is_filename empty string'; ok !is_filename(<<'FILENAME'), 'is_filename multiline'; multi line string FILENAME if ($] >= 5.010 and $] < 5.017) { eval q[ use IO::Detect -smartmatch, -default; ok(is_filename, "is_filename $_") for @filenames; ok not([] ~~ FileName), 'ARRAY ~~ FileName'; ok not(undef ~~ FileName), 'undef ~~ FileName'; ok not('' ~~ FileName), 'empty string ~~ FileName'; for (@filenames) { ok $_ ~~ FileName, "$_ ~~ FileName" }; ]; } done_testing(); iod-04fileuris.t000644001750001750 250312317646515 15610 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check IO::Detect can detect URI-like things. This file originally formed part of the IO-Detect test suite. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 IO::Detect qw( is_fileuri FileUri ); use URI; { package Local::Stringifier; use overload q[""], sub { $_[0][0] }; sub new { bless \@_, shift } } my @uris = qw( file://localhost/etc/fstab file:///etc/fstab file:///c:/WINDOWS/clock.avi file://localhost/c|/WINDOWS/clock.avi file:///c|/WINDOWS/clock.avi file://localhost/c:/WINDOWS/clock.avi file://localhost///remotehost/share/dir/file.txt file://///remotehost/share/dir/file.txt ); @uris = ( @uris, (map { Local::Stringifier->new($_) } @uris), (map { URI->new($_) } @uris), ); if ($] >= 5.010 and $] < 5.017) { eval q[ use IO::Detect -smartmatch, -default; ok(is_fileuri, sprintf("is_fileuri %s %s", ref $_, $_)) foreach @uris; ok($_ ~~ FileUri, sprintf("is_fileuri %s %s", ref $_, $_)) foreach @uris; ]; } ok not is_fileuri 'http://localhost/'; ok not is_fileuri "http://localhost/\nfile://"; done_testing(); iod-05ducktype.t000644001750001750 117612317646515 15624 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Test IO::Detect's C function. This file originally formed part of the IO-Detect test suite. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 tests => 2; use IO::Detect ducktype => { -as => 'can_dump', methods => ['Dump'] }; use Data::Dumper; use IO::Handle; ok can_dump(Data::Dumper->new([])); ok !can_dump(IO::Handle->new); iod-06asfh.t000644001750001750 110112317646515 14702 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Test C works. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2013-2014 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 IO::Detect as_filehandle => { mode => "<:encoding(UTF-8)" }; my $fh = as_filehandle(__FILE__); while (<$fh>) { pass("found COPYRIGHT line") if /COPYRIGHT [A][N][D] LICENCE/; } done_testing(); iod-11ioall.t000644001750001750 133412317646515 15065 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check how IO::Detect handles L objects. This test is skipped if IO::All is not available. This file originally formed part of the IO-Detect test suite. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 "v5.10", "IO::All"; use IO::All (); use IO::Detect; $_ = IO::All->new('Makefile.PL'); ok is_filehandle, "is_filehandle"; ok is_filename, "is_filename"; ok not(is_fileuri), "is_fileuri"; done_testing;iod-12pathclass.t000644001750001750 135612317646515 15754 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check how IO::Detect handles L objects. This test is skipped if Path::Class is not available. This file originally formed part of the IO-Detect test suite. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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 "v5.10", "Path::Class"; use Path::Class 'file'; use IO::Detect; $_ = file('Makefile.PL'); ok not(is_filehandle), "is_filehandle"; ok is_filename, "is_filename"; ok not(is_fileuri), "is_fileuri"; done_testing; iod-13pathtiny.t000644001750001750 134512317646515 15631 0ustar00taitai000000000000Scalar-Does-0.202/t=head1 PURPOSE Check how IO::Detect handles L objects. This test is skipped if Path::Tiny is not available. This file originally formed part of the IO-Detect test suite. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2014 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 "v5.10", "Path::Tiny"; use Path::Tiny 'path'; use IO::Detect; $_ = path('Makefile.PL'); ok not(is_filehandle), "is_filehandle"; ok is_filename, "is_filename"; ok not(is_fileuri), "is_fileuri"; done_testing; Detect.pm000644001750001750 2365712317646515 15301 0ustar00taitai000000000000Scalar-Does-0.202/lib/IOpackage IO::Detect; use 5.008; use constant { false => !1, true => !0 }; use strict; use warnings; use if $] < 5.010, 'UNIVERSAL::DOES'; BEGIN { $IO::Detect::AUTHORITY = 'cpan:TOBYINK'; $IO::Detect::VERSION = '0.202'; } use namespace::clean 0.19; EXPORTER: { use base "Exporter::Tiny"; our %_CONSTANTS; our @EXPORT = qw( is_filehandle is_filename is_fileuri ); our @EXPORT_OK = ( qw( is_filehandle is_filename is_fileuri ), qw( FileHandle FileName FileUri ), qw( ducktype as_filehandle ), ); our %EXPORT_TAGS = ( smartmatch => [qw( FileHandle FileName FileUri )], ); sub _exporter_validate_opts { require B; my $class = shift; $_[0]{exporter} ||= sub { my $into = $_[0]{into}; my ($name, $sym) = @{ $_[1] }; for (grep ref, $into->can($name)) { B::svref_2object($_)->STASH->NAME eq $into and _croak("Refusing to overwrite local sub '$name' with export from $class"); } "namespace::clean"->import(-cleanee => $_[0]{into}, $name); no strict qw(refs); no warnings qw(redefine prototype); *{"$into\::$name"} = $sym; } } } use overload qw<>; use Scalar::Util qw< blessed openhandle reftype >; use Carp qw; use URI::file; sub _lu { require lexical::underscore; goto \&lexical::underscore; } sub _ducktype { my ($object, $methods) = @_; return unless blessed $object; foreach my $m (@{ $methods || [] }) { return unless $object->can($m); } return true; } sub _generate_ducktype { my ($class, $name, $arg) = @_; my $methods = $arg->{methods}; return sub (;$) { @_ = ${+_lu} unless @_; push @_, $methods; goto \&_ducktype; }; } my $expected_methods = [ qw(close eof fcntl fileno getc getline getlines ioctl read print stat) ]; sub is_filehandle (;$) { my $fh = @_ ? shift : ${+_lu}; return true if openhandle $fh; # Logic from IO::Handle::Util { my $reftype = reftype($fh); $reftype = '' unless defined $reftype; if ($reftype eq 'IO' or $reftype eq 'GLOB' && *{$fh}{IO}) { for ($fh->fileno, fileno($fh)) { return unless defined; return unless $_ >= 0; } return true; } } return true if blessed $fh && $fh->DOES('IO::Handle'); return true if blessed $fh && $fh->DOES('FileHandle'); return true if blessed $fh && $fh->DOES('IO::All'); return _ducktype $fh, $expected_methods; } sub _oneline ($) { !! ( $_[0] !~ /\r?\n|\r/s ) } sub is_filename (;$) { my $f = @_ ? shift : ${+_lu}; return true if blessed $f && $f->DOES('IO::All'); return true if blessed $f && $f->DOES('Path::Class::Entity'); return ( length "$f" and _oneline "$f" ) if blessed $f && overload::Method($f, q[""]); return ( length $f and _oneline $f ) if defined $f && !ref $f; return; } sub is_fileuri (;$) { my $f = @_ ? shift : ${+_lu}; return $f if blessed $f && $f->DOES('URI::file'); return URI::file->new($f->uri) if blessed $f && $f->DOES('RDF::Trine::Node::Resource'); return URI::file->new($f) if $f =~ m{^file://\S+}i; return; } sub _generate_as_filehandle { my ($class, $name, $arg) = @_; my $default_mode = $arg->{mode} || '<'; return sub (;$$) { my $f = @_ ? shift : ${+_lu}; return $f if is_filehandle($f); if (my $uri = is_fileuri($f)) { $f = $uri->file } my $mode = shift || $default_mode; open my $fh, $mode, $f or croak "Cannot open '$f' with mode '$mode': $!, died"; return $fh; }; } *as_filehandle = __PACKAGE__->_generate_as_filehandle('as_filehandle', +{}); { package IO::Detect::SmartMatcher; BEGIN { $IO::Detect::SmartMatcher::AUTHORITY = 'cpan:TOBYINK'; $IO::Detect::SmartMatcher::VERSION = '0.202'; } use Scalar::Util qw< blessed >; use overload (); no warnings 'overload'; # '~~' unavailable in Perl 5.8 use overload '""' => 'to_string', '~~' => 'check', '==' => 'check', 'eq' => 'check', fallback => 1; sub check { my ($self, $thing) = @_; $self->[1]->($thing); } sub to_string { shift->[0] } sub new { my $proto = shift; if (blessed $proto and $proto->isa(__PACKAGE__)) { return "$proto"->new(@_); } bless \@_ => $proto; } } use constant FileHandle => IO::Detect::SmartMatcher::->new(FileHandle => \&is_filehandle); use constant FileName => IO::Detect::SmartMatcher::->new(FileName => \&is_filename); use constant FileUri => IO::Detect::SmartMatcher::->new(FileUri => \&is_fileuri); true; __END__ =pod =encoding utf8 =for stopwords frickin' filehandliness =head1 NAME IO::Detect - is this a frickin' filehandle or what?! =head1 SYNOPSIS use IO::Detect; if (is_filehandle $fh) { my $line = <$fh>; } =head1 DESCRIPTION It is stupidly complicated to detect whether a given scalar is a filehandle (or something filehandle like) in Perl. This module attempts to do so, but probably falls short in some cases. The primary advantage of using this module is that it gives you somebody to blame (me) if your code can't detect a filehandle. The main use case for IO::Detect is for when you are writing functions and you want to allow the caller to pass a file as an argument without being fussy as to whether they pass a file name or a file handle. =head2 Functions Each function takes a single argument, or if called with no argument, operates on C<< $_ >>. =over =item C<< is_filehandle $thing >> Theoretically returns true if and only if $thing is a file handle, or may be treated as a filehandle. That includes blessed references to filehandles, things that inherit from IO::Handle, etc. It's never going to work 100%. What Perl allows you to use as a filehandle is mysterious and somewhat context-dependent, as the following code illustrates. my $fh = "STD" . "OUT"; print $fh "Hello World!\n"; =item C<< is_filename $thing >> Returns true if $thing is a L object or L or L. That's because depending on your operating system, virtually anything can be used as a filename. (In fact, on many systems, including Linux, filenames can contain line breaks. However, this is unlikely to be intentional.) This function doesn't tell you whether $thing is an existing file on your system. It attempts to tell you whether $thing could possibly be a filename on some system somewhere. =item C<< is_fileuri $thing >> Returns true if $thing is a URI beginning with "file://". It allows for L objects, L objects, strings and objects that overload stringification. This function actually returns an "interesting value of true". The value returned is a L object. =item C<< as_filehandle $thing, $mode >> Returns $thing if it is a filehandle; otherwise opens it with mode $mode (croaking if it cannot be opened). $mode defaults to "<" (read access). This function is not exported by default, but needs to be requested explicitly: use IO::Detect qw(as_filehandle); You may even specify a different default mode, or import it several times with different names: use IO::Detect as_filehandle => { -as => 'as_filehandle_read', mode => '<' }, as_filehandle => { -as => 'as_filehandle_write', mode => '>' }; =back =head2 Smart Matching You can import three constants for use in smart matching: use IO::Detect -smartmatch; These constants are: =over =item C<< FileHandle >> =item C<< FileName >> =item C<< FileUri >> =back They can be used like this: if ($file ~~ FileHandle) { ... } Note that there does exist a L package in Perl core. This module attempts to do the right thing so that C<< FileHandle->new >> still works, but there are conceivably places this could go wrong, or be plain old confusing. Although C and its friends support Perl 5.8 and above, smart match is only available in Perl 5.10 onwards. =head2 Use with Scalar::Does The smart match constants can also be used with L: if (does $file, FileHandle) { ...; } elsif (does $file, FileName) { ...; } =head2 Precedence Because there is some overlap/ambiguity between what is a filehandle and what is a filename, etc, if you need to detect between them, I recommend checking C first, then C and falling back to C. for ($file) { when (FileHandle) { ... } when (FileUri) { ... } when (FileName) { ... } default { die "$file is not a file!" } } =head2 Export Like Scalar::Does, IO::Detect plays some tricks with L to ensure that any functions it exports to your namespace are cleaned up when you're finished with them. =head3 Duck Typing In some cases you might be happy to accept something less than a complete file handle. In this case you can import a customised "duck type" test... use IO::Detect -default, ducktype => { -as => 'is_slurpable', methods => [qw(getlines close)], }; sub do_something_with_a_file { my $f = shift; if ( is_filehandle $f or is_slurpable $f ) { ... } elsif ( is_filename $f ) { ... } } Duck type test functions only test that the argument is blessed and can do all of the specified methods. They don't test any other aspect of "filehandliness". =head1 BUGS Please report any bugs to L. =head1 SEE ALSO This module is an attempt to capture some of the wisdom from this PerlMonks thread L into executable code. Various other modules that may be of interest, in no particular order... L, L, L, L, L, L, L, L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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. Does.pm000644001750001750 3330712317646515 15652 0ustar00taitai000000000000Scalar-Does-0.202/lib/Scalarpackage Scalar::Does; use 5.008; use strict; use warnings; use if $] < 5.010, 'UNIVERSAL::DOES'; METADATA: { $Scalar::Does::AUTHORITY = 'cpan:TOBYINK'; $Scalar::Does::VERSION = '0.202'; } UTILITY_CLASS: { package Scalar::Does::RoleChecker; $Scalar::Does::RoleChecker::AUTHORITY = 'cpan:TOBYINK'; $Scalar::Does::RoleChecker::VERSION = '0.202'; use base "Type::Tiny"; sub new { my $class = shift; my ($name, $coderef); for my $p (@_) { if (Scalar::Does::does($p, 'CODE')) { $coderef = $p } if (Scalar::Does::does($p, 'HASH')) { $coderef = $p->{where} } if (Scalar::Does::does($p, 'Regexp')){ $coderef = sub { $_[0] =~ $p } } if (not ref $p) { $name = $p } } Carp::confess("Cannot make role without checker coderef or regexp") unless $coderef; $class->SUPER::new(display_name => $name, constraint => $coderef); } sub code { shift->constraint }; } PRIVATE_STUFF: { sub _lu { require lexical::underscore; goto \&lexical::underscore; } use constant MISSING_ROLE_MESSAGE => ( "Please supply a '-role' argument when exporting custom functions, died" ); use Carp 0 qw( confess ); use Types::Standard 0.004 qw( -types ); } use namespace::clean 0.19; DEFINE_CONSTANTS: { our %_CONSTANTS = ( BOOLEAN => q[bool], STRING => q[""], NUMBER => q[0+], REGEXP => q[qr], SMARTMATCH => q[~~], map {; $_ => $_ } qw( SCALAR ARRAY HASH CODE REF GLOB LVALUE FORMAT IO VSTRING ) ); require constant; constant->import(\%_CONSTANTS); } EXPORTER: { use base "Exporter::Tiny"; our %_CONSTANTS; our @EXPORT = ( "does" ); our @EXPORT_OK = ( qw( does overloads blessed reftype looks_like_number make_role where custom ), keys(%_CONSTANTS), ); our %EXPORT_TAGS = ( constants => [ "does", keys(%_CONSTANTS) ], only_constants => [ keys(%_CONSTANTS) ], make => [ qw( make_role where ) ], ); sub _exporter_validate_opts { require B; my $class = shift; $_[0]{exporter} ||= sub { my $into = $_[0]{into}; my ($name, $sym) = @{ $_[1] }; for (grep ref, $into->can($name)) { B::svref_2object($_)->STASH->NAME eq $into and _croak("Refusing to overwrite local sub '$name' with export from $class"); } "namespace::clean"->import(-cleanee => $_[0]{into}, $name); no strict qw(refs); no warnings qw(redefine prototype); *{"$into\::$name"} = $sym; } } } ROLES: { no warnings; my $io = "Type::Tiny"->new( display_name => "IO", constraint => sub { require IO::Detect; IO::Detect::is_filehandle($_) }, ); our %_ROLES = ( SCALAR => ( ScalarRef() | Ref->parameterize('SCALAR') | Overload->parameterize('${}') ), ARRAY => ( ArrayRef() | Ref->parameterize('ARRAY') | Overload->parameterize('@{}') ), HASH => ( HashRef() | Ref->parameterize('HASH') | Overload->parameterize('%{}') ), CODE => ( CodeRef() | Ref->parameterize('CODE') | Overload->parameterize('&{}') ), REF => ( Ref->parameterize('REF') ), GLOB => ( GlobRef() | Ref->parameterize('GLOB') | Overload->parameterize('*{}') ), LVALUE => ( Ref->parameterize('LVALUE') ), FORMAT => ( Ref->parameterize('FORMAT') ), IO => $io, VSTRING => ( Ref->parameterize('VSTRING') ), Regexp => ( RegexpRef() | Ref->parameterize('Regexp') | Overload->parameterize('qr') ), bool => ( Value() | Overload->complementary_type | Overload->parameterize('bool') ), q[""] => ( Value() | Overload->complementary_type | Overload->parameterize('""') ), q[0+] => ( Value() | Overload->complementary_type | Overload->parameterize('0+') ), q[<>] => ( Overload->parameterize('<>') | $io ), q[~~] => ( Overload->parameterize('~~') | Object->complementary_type ), q[${}] => 'SCALAR', q[@{}] => 'ARRAY', q[%{}] => 'HASH', q[&{}] => 'CODE', q[*{}] => 'GLOB', q[qr] => 'Regexp', ); while (my ($k, $v) = each %_ROLES) { $_ROLES{$k} = $_ROLES{$v} unless ref $v } } PUBLIC_FUNCTIONS: { use Scalar::Util 1.24 qw( blessed reftype looks_like_number ); sub overloads ($;$) { unshift @_, ${+_lu} if @_ == 1; return unless blessed $_[0]; goto \&overload::Method; } sub does ($;$) { unshift @_, ${+_lu} if @_ == 1; my ($thing, $role) = @_; no warnings; our %_ROLES; if (my $test = $_ROLES{$role}) { return !! $test->check($thing); } if (blessed $role and $role->can('check')) { return !! $role->check($thing); } if (blessed $thing && $thing->can('DOES')) { return !! 1 if $thing->DOES($role); } elsif (UNIVERSAL::can($thing, 'can') && $thing->can('DOES')) { my $class = $thing; return '0E0' if $class->DOES($role); } return; } sub _generate_custom { my ($class, $name, $arg) = @_; my $role = $arg->{ -role } or confess MISSING_ROLE_MESSAGE; return sub (;$) { push @_, $role; goto \&does; } } sub make_role { return "Scalar::Does::RoleChecker"->new(@_); } sub where (&) { return +{ where => $_[0] }; } } "it does" __END__ =pod =encoding utf8 =for stopwords vstring qr numifies =head1 NAME Scalar::Does - like ref() but useful =head1 SYNOPSIS use Scalar::Does qw( -constants ); my $object = bless {}, 'Some::Class'; does($object, 'Some::Class'); # true does($object, '%{}'); # true does($object, HASH); # true does($object, ARRAY); # false =head1 DESCRIPTION It has long been noted that Perl would benefit from a C<< does() >> built-in. A check that C<< ref($thing) eq 'ARRAY' >> doesn't allow you to accept an object that uses overloading to provide an array-like interface. =head2 Functions =over =item C<< does($scalar, $role) >> Checks if a scalar is capable of performing the given role. The following (case-sensitive) roles are predefined: =over =item * B or B<< ${} >> Checks if the scalar can be used as a scalar reference. Note: this role does not check whether a scalar is a scalar (which is obviously true) but whether it is a reference to another scalar. =item * B or B<< @{} >> Checks if the scalar can be used as an array reference. =item * B or B<< %{} >> Checks if the scalar can be used as a hash reference. =item * B or B<< &{} >> Checks if the scalar can be used as a code reference. =item * B or B<< *{} >> Checks if the scalar can be used as a glob reference. =item * B Checks if the scalar can be used as a ref reference (i.e. a reference to another reference). =item * B Checks if the scalar is a reference to a special lvalue (e.g. the result of C<< substr >> or C<< splice >>). =item * B or B<< <> >> Uses L to check if the scalar is a filehandle or file-handle-like object. (The C<< <> >> check is slightly looser, allowing objects which overload C<< <> >>, though overloading C<< <> >> well can be a little tricky.) =item * B Checks if the scalar is a vstring reference. =item * B Checks if the scalar is a format reference. =item * B or B<< qr >> Checks if the scalar can be used as a quoted regular expression. =item * B Checks if the scalar can be used as a boolean. (It's pretty rare for this to not be true.) =item * B<< "" >> Checks if the scalar can be used as a string. (It's pretty rare for this to not be true.) =item * B<< 0+ >> Checks if the scalar can be used as a number. (It's pretty rare for this to not be true.) Note that this is far looser than C from L. For example, an unblessed arrayref can be used as a number (it numifies to its reference address); the string "Hello World" can be used as a number (it numifies to 0). =item * B<< ~~ >> Checks if the scalar can be used on the right hand side of a smart match. =back If the given I is blessed, and provides a C method, then C<< does >> delegates to that. Otherwise, if the scalar being tested is blessed, then C<< $scalar->DOES($role) >> is called, and C returns true if the method call returned true. If the scalar being tested looks like a Perl class name, then C<< $scalar->DOES($role) >> is also called, and the string "0E0" is returned for success, which evaluates to 0 in a numeric context but true in a boolean context. =item C<< does($role) >> Called with a single argument, tests C<< $_ >>. Yes, this works with lexical C<< $_ >>. given ($object) { when(does ARRAY) { ... } when(does HASH) { ... } } Note: in Scalar::Does 0.007 and below the single-argument form of C returned a curried coderef. This was changed in Scalar::Does 0.008. =item C<< overloads($scalar, $role) >> A function C (which just checks overloading) is also available. =item C<< overloads($role) >> Called with a single argument, tests C<< $_ >>. Yes, this works with lexical C<< $_ >>. Note: in Scalar::Does 0.007 and below the single-argument form of C returned a curried coderef. This was changed in Scalar::Does 0.008. =item C<< blessed($scalar) >>, C<< reftype($scalar) >>, C<< looks_like_number($scalar) >> For convenience, this module can also re-export these functions from L. C is generally more useful than C<< does($scalar, q[0+]) >>. =item C<< make_role $name, where { BLOCK } >> Returns an anonymous role object which can be used as a parameter to C. The block is arbitrary code which should check whether $_[0] does the role. =item C<< where { BLOCK } >> Syntactic sugar for C. Compatible with the C function from L, so don't worry about conflicts. =back =head2 Constants The following constants may be exported for convenience: =over =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =back =head2 Export By default, only C is exported. This module uses L, so functions can be renamed: use Scalar::Does does => { -as => 'performs_role' }; Scalar::Does also plays some tricks with L to ensure that any functions it exports to your namespace are cleaned up when you're finished with them. This ensures that if you're writing object-oriented code C and C will not be left hanging around as methods of your classes. L provides a C method, and you should be able to use Scalar::Does without interfering with that. You can import the constants (plus C) using: use Scalar::Does -constants; The C and C functions can be exported like this: use Scalar::Does -make; Or list specific functions/constants that you wish to import: use Scalar::Does qw( does ARRAY HASH STRING NUMBER ); =head2 Custom Role Checks use Scalar::Does custom => { -as => 'does_array', -role => 'ARRAY' }, custom => { -as => 'does_hash', -role => 'HASH' }; does_array($thing); does_hash($thing); =head1 BUGS Please report any bugs to L. =head1 SEE ALSO L. L. =head2 Relationship to Moose roles Scalar::Does is not dependent on Moose, and its role-checking is not specific to Moose's idea of roles, but it does work well with Moose roles. Moose::Object overrides C, so Moose objects and Moose roles should "just work" with Scalar::Does. { package Transport; use Moose::Role; } { package Train; use Moose; with qw(Transport); } my $thomas = Train->new; does($thomas, 'Train'); # true does($thomas, 'Transport'); # true does($thomas, Transport->meta); # not yet supported! L should be compatible enough to work as well. See also: L, L, L. =head2 Relationship to Moose type constraints L objects, plus the constants exported by L libraries all provide a C method, so again, should "just work" with Scalar::Does. Type constraint strings are not supported however. use Moose::Util::TypeConstraints qw(find_type_constraint); use MooseX::Types qw(Int); use Scalar::Does qw(does); my $int = find_type_constraint("Int"); does( "123", $int ); # true does( "123", Int ); # true does( "123", "Int" ); # false Ls and L should be compatible enough to work as well. See also: L, L, L, L. =head2 Relationship to Type::Tiny type constraints Types built with L and L can be used exactly as Moose type constraint objects above. use Types::Standard qw(Int); use Scalar::Does qw(does); does(123, Int); # true In fact, L and related libraries are used extensively in the internals of Scalar::Does 0.200+. See also: L, L. =head2 Relationship to Role::Tiny and Moo roles Roles using Role::Tiny 1.002000 and above provide a C method, so should work with Scalar::Does just like Moose roles. Prior to that release, Role::Tiny did not provide C. Moo's role system is based on Role::Tiny. See also: L, L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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. MooseTypes.pm000644001750001750 411012317646515 17727 0ustar00taitai000000000000Scalar-Does-0.202/lib/Scalar/Doespackage Scalar::Does::MooseTypes; use strict; use warnings; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.202'; use base "Exporter::Tiny"; BEGIN { my @NAMES = qw( Any Item Undef Defined Bool Value Ref Str Num Int CodeRef RegexpRef GlobRef FileHandle Object ClassName RoleName ScalarRef ArrayRef HashRef ); require constant; require Types::Standard; constant->import(+{ map +( $_ => "Types::Standard"->get_type($_) ), @NAMES }); our @EXPORT_OK = @NAMES; our %EXPORT_TAGS = ( constants => \@NAMES, only_constants => \@NAMES, ); } 1; __END__ =head1 NAME Scalar::Does::MooseTypes - (DEPRECATED) additional constants for Scalar::Does, inspired by the built-in Moose type constraints =head1 SYNOPSIS use 5.010; use Scalar::Does qw(does); use Scalar::Does::MooseTypes -all; my $var = []; if (does $var, ArrayRef) { say "It's an arrayref!"; } =head1 STATUS This module is deprecated; use L instead: use 5.010; use Scalar::Does qw(does); use Types::Standard qw(ArrayRef); my $var = []; if (does $var, ArrayRef) { say "It's an arrayref!"; } =head1 DESCRIPTION =head2 Constants =over =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =item C =back =head1 SEE ALSO L. L, L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2012-2014 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.