IO-Termios-0.10000755001750001750 014643477232 12116 5ustar00leoleo000000000000IO-Termios-0.10/.editorconfig000444001750001750 5314643477232 14666 0ustar00leoleo000000000000root = true [*.{pm,pl,t}] indent_size = 3 IO-Termios-0.10/Build.PL000444001750001750 73214643477232 13531 0ustar00leoleo000000000000use v5; use strict; use warnings; use Module::Build; my $build = Module::Build->new( module_name => 'IO::Termios', configure_requires => { 'Module::Build' => '0.4004', # test_requires }, requires => { 'perl' => '5.014', 'IO::Tty' => 0, }, test_requires => { 'IO::Tty' => 0, 'IO::Pty' => 0, 'Test2::V0' => 0, }, license => 'perl', create_license => 1, create_readme => 1, ); $build->create_build_script; IO-Termios-0.10/Changes000444001750001750 333414643477232 13551 0ustar00leoleo000000000000Revision history for IO-Termios 0.10 2024-07-10 [CHANGES] * Module style updates: + Use perl 5.14 `package NAME VER` syntax + Use Test2::V0 instead of Test::More + Test::LongString 0.09 2020-09-03 22:48 [CHANGES] * Added ->setflags convenience function for setting multiple flags at once * Added support for INLCR, IGNCR, ICRNL, IGNBRK, BRKINT and PARMRK flags 0.08 2019-09-09 18:24:10 [CHANGES] * Added `-upgrade` import option 0.07 2018-10-09 22:18:32 [CHANGES] * Added support for OPOST flag * Added cfmakeraw() [BUGFIXES] * Declare dependency on perl 5.10+ because of // operator (RT125619) 0.06 2018-06-04 23:04:40 [CHANGES] * Support additional `sysopen()` flags to IO::Termios->open() 0.05 2016/06/06 01:37:24 [CHANGES] * Opportunistically use Linux::Termios2 if available for arbitrary baudrate support * Name tiocmbic / tiocmbis correctly [BUGFIXES] * Fix the sense of the ICANON mode documentation * select() for readability of O_NONBLOCK handles before sysread during unit tests 0.04 2013/12/23 10:58:30 [CHANGES] * Added wrapper methods for modem line control bits * Added more documentation to mention "serial ports" 0.03 2013/12/20 21:10:33 [CHANGES] * Added ->set_mode and ->get_mode convenience methods * Added $modestr parameter to IO::Termios->open() constructor 0.02 CHANGES: * Added accessors for CREAD, CLOCAL and HUPCL c_cflags flags. 0.01 First version, released on an unsuspecting world. IO-Termios-0.10/LICENSE000444001750001750 4653414643477232 13314 0ustar00leoleo000000000000This software is copyright (c) 2024 by Paul Evans . 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) 2024 by Paul Evans . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Perl Artistic License 1.0 --- This software is Copyright (c) 2024 by Paul Evans . This is free software, licensed under: The Perl 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 as specified below. "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 uunet.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) give non-standard executables non-standard names, and clearly document 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. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 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 whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End IO-Termios-0.10/MANIFEST000444001750001750 22114643477232 13357 0ustar00leoleo000000000000.editorconfig Build.PL Changes lib/IO/Termios.pm MANIFEST This list of files t/00use.t t/01flags.t t/99pod.t README LICENSE META.yml META.json IO-Termios-0.10/META.json000444001750001750 213714643477232 13677 0ustar00leoleo000000000000{ "abstract" : "supply F methods to C objects", "author" : [ "Paul Evans " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4234", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "IO-Termios", "prereqs" : { "configure" : { "requires" : { "Module::Build" : "0.4004" } }, "runtime" : { "requires" : { "IO::Tty" : "0", "perl" : "5.014" } }, "test" : { "requires" : { "IO::Pty" : "0", "IO::Tty" : "0", "Test2::V0" : "0" } } }, "provides" : { "IO::Termios" : { "file" : "lib/IO/Termios.pm", "version" : "0.10" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "0.10", "x_serialization_backend" : "JSON::PP version 4.16" } IO-Termios-0.10/META.yml000444001750001750 126614643477232 13531 0ustar00leoleo000000000000--- abstract: 'supply F methods to C objects' author: - 'Paul Evans ' build_requires: IO::Pty: '0' IO::Tty: '0' Test2::V0: '0' configure_requires: Module::Build: '0.4004' dynamic_config: 1 generated_by: 'Module::Build version 0.4234, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: IO-Termios provides: IO::Termios: file: lib/IO/Termios.pm version: '0.10' requires: IO::Tty: '0' perl: '5.014' resources: license: http://dev.perl.org/licenses/ version: '0.10' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' IO-Termios-0.10/README000444001750001750 2421014643477232 13152 0ustar00leoleo000000000000NAME IO::Termios - supply termios(3) methods to IO::Handle objects SYNOPSIS use IO::Termios; my $term = IO::Termios->open( "/dev/ttyS0", "9600,8,n,1" ) or die "Cannot open ttyS0 - $!"; $term->print( "Hello world\n" ); # Still an IO::Handle while( <$term> ) { print "A line from ttyS0: $_"; } DESCRIPTION This class extends the generic IO::Handle object class by providing methods which access the system's terminal control termios(3) operations. These methods are primarily of interest when dealing with TTY devices, including serial ports. The flag-setting methods will apply to any TTY device, such as a pseudo-tty, and are useful for controlling such flags as the ECHO flag, to disable local echo. my $stdin = IO::Termios->new( \*STDIN ); $stdin->setflag_echo( 0 ); When dealing with a serial port the line mode method is useful for setting the basic serial parameters such as baud rate, and the modem line control methods can be used to access the hardware handshaking lines. my $ttyS0 = IO::Termios->open( "/dev/ttyS0" ); $ttyS0->set_mode( "19200,8,n,1" ); $ttyS0->set_modem({ dsr => 1, cts => 1 }); Upgrading STDIN/STDOUT/STDERR If you pass the -upgrade option at import time, any of STDIN, STDOUT or STDERR that are found to be TTY wrappers are automatically upgraded into IO::Termios instances. use IO::Termios -upgrade; STDIN->setflag_echo(0); Arbitrary Baud Rates on Linux Linux supports a non-POSIX extension to the usual termios interface, which allows arbitrary baud rates to be set. IO::Termios can automatically make use of this ability if the Linux::Termios2 module is installed. If so, this will be used automatically and transparently, to allow the set*baud methods to set any rate allowed by the kernel/driver. If not, then only the POSIX-compatible rates may be used. CONSTRUCTORS new $term = IO::Termios->new(); Construct a new IO::Termios object around the terminal for the program. This is found by checking if any of STDIN, STDOUT or STDERR are a terminal. The first one that's found is used. An error occurs if no terminal can be found by this method. new (handle) $term = IO::Termios->new( $handle ); Construct a new IO::Termios object around the given filehandle. open $term = IO::Termios->open( $path, $modestr, $flags ); Open the given path, and return a new IO::Termios object around the filehandle. If the open call fails, undef is returned. If $modestr is provided, the constructor will pass it to the set_mode method before returning. If $flags is provided, it will be passed on to the underlying sysopen() call used to open the filehandle. It should contain a bitwise-or combination of O_* flags from the Fcntl module - for example O_NOCTTY or O_NDELAY. The value O_RDWR will be added to this; the caller does not need to specify it directly. For example: use Fcntl qw( O_NOCTTY O_NDELAY ); $term = IO::Termios->open( "/dev/ttyS0", O_NOCTTY|O_NDELAY ); $term->setflag_clocal( 1 ); $term->blocking( 1 ); METHODS getattr $attrs = $term->getattr; Makes a tcgetattr() call on the underlying filehandle, and returns a IO::Termios::Attrs object. If the tcgetattr() call fails, undef is returned. setattr $term->setattr( $attrs ); Makes a tcsetattr() call on the underlying file handle, setting attributes from the given IO::Termios::Attrs object. If the tcsetattr() call fails, undef is returned. Otherwise, a true value is returned. set_mode get_mode $term->set_mode( $modestr ); $modestr = $term->get_mode; Accessor for the derived "mode string", which is a comma-joined concatenation of the baud rate, character size, parity mode, and stop size in a format such as 19200,8,n,1 When setting the mode string, trailing components may be omitted meaning their value will not be affected. tiocmget tiocmset $bits = $term->tiocmget; $term->tiocmset( $bits ); Accessor for the modem line control bits. Takes or returns a bitmask of values. tiocmbic tiocmbis $term->tiocmbic( $bits ); $term->tiocmbis( $bits ); Bitwise mutator methods for the modem line control bits. tiocmbic will clear just the bits provided and leave the others unchanged; tiocmbis will set them. get_modem $flags = $term->get_modem; Returns a hash reference containing named flags corresponding to the modem line control bits. Any bit that is set will yield a key in the returned hash of the same name. The bit names are dtr dsr rts cts cd ri set_modem $term->set_modem( $flags ); Changes the modem line control bit flags as given by the hash reference. Each bit to be changed should be represented by a key in the $flags hash of the names given above. False values will be cleared, true values will be set. Other flags will not be altered. getmodem_BIT setmodem_BIT $set = $term->getmodem_BIT; $term->setmodem_BIT( $set ); Accessor methods for each of the modem line control bits. A set of methods exists for each of the named modem control bits given above. FLAG-ACCESSOR METHODS Theses methods are implemented in terms of the lower level methods, but provide an interface which is more abstract, and easier to re-implement on other non-POSIX systems. These should be used in preference to the lower ones. For efficiency, when getting or setting a large number of flags, it may be more efficient to call getattr, then operate on the returned object, before possibly passing it to setattr. The returned IO::Termios::Attrs object supports the same methods as documented here. The following two sections of code are therefore equivalent, though the latter is more efficient as it only calls setattr once. $term->setbaud( 38400 ); $term->setcsize( 8 ); $term->setparity( 'n' ); $term->setstop( 1 ); my $attrs = $term->getattr; $attrs->setbaud( 38400 ); $attrs->setcsize( 8 ); $attrs->setparity( 'n' ); $attrs->setstop( 1 ); $term->setattr( $attrs ); However, a convenient shortcut method is provided for the common case of setting the baud rate, character size, parity and stop size all at the same time. This is set_mode: $term->set_mode( "38400,8,n,1" ); getibaud getobaud setibaud setobaud setbaud $baud = $term->getibaud; $baud = $term->getobaud; $term->setibaud( $baud ); $term->setobaud( $baud ); $term->setbaud( $baud ); Convenience accessors for the ispeed and ospeed. $baud is an integer directly giving the line rate, instead of one of the Bnnn constants. getcsize setcsize $bits = $term->getcsize; $term->setcsize( $bits ); Convenience accessor for the CSIZE bits of c_cflag. $bits is an integer 5 to 8. getparity setparity $parity = $term->getparity; $term->setparity( $parity ); Convenience accessor for the PARENB and PARODD bits of c_cflag. $parity is n, o or e. getstop setstop $stop = $term->getstop; $term->setstop( $stop ); Convenience accessor for the CSTOPB bit of c_cflag. $stop is 1 or 2. cfmakeraw $term->cfmakeraw; Since version 0.07. Adjusts several bit flags to put the terminal into a "raw" mode. Input is available a character at a time, echo is disabled, and all special processing of input and output characters is disabled. getflag_FLAG setflag_FLAG $mode = $term->getflag_FLAG; $term->setflag_FLAG( $mode ); Accessors for various control flags. The following methods are defined for specific flags: inlcr Since version 0.09. The INLCR bit of the c_iflag. This translates NL to CR on input. igncr Since version 0.09. The IGNCR bit of the c_iflag. This ignores incoming CR characters. icrnl Since version 0.09. The ICRNL bit of the c_iflag. This translates CR to NL on input, unless IGNCR is also set. ignbrk Since version 0.09. The IGNBRK bit of the c_iflag. This controls whether incoming break conditions are ignored entirely. brkint Since version 0.09. The BRKINT bit of the c_iflag. This controls whether non-ignored incoming break conditions result in a SIGINT signal being delivered to the process. If not, such a condition reads as a nul byte. parmrk Since version 0.09. The PARMRK bit of the c_iflag. This controls how parity errors and break conditions are handled. opost Since version 0.07. The OPOST bit of the c_oflag. This enables system-specific post-processing on output. cread The CREAD bit of the c_cflag. This enables the receiver. hupcl The HUPCL bit of the c_cflag. This lowers the modem control lines after the last process closes the device. clocal The CLOCAL bit of the c_cflag. This controls whether local mode is enabled; which if set, ignores modem control lines. icanon The ICANON bit of c_lflag. This is called "canonical" mode and controls whether the terminal's line-editing feature will be used to return a whole line (if true), or if individual bytes from keystrokes will be returned as they are available (if false). echo The ECHO bit of c_lflag. This controls whether input characters are echoed back to the terminal. setflags $term->setflags( @flags ); Since version 0.09. A convenient wrapper to calling multiple flag setting methods in a sequence. Each flag is specified by name, in lower case, prefixed by either a + symbol to enable it, or - to disable. For example: $term->setflags( "+igncr", "+opost", "+clocal", "-echo" ); TODO * Adding more getflag_*/setflag_* convenience wrappers SEE ALSO * IO::Tty - Import Tty control constants AUTHOR Paul Evans IO-Termios-0.10/lib000755001750001750 014643477232 12664 5ustar00leoleo000000000000IO-Termios-0.10/lib/IO000755001750001750 014643477232 13173 5ustar00leoleo000000000000IO-Termios-0.10/lib/IO/Termios.pm000444001750001750 5006314643477232 15334 0ustar00leoleo000000000000# You may distribute under the terms of either the GNU General Public License # or the Artistic License (the same terms as Perl itself) # # (C) Paul Evans, 2008-2024 -- leonerd@leonerd.org.uk package IO::Termios 0.10; use v5.14; use warnings; use base qw( IO::Handle ); use Carp; use Exporter (); use Fcntl qw( O_RDWR ); use POSIX qw( TCSANOW ); use IO::Tty; use IO::Tty::Constant qw( TIOCMGET TIOCMSET TIOCMBIC TIOCMBIS TIOCM_DTR TIOCM_DSR TIOCM_RTS TIOCM_CTS TIOCM_CD TIOCM_RI ); # Linux can support finer-grained control of baud rates if we let it use constant HAVE_LINUX_TERMIOS2 => eval { require Linux::Termios2; }; =head1 NAME C - supply F methods to C objects =head1 SYNOPSIS use IO::Termios; my $term = IO::Termios->open( "/dev/ttyS0", "9600,8,n,1" ) or die "Cannot open ttyS0 - $!"; $term->print( "Hello world\n" ); # Still an IO::Handle while( <$term> ) { print "A line from ttyS0: $_"; } =head1 DESCRIPTION This class extends the generic C object class by providing methods which access the system's terminal control C operations. These methods are primarily of interest when dealing with TTY devices, including serial ports. The flag-setting methods will apply to any TTY device, such as a pseudo-tty, and are useful for controlling such flags as the C flag, to disable local echo. my $stdin = IO::Termios->new( \*STDIN ); $stdin->setflag_echo( 0 ); When dealing with a serial port the line mode method is useful for setting the basic serial parameters such as baud rate, and the modem line control methods can be used to access the hardware handshaking lines. my $ttyS0 = IO::Termios->open( "/dev/ttyS0" ); $ttyS0->set_mode( "19200,8,n,1" ); $ttyS0->set_modem({ dsr => 1, cts => 1 }); =head2 Upgrading STDIN/STDOUT/STDERR If you pass the C<-upgrade> option at C time, any of STDIN, STDOUT or STDERR that are found to be TTY wrappers are automatically upgraded into C instances. use IO::Termios -upgrade; STDIN->setflag_echo(0); =head2 Arbitrary Baud Rates on Linux F supports a non-POSIX extension to the usual C interface, which allows arbitrary baud rates to be set. C can automatically make use of this ability if the L module is installed. If so, this will be used automatically and transparently, to allow the C methods to set any rate allowed by the kernel/driver. If not, then only the POSIX-compatible rates may be used. =cut sub import { my $pkg = shift; my @symbols = @_; my $caller = caller; my $upgrade; @symbols = grep { $_ eq "-upgrade" ? ( $upgrade++, 0 ) : 1 } @symbols; if( $upgrade ) { foreach my $fh ( *STDIN{IO}, *STDOUT{IO}, *STDERR{IO} ) { IO::Termios::Attrs->new->getattr( $fh->fileno ) or next; bless $fh, __PACKAGE__; } } } =head1 CONSTRUCTORS =cut =head2 new $term = IO::Termios->new(); Construct a new C object around the terminal for the program. This is found by checking if any of C, C or C are a terminal. The first one that's found is used. An error occurs if no terminal can be found by this method. =head2 new (handle) $term = IO::Termios->new( $handle ); Construct a new C object around the given filehandle. =cut sub new { my $class = shift; my ( $handle ) = @_; if( not $handle ) { # Try to find a terminal - STDIN, STDOUT, STDERR are good candidates return $class->SUPER::new_from_fd( fileno STDIN, "w+" ) if -t STDIN; return $class->SUPER::new_from_fd( fileno STDOUT, "w+" ) if -t STDOUT; return $class->SUPER::new_from_fd( fileno STDERR, "w+" ) if -t STDERR; die "TODO: Need to find a terminal\n"; } croak '$handle is not a filehandle' unless defined fileno $handle; my $self = $class->SUPER::new_from_fd( $handle, "w+" ); return $self; } =head2 open $term = IO::Termios->open( $path, $modestr, $flags ); Open the given path, and return a new C object around the filehandle. If the C call fails, C is returned. If C<$modestr> is provided, the constructor will pass it to the C method before returning. If C<$flags> is provided, it will be passed on to the underlying C call used to open the filehandle. It should contain a bitwise-or combination of C flags from the L module - for example C or C. The value C will be added to this; the caller does not need to specify it directly. For example: use Fcntl qw( O_NOCTTY O_NDELAY ); $term = IO::Termios->open( "/dev/ttyS0", O_NOCTTY|O_NDELAY ); $term->setflag_clocal( 1 ); $term->blocking( 1 ); =cut sub open { my $class = shift; my ( $path, $modestr, $flags ) = @_; $flags //= 0; sysopen my $tty, $path, O_RDWR | $flags, or return undef; my $self = $class->new( $tty ) or return undef; $self->set_mode( $modestr ) if defined $modestr; return $self; } =head1 METHODS =cut =head2 getattr $attrs = $term->getattr; Makes a C call on the underlying filehandle, and returns a C object. If the C call fails, C is returned. =cut sub getattr { my $self = shift; my $attrs = IO::Termios::Attrs->new; $attrs->getattr( $self->fileno ) or return undef; return $attrs; } =head2 setattr $term->setattr( $attrs ); Makes a C call on the underlying file handle, setting attributes from the given C object. If the C call fails, C is returned. Otherwise, a true value is returned. =cut sub setattr { my $self = shift; my ( $attrs ) = @_; return $attrs->setattr( $self->fileno, TCSANOW ); } =head2 set_mode =head2 get_mode $term->set_mode( $modestr ); $modestr = $term->get_mode; Accessor for the derived "mode string", which is a comma-joined concatenation of the baud rate, character size, parity mode, and stop size in a format such as 19200,8,n,1 When setting the mode string, trailing components may be omitted meaning their value will not be affected. =cut sub set_mode { my $self = shift; my ( $modestr ) = @_; my ( $baud, $csize, $parity, $stop ) = split m/,/, $modestr; my $attrs = $self->getattr; $attrs->setbaud ( $baud ) if defined $baud; $attrs->setcsize ( $csize ) if defined $csize; $attrs->setparity( $parity ) if defined $parity; $attrs->setstop ( $stop ) if defined $stop; $self->setattr( $attrs ); } sub get_mode { my $self = shift; my $attrs = $self->getattr; return join ",", $attrs->getibaud, $attrs->getcsize, $attrs->getparity, $attrs->getstop; } =head2 tiocmget =head2 tiocmset $bits = $term->tiocmget; $term->tiocmset( $bits ); Accessor for the modem line control bits. Takes or returns a bitmask of values. =cut sub tiocmget { my $self = shift; my $bitstr = pack "i!", 0; ioctl( $self, TIOCMGET, $bitstr ) or croak "Cannot ioctl(TIOCMGET) - $!"; return unpack "i!", $bitstr; } sub tiocmset { my $self = shift; my ( $bits ) = @_; my $bitstr = pack "i!", $bits; ioctl( $self, TIOCMSET, $bitstr ) or croak "Cannot ioctl(TIOCMSET) - $!"; } =head2 tiocmbic =head2 tiocmbis $term->tiocmbic( $bits ); $term->tiocmbis( $bits ); Bitwise mutator methods for the modem line control bits. C will clear just the bits provided and leave the others unchanged; C will set them. =cut sub tiocmbic { my $self = shift; my ( $bits ) = @_; my $bitstr = pack "i!", $bits; ioctl( $self, TIOCMBIC, $bitstr ) or croak "Cannot ioctl(TIOCMBIC) - $!"; } sub tiocmbis { my $self = shift; my ( $bits ) = @_; my $bitstr = pack "i!", $bits; ioctl( $self, TIOCMBIS, $bitstr ) or croak "Cannot ioctl(TIOCMBIS) - $!"; } my %_bit2modem; my %_modem2bit; foreach (qw( dtr dsr rts cts cd ri )) { my $bit = IO::Tty::Constant->${\"TIOCM_\U$_"}; $_bit2modem{$bit} = $_; $_modem2bit{$_} = $bit; my $getmodem = sub { my $self = shift; return !!($self->tiocmget & $bit); }; my $setmodem = sub { my $self = shift; my ( $set ) = @_; $set ? $self->tiocmbis( $bit ) : $self->tiocmbic( $bit ); }; no strict 'refs'; *{"getmodem_$_"} = $getmodem; *{"setmodem_$_"} = $setmodem; } =head2 get_modem $flags = $term->get_modem; Returns a hash reference containing named flags corresponding to the modem line control bits. Any bit that is set will yield a key in the returned hash of the same name. The bit names are dtr dsr rts cts cd ri =cut sub get_modem { my $self = shift; my $bits = $self->tiocmget; return +{ map { $bits & $_modem2bit{$_} ? ( $_ => 1 ) : () } keys %_modem2bit }; } =head2 set_modem $term->set_modem( $flags ); Changes the modem line control bit flags as given by the hash reference. Each bit to be changed should be represented by a key in the C<$flags> hash of the names given above. False values will be cleared, true values will be set. Other flags will not be altered. =cut sub set_modem { my $self = shift; my ( $flags ) = @_; my $bits = $self->tiocmget; foreach ( keys %$flags ) { my $bit = $_modem2bit{$_} or croak "Unrecognised modem line control bit $_"; $flags->{$_} ? ( $bits |= $bit ) : ( $bits &= ~$bit ); } $self->tiocmset( $bits ); } =head2 getmodem_BIT =head2 setmodem_BIT $set = $term->getmodem_BIT; $term->setmodem_BIT( $set ); Accessor methods for each of the modem line control bits. A set of methods exists for each of the named modem control bits given above. =head1 FLAG-ACCESSOR METHODS Theses methods are implemented in terms of the lower level methods, but provide an interface which is more abstract, and easier to re-implement on other non-POSIX systems. These should be used in preference to the lower ones. For efficiency, when getting or setting a large number of flags, it may be more efficient to call C, then operate on the returned object, before possibly passing it to C. The returned C object supports the same methods as documented here. The following two sections of code are therefore equivalent, though the latter is more efficient as it only calls C once. $term->setbaud( 38400 ); $term->setcsize( 8 ); $term->setparity( 'n' ); $term->setstop( 1 ); Z<> my $attrs = $term->getattr; $attrs->setbaud( 38400 ); $attrs->setcsize( 8 ); $attrs->setparity( 'n' ); $attrs->setstop( 1 ); $term->setattr( $attrs ); However, a convenient shortcut method is provided for the common case of setting the baud rate, character size, parity and stop size all at the same time. This is C: $term->set_mode( "38400,8,n,1" ); =cut =head2 getibaud =head2 getobaud =head2 setibaud =head2 setobaud =head2 setbaud $baud = $term->getibaud; $baud = $term->getobaud; $term->setibaud( $baud ); $term->setobaud( $baud ); $term->setbaud( $baud ); Convenience accessors for the C and C. C<$baud> is an integer directly giving the line rate, instead of one of the C> constants. =head2 getcsize =head2 setcsize $bits = $term->getcsize; $term->setcsize( $bits ); Convenience accessor for the C bits of C. C<$bits> is an integer 5 to 8. =head2 getparity =head2 setparity $parity = $term->getparity; $term->setparity( $parity ); Convenience accessor for the C and C bits of C. C<$parity> is C, C or C. =head2 getstop =head2 setstop $stop = $term->getstop; $term->setstop( $stop ); Convenience accessor for the C bit of C. C<$stop> is 1 or 2. =head2 cfmakeraw $term->cfmakeraw; I Adjusts several bit flags to put the terminal into a "raw" mode. Input is available a character at a time, echo is disabled, and all special processing of input and output characters is disabled. =cut foreach my $name (qw( ibaud obaud csize parity stop )) { my $getmethod = "get$name"; my $setmethod = "set$name"; no strict 'refs'; *$getmethod = sub { my ( $self ) = @_; my $attrs = $self->getattr or croak "Cannot getattr - $!"; return $attrs->$getmethod; }; *$setmethod = sub { my ( $self, $val ) = @_; my $attrs = $self->getattr or croak "Cannot getattr - $!"; $attrs->$setmethod( $val ); $self->setattr( $attrs ) or croak "Cannot setattr - $!"; }; } foreach my $method (qw( setbaud cfmakeraw )) { no strict 'refs'; *$method = sub { my $self = shift; my $attrs = $self->getattr or croak "Cannot getattr - $!"; $attrs->$method( @_ ); $self->setattr( $attrs ) or croak "Cannot setattr - $!"; }; } =head2 getflag_I =head2 setflag_I $mode = $term->getflag_FLAG; $term->setflag_FLAG( $mode ); Accessors for various control flags. The following methods are defined for specific flags: =head3 inlcr I The C bit of the C. This translates NL to CR on input. =head3 igncr I The C bit of the C. This ignores incoming CR characters. =head3 icrnl I The C bit of the C. This translates CR to NL on input, unless C is also set. =head3 ignbrk I The C bit of the C. This controls whether incoming break conditions are ignored entirely. =head3 brkint I The C bit of the C. This controls whether non-ignored incoming break conditions result in a C signal being delivered to the process. If not, such a condition reads as a nul byte. =head3 parmrk I The C bit of the C. This controls how parity errors and break conditions are handled. =head3 opost I The C bit of the C. This enables system-specific post-processing on output. =head3 cread The C bit of the C. This enables the receiver. =head3 hupcl The C bit of the C. This lowers the modem control lines after the last process closes the device. =head3 clocal The C bit of the C. This controls whether local mode is enabled; which if set, ignores modem control lines. =head3 icanon The C bit of C. This is called "canonical" mode and controls whether the terminal's line-editing feature will be used to return a whole line (if true), or if individual bytes from keystrokes will be returned as they are available (if false). =head3 echo The C bit of C. This controls whether input characters are echoed back to the terminal. =cut my @flags = ( # iflag [ inlcr => qw( INLCR i ) ], [ igncr => qw( IGNCR i ) ], [ icrnl => qw( ICRNL i ) ], [ ignbrk => qw( IGNBRK i ) ], [ brkint => qw( BRKINT i ) ], [ parmrk => qw( PARMRK i ) ], # oflag [ opost => qw( OPOST o ) ], # cflag [ cread => qw( CREAD c ) ], [ clocal => qw( CLOCAL c ) ], [ hupcl => qw( HUPCL c ) ], # lflag [ icanon => qw( ICANON l ) ], [ echo => qw( ECHO l ) ], ); foreach ( @flags ) { my ( $name ) = @$_; my $getmethod = "getflag_$name"; my $setmethod = "setflag_$name"; no strict 'refs'; *$getmethod = sub { my ( $self ) = @_; my $attrs = $self->getattr or croak "Cannot getattr - $!"; return $attrs->$getmethod; }; *$setmethod = sub { my ( $self, $set ) = @_; my $attrs = $self->getattr or croak "Cannot getattr - $!"; $attrs->$setmethod( $set ); $self->setattr( $attrs ) or croak "Cannot setattr - $!"; }; } =head2 setflags $term->setflags( @flags ); I A convenient wrapper to calling multiple flag setting methods in a sequence. Each flag is specified by name, in lower case, prefixed by either a C<+> symbol to enable it, or C<-> to disable. For example: $term->setflags( "+igncr", "+opost", "+clocal", "-echo" ); =cut sub setflags { my $self = shift; my @flags = @_; my $attrs = $self->getattr or croak "Cannot getattr - $!"; foreach my $flag ( @flags ) { my $sense = 1; $sense = 0 if $flag =~ s/^-//; $flag =~ s/^\+//; my $method = "setflag_$flag"; $attrs->$method( $sense ); } $self->setattr( $attrs ) or croak "Cannot setattr - $!"; } package # hide from CPAN IO::Termios::Attrs; use Carp; use POSIX qw( CSIZE CS5 CS6 CS7 CS8 PARENB PARODD CSTOPB IGNBRK BRKINT PARMRK ISTRIP INLCR IGNCR ICRNL IXON OPOST ECHO ECHONL ICANON ISIG IEXTEN ); # IO::Tty has more B<\d> constants than POSIX has use IO::Tty; # Simple XS-implemented classes tend not to respect subclassing sub new { my $class = shift; my $self = $class->SUPER::new; bless $self, $class; return $self; } if( IO::Termios::HAVE_LINUX_TERMIOS2 ) { our @ISA = qw( Linux::Termios2 ); # baud is directly applicable *getibaud = __PACKAGE__->can( 'getispeed' ); *getobaud = __PACKAGE__->can( 'getospeed' ); *setibaud = __PACKAGE__->can( 'setispeed' ); *setobaud = __PACKAGE__->can( 'setospeed' ); } else { our @ISA = qw( POSIX::Termios ); # baud needs converting to/from the speed_t constants my %_speed2baud = map { IO::Tty::Constant->${\"B$_"} => $_ } qw( 0 50 75 110 134 150 200 300 600 1200 2400 4800 9600 19200 38400 57600 115200 230400 ); my %_baud2speed = reverse %_speed2baud; *getibaud = sub { $_speed2baud{ $_[0]->getispeed } }; *getobaud = sub { $_speed2baud{ $_[0]->getospeed } }; *setibaud = sub { $_[0]->setispeed( $_baud2speed{$_[1]} // die "Unrecognised baud rate" ); }; *setobaud = sub { $_[0]->setospeed( $_baud2speed{$_[1]} // die "Unrecognised baud rate" ); }; } sub setbaud { $_[0]->setibaud( $_[1] ); $_[0]->setobaud( $_[1] ); } foreach ( @flags ) { my ( $name, $const, $member ) = @$_; $const = POSIX->$const(); my $getmethod = "getflag_$name"; my $getflag = "get${member}flag"; my $setmethod = "setflag_$name"; my $setflag = "set${member}flag"; no strict 'refs'; *$getmethod = sub { my ( $self ) = @_; $self->$getflag & $const }; *$setmethod = sub { my ( $self, $set ) = @_; $set ? $self->$setflag( $self->$getflag | $const ) : $self->$setflag( $self->$getflag & ~$const ); }; } sub getcsize { my $self = shift; my $cflag = $self->getcflag; return { CS5, 5, CS6, 6, CS7, 7, CS8, 8, }->{ $cflag & CSIZE }; } sub setcsize { my $self = shift; my ( $bits ) = @_; my $cflag = $self->getcflag; $cflag &= ~CSIZE; $cflag |= { 5, CS5, 6, CS6, 7, CS7, 8, CS8, }->{ $bits }; $self->setcflag( $cflag ); } sub getparity { my $self = shift; my $cflag = $self->getcflag; return 'n' unless $cflag & PARENB; return 'o' if $cflag & PARODD; return 'e'; } sub setparity { my $self = shift; my ( $parity ) = @_; my $cflag = $self->getcflag; $parity eq 'n' ? $cflag &= ~PARENB : $parity eq 'o' ? $cflag |= PARENB|PARODD : $parity eq 'e' ? ($cflag |= PARENB) &= ~PARODD : croak "Unrecognised parity '$parity'"; $self->setcflag( $cflag ); } sub getstop { my $self = shift; return 2 if $self->getcflag & CSTOPB; return 1; } sub setstop { my $self = shift; my ( $stop ) = @_; my $cflag = $self->getcflag; $stop == 1 ? $cflag &= ~CSTOPB : $stop == 2 ? $cflag |= CSTOPB : croak "Unrecognised stop '$stop'"; $self->setcflag( $cflag ); } sub cfmakeraw { my $self = shift; # Coped from bit manipulations in termios(3) $self->setiflag( $self->getiflag & ~( IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON ) ); $self->setoflag( $self->getoflag & ~( OPOST ) ); $self->setlflag( $self->getlflag & ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN ) ); $self->setcflag( $self->getcflag & ~( CSIZE | PARENB ) | CS8 ); } =head1 TODO =over 4 =item * Adding more getflag_*/setflag_* convenience wrappers =back =head1 SEE ALSO =over 4 =item * L - Import Tty control constants =back =head1 AUTHOR Paul Evans =cut 0x55AA; IO-Termios-0.10/t000755001750001750 014643477232 12361 5ustar00leoleo000000000000IO-Termios-0.10/t/00use.t000444001750001750 17114643477232 13616 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; require IO::Termios; pass( "Modules loaded" ); done_testing; IO-Termios-0.10/t/01flags.t000444001750001750 461114643477232 14142 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; use IO::Termios; use IO::Pty; use POSIX qw( EAGAIN ); # Can't use STDIN as we don't know if it will be a TTY at testing time my $pty = IO::Pty->new() or skip_all( "No PTY available" ); my $term = IO::Termios->new( $pty->slave ); # echo flag { $term->setflag_echo( 1 ); ok( $term->getflag_echo, '$term->getflag_echo is on' ); $pty->syswrite( "With ECHO\n" ); is( scalar <$term>, "With ECHO\n", '$term syswrite' ); is( scalar <$pty>, "With ECHO\r\n", 'Echoed back' ); $term->setflag_echo( 0 ); ok( !$term->getflag_echo, '$term->getflag_echo is off' ); } # non-blocking mode { $pty->blocking( 0 ); my $b; $pty->syswrite( "Without ECHO\n" ); is( scalar <$term>, "Without ECHO\n", '$term syswrite' ); ok( !defined $pty->sysread( $b, 8192 ), '$pty not readable' ); is( $!+0, EAGAIN, '$pty not readable (EAGAIN)' ); } # icanon flag { $term->setflag_icanon( 0 ); ok( !$term->getflag_icanon, '$term->getflag_icanon is off' ); $term->blocking( 0 ); my $rvec; my $rout; vec( $rvec, $term->fileno, 1 ) = 1; $pty->syswrite( "Without " ); select( $rout = $rvec, undef, undef, 0.1 ); ok( defined $term->sysread( $b, 8192 ), '$term is readable' ); is( $b, "Without ", '$pty reads partial line' ); $pty->syswrite( "ICANON\n" ); select( $rout = $rvec, undef, undef, 0.1 ); ok( defined $term->sysread( $b, 8192 ), '$term is readable' ); is( $b, "ICANON\n", '$pty reads remainder of line' ); $term->setflag_icanon( 1 ); ok( $term->getflag_icanon, '$term->getflag_icanon is on' ); $pty->syswrite( "With " ); ok( !defined $term->sysread( $b, 8192 ), '$term not readable' ); is( $!+0, EAGAIN, '$pty not readable (EAGAIN)' ); $pty->syswrite( "ICANON\n" ); select( $rout = $rvec, undef, undef, 0.1 ); ok( defined $term->sysread( $b, 8192 ), '$term is readable' ); is( $b, "With ICANON\n", '$pty reads remainder of line' ); } # setflags wrapper { $term->setflags(qw( +echo +cread -icrnl )); ok( $term->getflag_echo, 'echo set after setflags +echo' ); ok( $term->getflag_cread, 'cread set after setflags +cread' ); ok( !$term->getflag_icrnl, 'icrnl set after setflags -icrnl' ); $term->setflags(qw( -echo +cread +icrnl )); ok( !$term->getflag_echo, 'echo set after setflags -echo' ); ok( $term->getflag_icrnl, 'icrnl set after setflags +icrnl' ); } done_testing; IO-Termios-0.10/t/99pod.t000444001750001750 25514643477232 13631 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();