pax_global_header00006660000000000000000000000064127317557760014536gustar00rootroot0000000000000052 comment=a0919847f848451f7fcb4bee565dabcff76047c4 libperlio-layers-perl-0.011/000077500000000000000000000000001273175577600157555ustar00rootroot00000000000000libperlio-layers-perl-0.011/Build.PL000066400000000000000000000025671273175577600172630ustar00rootroot00000000000000 # This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v5.011. use strict; use warnings; use Module::Build 0.3601; my %module_build_args = ( "build_requires" => { "Module::Build" => "0.3601" }, "configure_requires" => { "Module::Build" => "0.3601" }, "dist_abstract" => "Querying your filehandle's capabilities", "dist_author" => [ "Leon Timmermans " ], "dist_name" => "PerlIO-Layers", "dist_version" => "0.011", "license" => "perl", "module_name" => "PerlIO::Layers", "recommends" => {}, "recursive_test_files" => 1, "requires" => { "Carp" => 0, "Exporter" => "5.57", "List::Util" => 0, "PerlIO" => 0, "XSLoader" => 0, "perl" => "5.008_001", "strict" => 0, "warnings" => 0 }, "script_files" => [], "test_requires" => { "Data::Dumper" => 0, "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Test::More" => "0.82" } ); my %fallback_build_requires = ( "Data::Dumper" => 0, "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Module::Build" => "0.3601", "Test::More" => "0.82" ); unless ( eval { Module::Build->VERSION(0.4004) } ) { delete $module_build_args{test_requires}; $module_build_args{build_requires} = \%fallback_build_requires; } my $build = Module::Build->new(%module_build_args); $build->create_build_script; libperlio-layers-perl-0.011/Changes000066400000000000000000000024251273175577600172530ustar00rootroot00000000000000Revision history for PerlIO-Layers 0.011 2014-03-07 15:20:03CET+0100 Europe/Amsterdam Got rid of natatime/List::MoreUtils Remove problematic test on Windows 0.010 2012-04-05 15:20:18 Europe/Amsterdam Prevent segfault that happened on some systems 0.009 2012-04-04 22:56:42 Europe/Amsterdam Fixed fatal error on Windows on perl 5.14+ Added get_buffer_sized method Added line_buffered and autoflush checks Increased minimal perl version to 5.8.1, as that's when PerlIO::get_layers was introduced. 0.008 2011-05-01 22:40:59 Europe/Bucharest No longer assume :raw can't be can_crlf for perl 5.14 compatibility Converted to Dist::Zilla 0.007 2010-12-21 Made layer type queryable Made layer 'kinds' queryable Added lots of tests 0.006 2010-12-12 Added mappable and mapped tests Added unit tests 0.005 2010-09-08 Fixed unit tests on Windows 0.004 2010-09-06 Added get_layers() 0.003 2010-06-12 Skip some tests on automated testers, as stdin/stdout/stderr may not be open 0.002 2010-06-04 Removed dependency on namespace::clean. 0.001 2010-06-03 First version, released on an unsuspecting world. libperlio-layers-perl-0.011/INSTALL000066400000000000000000000017121273175577600170070ustar00rootroot00000000000000 This is the Perl distribution PerlIO-Layers. Installing PerlIO-Layers is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm PerlIO::Layers 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 PerlIO::Layers ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan PerlIO::Layers ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Build.PL % ./Build && ./Build test Then install it: % ./Build install If you are installing into a system-wide directory, you may need to run: % sudo ./Build install ## Documentation PerlIO-Layers documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc PerlIO::Layers libperlio-layers-perl-0.011/LICENSE000066400000000000000000000436641273175577600167770ustar00rootroot00000000000000This software is copyright (c) 2010 by Leon Timmermans. 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) 2010 by Leon Timmermans. 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) 2010 by Leon Timmermans. 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 libperlio-layers-perl-0.011/MANIFEST000066400000000000000000000004251273175577600171070ustar00rootroot00000000000000# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.011. Build.PL Changes INSTALL LICENSE MANIFEST META.json META.yml README dist.ini lib/PerlIO/Layers.pm lib/PerlIO/Layers.xs t/00-compile.t t/10-basics.t t/release-pod-coverage.t t/release-pod-syntax.t libperlio-layers-perl-0.011/META.json000066400000000000000000000036001273175577600173750ustar00rootroot00000000000000{ "abstract" : "Querying your filehandle's capabilities", "author" : [ "Leon Timmermans " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.011, CPAN::Meta::Converter version 2.132830", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "PerlIO-Layers", "prereqs" : { "build" : { "requires" : { "Module::Build" : "0.3601" } }, "configure" : { "requires" : { "Module::Build" : "0.3601" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Carp" : "0", "Exporter" : "5.57", "List::Util" : "0", "PerlIO" : "0", "XSLoader" : "0", "perl" : "5.008_001", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Data::Dumper" : "0", "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::More" : "0.82" } } }, "provides" : { "PerlIO::Layers" : { "file" : "lib/PerlIO/Layers.pm", "version" : "0.011" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-perlio-layers at rt.cpan.org", "web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=PerlIO-Layers" }, "repository" : { "type" : "git", "url" : "git://github.com/Leont/perlio-layers.git", "web" : "https://github.com/Leont/perlio-layers" } }, "version" : "0.011" } libperlio-layers-perl-0.011/META.yml000066400000000000000000000015301273175577600172250ustar00rootroot00000000000000--- abstract: "Querying your filehandle's capabilities" author: - 'Leon Timmermans ' build_requires: Data::Dumper: 0 File::Spec: 0 IO::Handle: 0 IPC::Open3: 0 Module::Build: 0.3601 Test::More: 0.82 configure_requires: Module::Build: 0.3601 dynamic_config: 0 generated_by: 'Dist::Zilla version 5.011, CPAN::Meta::Converter version 2.132830' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: PerlIO-Layers provides: PerlIO::Layers: file: lib/PerlIO/Layers.pm version: 0.011 requires: Carp: 0 Exporter: 5.57 List::Util: 0 PerlIO: 0 XSLoader: 0 perl: 5.008_001 strict: 0 warnings: 0 resources: bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=PerlIO-Layers repository: git://github.com/Leont/perlio-layers.git version: 0.011 libperlio-layers-perl-0.011/README000066400000000000000000000005741273175577600166430ustar00rootroot00000000000000 This archive contains the distribution PerlIO-Layers, version 0.011: Querying your filehandle's capabilities This software is copyright (c) 2010 by Leon Timmermans. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v5.011. libperlio-layers-perl-0.011/dist.ini000066400000000000000000000002551273175577600174230ustar00rootroot00000000000000name = PerlIO-Layers author = Leon Timmermans license = Perl_5 copyright_holder = Leon Timmermans copyright_year = 2010 [@LEONT] install_tool = mb libperlio-layers-perl-0.011/lib/000077500000000000000000000000001273175577600165235ustar00rootroot00000000000000libperlio-layers-perl-0.011/lib/PerlIO/000077500000000000000000000000001273175577600176555ustar00rootroot00000000000000libperlio-layers-perl-0.011/lib/PerlIO/Layers.pm000066400000000000000000000175451273175577600214660ustar00rootroot00000000000000package PerlIO::Layers; $PerlIO::Layers::VERSION = '0.011'; use 5.008_001; use strict; use warnings FATAL => 'all'; use XSLoader; use PerlIO (); use Carp qw/croak/; use List::Util qw/reduce max/; use Exporter 5.57 qw/import/; our @EXPORT_OK = qw/query_handle get_layers get_buffer_sizes/; XSLoader::load(__PACKAGE__, __PACKAGE__->VERSION); our %FLAG_FOR; sub _names_to_flags { return reduce { $a | $b } map { $FLAG_FOR{$_} } @_; } sub _flag_names { my $flagbits = shift; return grep { $FLAG_FOR{$_} & $flagbits } keys %FLAG_FOR; } sub _has_flags { my $check_flag = _names_to_flags(@_); return sub { my ($fh, $layer) = @_; my @info = PerlIO::get_layers($fh, details => 1); while (my ($name, $arguments, $flags) = splice @info, 0, 3) { next if defined $layer and $name ne $layer; my $entry = $flags & $check_flag; return 1 if $entry; } return 0; } } our %KIND_FOR; sub _is_kind { my $kind = shift; return sub { my $fh = shift; my $kinds = _get_kinds($fh); if (@_) { my $layer = shift; return exists $kinds->{$layer} && $kinds->{$layer} & $KIND_FOR{$kind} ? 1 : 0; } else { return (grep { $kinds->{$_} & $KIND_FOR{$kind} } keys %{$kinds}) ? 1 : 0; } }; } my %is_binary = map { ( $_ => 1) } qw/unix stdio perlio crlf flock creat excl mmap/; my $nonbinary_flags = _names_to_flags('UTF8', 'CRLF'); my $crlf_flags = _names_to_flags('CRLF'); my %layer_query_for = ( writeable => _has_flags('CANWRITE'), readable => _has_flags('CANREAD'), open => _has_flags('OPEN'), temp => _has_flags('TEMP'), crlf => _has_flags('CRLF'), utf8 => _has_flags('UTF8'), binary => sub { my ($fh, $layer) = @_; my @info = PerlIO::get_layers($fh, details => 1); while (my ($name, $arguments, $flags) = splice @info, 0, 3) { next if defined $layer and $name ne $layer; return 0 if not $is_binary{$name} or $flags & $nonbinary_flags; } return 1; }, mappable => sub { my ($fh, $layer) = @_; my @info = PerlIO::get_layers($fh, details => 1); while (my ($name, $arguments, $flags) = splice @info, 0, 3) { next if defined $layer and $name ne $layer; return 0 if not $is_binary{$name} or $flags & $crlf_flags; } return 1; }, layer => sub { my ($fh, $layer) = @_; my @info = PerlIO::get_layers($fh, details => 1); while (my ($name, $arguments, $flags) = splice @info, 0, 3) { return 1 if $name eq $layer; } return 0; }, buffered => _is_kind('BUFFERED'), can_crlf => _is_kind('CANCRLF'), line_buffered => _has_flags('LINEBUF'), autoflush => _has_flags('UNBUF'), buffer_size => sub { my ($handle, $size) = @_; return max(get_buffer_sizes($handle)) == $size; } ); sub query_handle { my ($fh, $query_name, @args) = @_; my $layer_query = $layer_query_for{$query_name} or croak "Query $query_name isn't defined"; return $layer_query->($fh, @args); } sub get_layers { my $fh = shift; my @results; my @info = PerlIO::get_layers($fh, details => 1); while (my ($name, $arguments, $flags) = splice @info, 0, 3) { push @results, [ $name, $arguments, [ _flag_names($flags) ] ]; } return @results; } 1; # End of PerlIO::Layers # ABSTRACT: Querying your filehandle's capabilities __END__ =pod =encoding UTF-8 =head1 NAME PerlIO::Layers - Querying your filehandle's capabilities =head1 VERSION version 0.011 =head1 SYNOPSIS use PerlIO::Layers qw/query_handle/; if (!query_handle(\*STDOUT, 'binary')) { ... } =head1 DESCRIPTION Perl's filehandles are implemented as a stack of layers, with the bottom-most usually doing the actual IO and the higher ones doing buffering, encoding/decoding or transformations. PerlIO::Layers allows you to query the filehandle's properties concerning these layers. =head1 FUNCTIONS =head2 query_handle($fh, $query_name [, $argument]) This query a filehandle for some information. All queries can take an optional argument, that will test for that layer's properties instead of all layers of the handle. Currently supported queries include: =over 4 =item * layer Check the presence of a certain layer. Unlike most other properties C<$argument> is mandatory for this query. =item * utf8 Check whether the filehandle/layer handles unicode =item * crlf Check whether the filehandle/layer does crlf translation =item * binary Check whether the filehandle/layer is binary. This test is pessimistic (for unknown layers it will assume it's not binary). =item * mappable Checks whether the filehandle/layer is memory mappable. It is the same as binary, except that the C layer is accepted. =item * buffered Check whether the filehandle/layer is buffered. =item * readable Check whether the filehandle/layer is readable. =item * writeable Check whether the filehandle/layer is writeable. =item * open Check whether the filehandle/layer is open. =item * temp Check whether the filehandle/layer refers to a temporary file. =item * can_crlf Checks whether layer C<$argument> (or any layer if C<$argument> it not given) can do crlf translation. =item * line_buffered Check whether the filehandle is in line-buffering mode. =item * autoflush Checks wheter the filehandle is in unbuffering mode. Note that this is not the opposite of buffering, but more similar to autoflush, hence the name of this test. =item * buffer_size Check whether the buffer size is equal to C<$argument>. =back =head2 get_layers($fh) Gets information on the layers of a filehandle. It's a list with whose entries have 3 elements: the name of the layer, the arguments of the layer (may be undef) and an arrayref with the flags of the layer as strings. The flags array can contain any of these values: =over 4 =item * EOF End of file has been reached. =item * CANWRITE Writes are permitted, i.e. opened as ">" or "+<" or ">>", etc. =item * CANREAD Reads are permitted i.e. opened "<" or "+>". =item * ERROR An error has occurred. =item * TRUNCATE Truncate file suggested by open mode. =item * APPEND All writes should be appends. =item * CRLF Layer is performing Win32-like "\n" mapped to CR,LF for output and CR,LF mapped to "\n" for input. Normally the provided "crlf" layer is the only layer that need bother about this. C will mess with this flag rather than add/remove layers if the PERLIO_K_CANCRLF bit is set for the layers class. =item * UTF8 Data written to this layer should be UTF-8 encoded; data provided by this layer should be considered UTF-8 encoded. Can be set on any layer by ":utf8" dummy layer. Also set on ":encoding" layer. =item * UNBUF Layer is unbuffered - i.e. write to next layer down should occur for each write to this layer. =item * WRBUF The buffer for this layer currently holds data written to it but not sent to next layer. =item * RDBUF The buffer for this layer currently holds unconsumed data read from layer below. =item * LINEBUF Layer is line buffered. Write data should be passed to next layer down whenever a "\n" is seen. Any data beyond the "\n" should then be processed. =item * TEMP File has been unlink()ed, or should be deleted on close(). =item * OPEN Handle is open. =item * FASTGETS This instance of this layer supports the "fast gets" interface. Normally set based on PERLIO_K_FASTGETS for the class and by the existence of the function(s) in the table. However a class that normally provides that interface may need to avoid it on a particular instance. The "pending" layer needs to do this when it is pushed above a layer which does not support the interface. =back C provides a more high level interface to this, you should probably use that when you can. =head2 get_buffer_sizes($fh) Returns a list of buffer sizes for all buffered layers. Unbuffered layers are skipped. =head1 AUTHOR Leon Timmermans =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Leon Timmermans. 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 libperlio-layers-perl-0.011/lib/PerlIO/Layers.xs000066400000000000000000000034631273175577600214760ustar00rootroot00000000000000#define PERL_NO_GET_CONTEXT #include #include #include #include #define CONSTANT(name, key, value) hv_store(get_hv("PerlIO::Layers::" #name, TRUE), key, sizeof key - 1, newSVuv(value), 0) #define INSTANCE_CONSTANT(cons) CONSTANT(FLAG_FOR, #cons, PERLIO_F_##cons) #define KIND_CONSTANT(cons) CONSTANT(KIND_FOR, #cons, PERLIO_K_##cons) MODULE = PerlIO::Layers PACKAGE = PerlIO::Layers BOOT: INSTANCE_CONSTANT(EOF); INSTANCE_CONSTANT(CANWRITE); INSTANCE_CONSTANT(CANREAD); INSTANCE_CONSTANT(ERROR); INSTANCE_CONSTANT(TRUNCATE); INSTANCE_CONSTANT(APPEND); INSTANCE_CONSTANT(CRLF); INSTANCE_CONSTANT(UTF8); INSTANCE_CONSTANT(UNBUF); INSTANCE_CONSTANT(WRBUF); INSTANCE_CONSTANT(RDBUF); INSTANCE_CONSTANT(LINEBUF); INSTANCE_CONSTANT(TEMP); INSTANCE_CONSTANT(OPEN); INSTANCE_CONSTANT(FASTGETS); KIND_CONSTANT(BUFFERED); KIND_CONSTANT(RAW); KIND_CONSTANT(CANCRLF); KIND_CONSTANT(FASTGETS); KIND_CONSTANT(MULTIARG); KIND_CONSTANT(UTF8); SV* _get_kinds(handle); PerlIO* handle; PREINIT: HV* ret = newHV(); CODE: while (PerlIOBase(handle)) { PerlIOl* current = PerlIOBase(handle); hv_store(ret, current->tab->name, strlen(current->tab->name), newSViv(current->tab->kind), 0); handle = PerlIONext(handle); } RETVAL = newRV_noinc((SV*)ret); OUTPUT: RETVAL IV get_buffer_sizes(handle); PerlIO* handle; PREINIT: PerlIO* current; int counter = 0; PPCODE: for (current = handle; *current; current = PerlIONext(current)) { PerlIOBuf* buffer; if (!(PerlIOBase(current)->tab->kind & PERLIO_K_BUFFERED)) continue; buffer = PerlIOSelf(current, PerlIOBuf); if (!buffer->bufsiz && !buffer->buf) PerlIO_get_base(current); mXPUSHu(buffer->bufsiz); counter++; } if (!counter) Perl_croak(aTHX_ "Handle not buffered, aborting"); PUTBACK; libperlio-layers-perl-0.011/t/000077500000000000000000000000001273175577600162205ustar00rootroot00000000000000libperlio-layers-perl-0.011/t/00-compile.t000066400000000000000000000016651273175577600202620ustar00rootroot00000000000000use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.036 use Test::More tests => 1 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'PerlIO/Layers.pm' ); # no fake home requested my $inc_switch = q[-Mblib]; use File::Spec; use IPC::Open3; use IO::Handle; my @warnings; for my $lib (@module_files) { # see L open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') if $ENV{AUTHOR_TESTING}; libperlio-layers-perl-0.011/t/10-basics.t000066400000000000000000000063641273175577600201000ustar00rootroot00000000000000#!perl use strict; use warnings FATAL => 'all'; use Test::More 0.82; use Data::Dumper; use List::Util 'max'; use PerlIO::Layers qw/query_handle get_layers get_buffer_sizes/; my %flags = map { ($_ => 1) } map { @{ $_->[2] } } get_layers(\*STDOUT); ok $flags{CANWRITE}, 'STDOUT has CANWRITE flag'; is(query_handle(\*STDIN, 'readable'), 1, 'stdin is readable'); is(query_handle(\*STDIN, 'writeable'), 0, 'stdin is not writable'); is(query_handle(\*STDOUT, 'readable'), 0, 'stdout is readable'); is(query_handle(\*STDOUT, 'writeable'), 1, 'stdout is not writable'); is(query_handle(\*STDOUT, 'buffered'), 1, 'stdout is buffered'); is(query_handle(\*STDERR, 'readable'), 0, 'stderr is readable'); is(query_handle(\*STDERR, 'writeable'), 1, 'stderr is not writable'); is(query_handle(\*STDERR, 'buffered'), 1, 'stderr is buffered'); my $is_win32 = int($^O eq 'MSWin32'); my $not_win32 = int !$is_win32; is(query_handle(\*STDIN, 'crlf'), $is_win32, 'crlf is only true on Windows'); my @types = ( ['<', utf8 => 0, binary => $not_win32, mappable => $not_win32, crlf => $is_win32, buffered => 1, can_crlf => { unix => 0, crlf => $is_win32 }, 'line_buffered' => 0 ], ['<:bytes', layer => { crlf => $is_win32 }, utf8 => 0, binary => $not_win32, mappable => $not_win32, crlf => $is_win32, can_crlf => $is_win32, buffered => 1], ['<:raw', layer => { unix => 1 }, utf8 => 0, binary => 1, mappable => 1, crlf => 0], ['<:raw:perlio', layer => { unix => 1, perlio => 1 }, utf8 => 0, binary => 1, mappable => 1, crlf => 0, buffered => 1 ], ['<:utf8', layer => { utf8 => 0 }, utf8 => 1, binary => 0, mappable => $not_win32, crlf => $is_win32], ['<:raw:utf8', layer => { unix => 1 }, utf8 => 1, binary => 0, mappable => 1, crlf => 0], ['<:encoding(utf8)', layer => { encoding => 1 }, utf8 => 1, binary => 0, mappable => 0], ['<:encoding(utf-8)', layer => { encoding => 1 }, utf8 => 1, binary => 0, mappable => 0], ['<:encoding(UTF-8)', layer => { encoding => 1 }, utf8 => 1, binary => 0, mappable => 0], ['<:encoding(latin1)', layer => { encoding => 1 }, utf8 => 1, binary => 0, mappable => 0], ['<:crlf', layer => { crlf => 1 }, utf8 => 0, binary => 0, mappable => 0, crlf => 1], ['<:pop', layer => { perlio => 0, crlf => 0, stdio => 0 }, buffered => 0, can_crlf => 0] ); if ($^O ne 'MSWin32') { push @types, ['<:mmap', 'layer' => { mmap => 1 }, utf8 => 0, binary => 1, mappable => 1, crlf => 0, buffered => 1, can_crlf => 0]; } { open my $fh, '<', $0 or die $!; #scalar <$fh>; my @sizes = get_buffer_sizes($fh); ok(max(@sizes), 'non zero buffer size for handle') or diag('Sizes are: ', explain(\@sizes)); } for my $type (@types) { my ($mode, %result_for) = @{$type}; open my $fh, $mode, $0 or BAIL_OUT("Open failed: $!"); for my $test_type (keys %result_for) { if (ref($result_for{$test_type})) { my %compound = %{ $result_for{$test_type} }; for my $subtype (keys %compound) { is query_handle($fh, $test_type, $subtype), $compound{$subtype}, "File opened with $mode should return $compound{$subtype} on test $test_type($subtype)" or diag Dumper get_layers($fh); } } else { is query_handle($fh, $test_type), $result_for{$test_type}, "File opened with $mode should return $result_for{$test_type} on test $test_type" or diag Dumper get_layers($fh); } } } done_testing(); libperlio-layers-perl-0.011/t/release-pod-coverage.t000066400000000000000000000011071273175577600223750ustar00rootroot00000000000000#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::More; eval "use Test::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); libperlio-layers-perl-0.011/t/release-pod-syntax.t000066400000000000000000000005701273175577600221330ustar00rootroot00000000000000#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok();