Test-POE-Client-TCP-1.26/000755 001751 001751 00000000000 13373611641 015455 5ustar00bingosbingos000000 000000 Test-POE-Client-TCP-1.26/README000644 001751 001751 00000027175 13373611641 016351 0ustar00bingosbingos000000 000000 NAME Test::POE::Client::TCP - A POE Component providing TCP client services for test cases VERSION version 1.26 SYNOPSIS use strict; use Socket; use Test::More tests => 15; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use Test::POE::Client::TCP; my @data = ( 'This is a test', 'This is another test', 'This is the last test', ); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], heap => { data => \@data, }, ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{testc} = Test::POE::Client::TCP->spawn(); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); my $port = ( sockaddr_in( $_[HEAP]->{listener}->getsockname() ) )[0]; $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$heap,$sender) = @_[KERNEL,HEAP,SENDER]; pass($_[STATE]); $kernel->post( $sender, 'send_to_server', $heap->{data}->[0] ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); my $data = shift @{ $heap->{data} }; ok( $input eq $data, "Data matched: '$input'" ); unless ( scalar @{ $heap->{data} } ) { $heap->{testc}->terminate(); return; } $poe_kernel->post( $_[SENDER], 'send_to_server', $heap->{data}->[0] ); return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } DESCRIPTION Test::POE::Client::TCP is a POE component that provides a TCP client framework for inclusion in client component test cases, instead of having to roll your own. Once registered with the component, a session will receive events related to connections made, disconnects, flushed output and input from the specified server. CONSTRUCTOR spawn Takes a number of optional arguments: 'alias', set an alias on the component; 'address', the remote address to connect to; 'port', the remote port to connect to; 'options', a hashref of POE::Session options; 'filter', specify a POE::Filter to use for client connections, default is POE::Filter::Line; 'inputfilter', specify a POE::Filter for client input; 'outputfilter', specify a POE::Filter for output to clients; 'localaddr', specify that connections be made from a particular local address; 'localport', specify that connections be made from a particular port; 'autoconnect', set to a true value to make the poco connect immediately; 'prefix', specify an event prefix other than the default of 'testc'; 'timeout', specify number of seconds to wait for socket timeouts; 'context', anything that can fit into a scalar, such as a ref, etc. 'usessl', enable SSL/TLS if POE::Component::SSLify is available; 'sslctx', set to a SSL Context to configure the SSL Connection; 'sslcert', set to a x509 Certificate(PEM encoded) to connect using a client cert; 'sslkey', set to a private Key(PEM encoded) to connect using a client cert; The semantics for filter, inputfilter and outputfilter are the same as for POE::Component::Server::TCP in that one may provide either a SCALAR, ARRAYREF or an OBJECT. If the component is spawned within another session it will automatically register the parent session to receive all events. address and port are optional within spawn, but if they aren't specified they must be provided to subsequent connects. If autoconnect is specified, address and port must also be defined. usessl is dependent on whether POE::Component::SSLify is available. METHODS connect Initiates a connection to the given server. Takes a number of parameters: 'address', the remote address to connect to; 'port', the remote port to connect to; 'localaddr', specify that connections be made from a particular local address, optional; 'localport', specify that connections be made from a particular port, optional; 'usessl', enable SSL/TLS if POE::Component::SSLify is available; address and port are optional if they have been already specified during spawn. session_id Returns the POE::Session ID of the component. shutdown Terminates the component. It will terminate any pending connects or connections. server_info Retrieves socket information about the current connection. In a list context it returns a list consisting of, in order, the server address, the server TCP port, our address and our TCP port. In a scalar context it returns a HASHREF with the following keys: 'peeraddr', the server address; 'peerport', the server TCP port; 'sockaddr', our address; 'sockport', our TCP port; send_to_server Send some output to the connected server. The first parameter is a string of text to send. This parameter may also be an arrayref of items to send to the client. If the filter you have used requires an arrayref as input, nest that arrayref within another arrayref. disconnect Places the server connection into pending disconnect state. Set this, then send an applicable message to the server using send_to_server() and the server connection will be terminated. terminate Immediately disconnects a server connection. wheel Returns the underlying POE::Wheel::ReadWrite object if we are currently connected to a server, undef otherwise. You can use this method to call methods on the wheel object to switch filters, etc. Exercise caution. alias Returns the currently configured alias. context Returns whatever was provided as context when the component was spawned. If nothing was provided then it returns nothing. INPUT EVENTS These are events that the component will accept: register Takes N arguments: a list of event names that your session wants to listen for, minus the 'testc_' prefix. Registering for 'all' will cause it to send all TESTC-related events to you; this is the easiest way to handle it. unregister Takes N arguments: a list of event names which you don't want to receive. If you've previously done a 'register' for a particular event which you no longer care about, this event will tell the poco to stop sending them to you. (If you haven't, it just ignores you. No big deal). connect Initiates a connection to the given server. Takes a number of parameters: 'address', the remote address to connect to; 'port', the remote port to connect to; 'localaddr', specify that connections be made from a particular local address, optional; 'localport', specify that connections be made from a particular port, optional; address and port are optional if they have been already specified during spawn. shutdown Terminates the component. It will terminate any pending connects or connections. send_to_server Send some output to the connected server. The first parameter is a string of text to send. This parameter may also be an arrayref of items to send to the client. If the filter you have used requires an arrayref as input, nest that arrayref within another arrayref. disconnect Places the server connection into pending disconnect state. Set this, then send an applicable message to the server using send_to_server() and the server connection will be terminated. terminate Immediately disconnects a server connection. OUTPUT EVENTS The component sends the following events to registered sessions. If you have changed the prefix option in spawn then substitute testc with the event prefix that you specified. testc_registered This event is sent to a registering session. ARG0 is the Test::POE::Client::TCP object. testc_socket_failed Generated if the component cannot make a socket connection. ARG0 contains the name of the operation that failed. ARG1 and ARG2 hold numeric and string values for $!, respectively. testc_connected Generated whenever a connection is established. ARG0 is the server's IP address, ARG1 is the server's TCP port. ARG3 is our IP address and ARG4 is our socket port. testc_disconnected Generated whenever we disconnect from the server. testc_input Generated whenever the server sends us some traffic. ARG0 is the data sent ( tokenised by whatever POE::Filter you specified ). testc_flushed Generated whenever anything we send to the server is actually flushed down the 'line'. KUDOS Contains code borrowed from POE::Component::Server::TCP by Rocco Caputo, Ann Barcomb and Jos Boumans. SEE ALSO POE POE::Component::Server::TCP AUTHOR Chris Williams COPYRIGHT AND LICENSE This software is copyright (c) 2018 by Chris Williams, Rocco Caputo, Ann Barcomb and Jos Boumans. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Test-POE-Client-TCP-1.26/LICENSE000644 001751 001751 00000044064 13373611641 016472 0ustar00bingosbingos000000 000000 This software is copyright (c) 2018 by Chris Williams, Rocco Caputo, Ann Barcomb and Jos Boumans. 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) 2018 by Chris Williams, Rocco Caputo, Ann Barcomb and Jos Boumans. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2018 by Chris Williams, Rocco Caputo, Ann Barcomb and Jos Boumans. 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 Test-POE-Client-TCP-1.26/Changes000644 001751 001751 00000006071 13373611641 016754 0ustar00bingosbingos000000 000000 ================================================== Changes from 2013-11-17 00:00:00 +0000 to present. ================================================== ----------------------------------------- version 1.26 at 2018-11-16 18:59:15 +0000 ----------------------------------------- Change: 568bcd2cf9d6433af20a9c656566534c48376e8d Author: Chris 'BinGOs' Williams Date : 2018-11-16 18:59:15 +0000 Require a more recent Socket ----------------------------------------- version 1.24 at 2018-09-17 09:02:56 +0000 ----------------------------------------- Change: e388b5a07feb6fcf272c916236f0698ffbbd1a91 Author: Chris 'BinGOs' Williams Date : 2018-09-17 10:02:56 +0000 Release engineering for 1.24 Change: a0d662f7225e68faf8dd8f4d76ec85e7f3af1490 Author: Damyan Ivanov Date : 2018-09-16 20:49:45 +0000 add support for IPv6 ----------------------------------------- version 1.22 at 2018-07-15 12:24:13 +0000 ----------------------------------------- Change: f3770138dd1fe7948ee2f7633a14dd661daa1267 Author: Chris 'BinGOs' Williams Date : 2018-07-15 13:24:13 +0000 Fixed problem when specifying ssl options ----------------------------------------- version 1.20 at 2018-07-13 18:06:30 +0000 ----------------------------------------- Change: dedc0de6a3a6513ac32355393443ae5bee756ec8 Author: Chris 'BinGOs' Williams Date : 2018-07-13 19:06:30 +0000 Added sslctx, sslcert and sslkey options These allow manipulation of the SSL/TLS connection and to specify client-side certificate, respectively. ----------------------------------------- version 1.18 at 2018-07-02 09:18:10 +0000 ----------------------------------------- Change: 58133ae09a1087d1d0cf6e5eac3767961b2e2577 Author: Chris 'BinGOs' Williams Date : 2018-07-02 10:18:10 +0000 Added usessl option to enable SSL/TLS ----------------------------------------- version 1.16 at 2018-06-21 19:18:05 +0000 ----------------------------------------- Change: 80815ed0757d71ba2b35b9366d3350a8b2415547 Author: Chris 'BinGOs' Williams Date : 2018-06-21 20:18:05 +0000 Bump version to 1.16 Change: 6e7dd74c4d8bc13faee5c266d1650c2903c605fa Author: Chris Williams Date : 2018-06-21 20:15:15 +0000 Merge pull request #1 from fschlich/patch-1 fix typos in POD Change: 253810a4de56c91c45a940397106cf76be899585 Author: Florian Schlichting Date : 2018-06-21 20:03:41 +0000 fix typos ----------------------------------------- version 1.14 at 2018-05-29 08:22:21 +0000 ----------------------------------------- Change: 7ba57fa9ee6d411fc7cd1336a985e57565d082c9 Author: Chris 'BinGOs' Williams Date : 2018-05-29 09:22:21 +0000 Added accessor for 'context' and update documentation ================================================ Plus 7 releases after 2013-11-17 00:00:00 +0000. ================================================ Test-POE-Client-TCP-1.26/dist.ini000644 001751 001751 00000000660 13373611641 017123 0ustar00bingosbingos000000 000000 name = Test-POE-Client-TCP version = 1.26 author = Chris Williams license = Perl_5 copyright_holder = Chris Williams, Rocco Caputo, Ann Barcomb and Jos Boumans [@BINGOS] [Prereqs / BuildRequires] ExtUtils::MakeMaker = 6.59 Test::More = 0.47 Text::ParseWords = 0 [Prereqs] POE = 1.28 POE::Filter = 0 POE::Filter::Line = 0 POE::Wheel::ReadWrite = 0 POE::Wheel::SocketFactory = 0 perl = 5.006 Socket = 2.013 Test-POE-Client-TCP-1.26/META.yml000644 001751 001751 00000001662 13373611641 016733 0ustar00bingosbingos000000 000000 --- abstract: 'A POE Component providing TCP client services for test cases' author: - 'Chris Williams ' build_requires: ExtUtils::MakeMaker: '6.59' File::Spec: '0' IO::Handle: '0' IPC::Open3: '0' Test::More: '0.47' Text::ParseWords: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.012, 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: Test-POE-Client-TCP requires: POE: '1.28' POE::Filter: '0' POE::Filter::Line: '0' POE::Wheel::ReadWrite: '0' POE::Wheel::SocketFactory: '0' Socket: '2.013' perl: '5.006' resources: homepage: https://github.com/bingos/test-poe-client-tcp repository: https://github.com/bingos/test-poe-client-tcp.git version: '1.26' x_generated_by_perl: v5.26.2 x_serialization_backend: 'YAML::Tiny version 1.73' Test-POE-Client-TCP-1.26/MANIFEST000644 001751 001751 00000000734 13373611641 016612 0ustar00bingosbingos000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.012. Changes Changes.old LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini examples/synopsis.pl lib/Test/POE/Client/TCP.pm t/00-compile.t t/00_use.t t/01_spawn.t t/01_spawn_ipv6.t t/02_register.t t/03_register.t t/04_multiple.t t/05_subclass.t t/06_filter.t t/07_synopsis.t t/08_buffer.t t/09_autoconnect.t t/09_server_info.t t/10_prefix.t t/author-pod-coverage.t t/author-pod-syntax.t Test-POE-Client-TCP-1.26/META.json000644 001751 001751 00000003541 13373611641 017101 0ustar00bingosbingos000000 000000 { "abstract" : "A POE Component providing TCP client services for test cases", "author" : [ "Chris Williams " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Test-POE-Client-TCP", "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "6.59", "Test::More" : "0.47", "Text::ParseWords" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "POE" : "1.28", "POE::Filter" : "0", "POE::Filter::Line" : "0", "POE::Wheel::ReadWrite" : "0", "POE::Wheel::SocketFactory" : "0", "Socket" : "2.013", "perl" : "5.006" } }, "test" : { "requires" : { "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::More" : "0.47" } } }, "release_status" : "stable", "resources" : { "homepage" : "https://github.com/bingos/test-poe-client-tcp", "repository" : { "type" : "git", "url" : "https://github.com/bingos/test-poe-client-tcp.git", "web" : "https://github.com/bingos/test-poe-client-tcp" } }, "version" : "1.26", "x_generated_by_perl" : "v5.26.2", "x_serialization_backend" : "Cpanel::JSON::XS version 4.06" } Test-POE-Client-TCP-1.26/t/000755 001751 001751 00000000000 13373611641 015720 5ustar00bingosbingos000000 000000 Test-POE-Client-TCP-1.26/Changes.old000644 001751 001751 00000001657 13373611641 017536 0ustar00bingosbingos000000 000000 Test::POE::Client::TCP ====================== 1.10 Wed Jun 29 10:37:32 BST 2011 - Explicitly shutdown socket in/out on destruction under Cygwin/MSWin32 1.08 Wed Apr 28 15:30:13 BST 2010 - The 'oh fuck' I deleted it from CPAN release 1.06 Mon Oct 26 23:22:03 GMT 2009 - Amended tests and bumped required POE version 1.04 Wed Jun 17 23:39:16 BST 2009 - Added accessor for alias. 1.02 Tue Apr 7 21:06:02 BST 2009 - Make auto_set_repository() only run at author-time 1.00 Mon Apr 6 22:52:02 BST 2009 - Bump to 'stable' version - add auto_set_repository to Makefile.PL 0.10 Tue Jan 20 12:27:34 GMT 2009 - Added 'wheel' method to get the POE::Wheel::ReadWrite object. 0.08 Thu Jan 15 10:33:50 GMT 2009 - Enabled event 'prefix' to be specified. 0.06 Tue Jul 1 10:28:19 BST 2008 - Managed to delete distro from CPAN, restoring. 0.04 Tue May 20 18:02:45 BST 2008 - added server_info() method. 0.02 - Initial CPAN release Test-POE-Client-TCP-1.26/Makefile.PL000644 001751 001751 00000003241 13373611641 017427 0ustar00bingosbingos000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.012. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "A POE Component providing TCP client services for test cases", "AUTHOR" => "Chris Williams ", "BUILD_REQUIRES" => { "ExtUtils::MakeMaker" => "6.59", "Test::More" => "0.47", "Text::ParseWords" => 0 }, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Test-POE-Client-TCP", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.006", "NAME" => "Test::POE::Client::TCP", "PREREQ_PM" => { "POE" => "1.28", "POE::Filter" => 0, "POE::Filter::Line" => 0, "POE::Wheel::ReadWrite" => 0, "POE::Wheel::SocketFactory" => 0, "Socket" => "2.013" }, "TEST_REQUIRES" => { "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Test::More" => "0.47" }, "VERSION" => "1.26", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "ExtUtils::MakeMaker" => "6.59", "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "POE" => "1.28", "POE::Filter" => 0, "POE::Filter::Line" => 0, "POE::Wheel::ReadWrite" => 0, "POE::Wheel::SocketFactory" => 0, "Socket" => "2.013", "Test::More" => "0.47", "Text::ParseWords" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Test-POE-Client-TCP-1.26/examples/000755 001751 001751 00000000000 13373611641 017273 5ustar00bingosbingos000000 000000 Test-POE-Client-TCP-1.26/lib/000755 001751 001751 00000000000 13373611641 016223 5ustar00bingosbingos000000 000000 Test-POE-Client-TCP-1.26/lib/Test/000755 001751 001751 00000000000 13373611641 017142 5ustar00bingosbingos000000 000000 Test-POE-Client-TCP-1.26/lib/Test/POE/000755 001751 001751 00000000000 13373611641 017565 5ustar00bingosbingos000000 000000 Test-POE-Client-TCP-1.26/lib/Test/POE/Client/000755 001751 001751 00000000000 13373611641 021003 5ustar00bingosbingos000000 000000 Test-POE-Client-TCP-1.26/lib/Test/POE/Client/TCP.pm000644 001751 001751 00000060325 13373611641 021775 0ustar00bingosbingos000000 000000 package Test::POE::Client::TCP; $Test::POE::Client::TCP::VERSION = '1.26'; #ABSTRACT: A POE Component providing TCP client services for test cases use strict; use warnings; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use POSIX qw[ETIMEDOUT]; use Socket qw(AF_INET AF_INET6 SOCK_STREAM inet_ntoa inet_ntop inet_pton unpack_sockaddr_in unpack_sockaddr_in6); use Carp qw(carp croak); our $GOT_SSL; BEGIN { eval { require POE::Component::SSLify; import POE::Component::SSLify qw( Client_SSLify SSLify_ContextCreate ); $GOT_SSL = 1; }; } sub spawn { my $package = shift; my %opts = @_; $opts{lc $_} = delete $opts{$_} for keys %opts; my $options = delete $opts{options}; my $autoconnect = delete $opts{autoconnect}; if ( $autoconnect and !( $opts{address} and $opts{port} ) ) { carp "You must provide both 'address' and 'port' parameters when specifying 'autoconnect'\n"; return; } my $usessl = delete $opts{usessl}; if ( $usessl && !$GOT_SSL ) { carp "'usessl' specified but POE::Component::SSLify is not available\n"; return; } delete $opts{timeout} unless $opts{timeout} and $opts{timeout} =~ m!^\d+$!; my $self = bless \%opts, $package; $self->{usessl} = $usessl; $self->{_prefix} = delete $self->{prefix}; $self->{_prefix} = 'testc_' unless defined $self->{_prefix}; $self->{_prefix} .= '_' unless $self->{_prefix} =~ /\_$/; $self->{session_id} = POE::Session->create( object_states => [ $self => { shutdown => '_shutdown', send_event => '__send_event', send_to_server => '_send_to_server', disconnect => '_disconnect', terminate => '_terminate', connect => '_connect', _timeout => '_socket_fail', }, $self => [ qw(_start register unregister _socket_up _socket_fail _conn_input _conn_error _conn_flushed _send_to_server __send_event _disconnect) ], ], heap => $self, ( ref($options) eq 'HASH' ? ( options => $options ) : () ), args => [ $autoconnect ], )->ID(); return $self; } sub session_id { shift->{session_id}; } sub context { my $self = shift; return $self->{context} if defined $self->{context}; return; } sub shutdown { $poe_kernel->call( shift->{session_id}, 'shutdown' ); } sub server_info { my $self = shift; return unless $self->{_server_info}; my @vals = @{ $self->{_server_info} }; return @vals if wantarray; return { map { $_ => shift @vals } qw(peeraddr peerport sockaddr sockport) }; } sub connect { $poe_kernel->call( shift->{session_id}, 'connect' ); } sub wheel { my $self = shift; return unless $self->{socket}; return $self->{socket}; } sub alias { shift->{alias}; } sub _start { my ($kernel,$self,$sender,$autoconnect) = @_[KERNEL,OBJECT,SENDER,ARG0]; $self->{session_id} = $_[SESSION]->ID(); if ( $self->{alias} ) { $kernel->alias_set( $self->{alias} ); } else { $kernel->refcount_increment( $self->{session_id} => __PACKAGE__ ); } if ( $kernel != $sender ) { my $sender_id = $sender->ID; $self->{events}->{$self->{_prefix} . 'all'}->{$sender_id} = $sender_id; $self->{sessions}->{$sender_id}->{'ref'} = $sender_id; $self->{sessions}->{$sender_id}->{'refcnt'}++; $kernel->refcount_increment($sender_id, __PACKAGE__); $kernel->post( $sender, $self->{_prefix} . 'registered', $self ); $kernel->detach_myself(); } $kernel->yield( 'connect' ) if $autoconnect and $self->{address} and $self->{port}; return; } sub _connect { my ($kernel,$self) = @_[KERNEL,OBJECT]; my $args; if ( ref( $_[ARG0] ) eq 'HASH' ) { $args = { %{ $_[ARG0] } }; } else { $args = { @_[ARG0..$#_] }; } $args->{lc $_} = delete $args->{$_} for keys %{ $args }; unless ( $self->{address} and $self->{port} ) { unless ( $args->{address} and $args->{port} ) { carp "You must provide both 'address' and 'port' parameters\n"; return; } $self->{address} = $args->{address}; $self->{port} = $args->{port}; } my $usessl = delete $args->{usessl}; if ( $usessl && !$GOT_SSL ) { carp "'usessl' specified but POE::Component::SSLify is not available\n"; return; } $self->{usessl} = $usessl if defined $usessl; $self->{localaddr} = $args->{localaddr} if $args->{localaddr}; $self->{localport} = $args->{localaddr} if $args->{localport}; if ( $self->{socket} ) { carp "Already connected. Disconnect and call 'connect' again\n"; return; } if ( $self->{factory} ) { carp "Connection already in progress\n"; return; } $self->{domain} = defined( inet_pton( AF_INET6, $self->{address} ) ) ? AF_INET6 : AF_INET; $self->{factory} = POE::Wheel::SocketFactory->new( RemoteAddress => $self->{address}, RemotePort => $self->{port}, ( defined $self->{address} ? ( BindAddress => $self->{localaddr} ) : () ), ( defined $self->{port} ? ( BindPort => $self->{localport} ) : () ), SuccessEvent => '_socket_up', FailureEvent => '_socket_fail', SocketDomain => $self->{domain}, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'yes', # Lets the port be reused ); $kernel->delay( '_timeout', $self->{timeout}, 'connect', ETIMEDOUT, POSIX::strerror( ETIMEDOUT ) ) if $self->{timeout}; return; } sub _socket_up { my ($kernel,$self,$socket,$peeraddr,$peerport) = @_[KERNEL,OBJECT,ARG0..ARG2]; my @sockaddr = ( $self->{domain} == AF_INET6 ) ? unpack_sockaddr_in6 ( CORE::getsockname $socket ) : unpack_sockaddr_in ( CORE::getsockname $socket ); my $sockaddr = inet_ntop( $self->{domain}, $sockaddr[1] ); my $sockport = $sockaddr[0]; $peeraddr = inet_ntop( $self->{domain}, $peeraddr ); $kernel->delay( '_timeout' ); delete $self->{factory}; if ( $self->{usessl} && $GOT_SSL ) { eval { my $ctx; if ($self->{sslctx}) { $ctx = $self->{sslctx}; } elsif ($self->{sslkey} && $self->{sslcert}) { $ctx = SSLify_ContextCreate($self->{sslkey}, $self->{sslcert}); } else { $ctx = undef; } $socket = Client_SSLify( $socket, undef, undef, $ctx ); if ( $@ ) { warn "Couldn't use an SSL socket: $@\n"; $self->{usessl} = 0; } }; } $self->{socket} = POE::Wheel::ReadWrite->new( Handle => $socket, _get_filters( $self->{filter}, $self->{inputfilter}, $self->{outputfilter} ), InputEvent => '_conn_input', ErrorEvent => '_conn_error', FlushedEvent => '_conn_flushed', ); $self->{_server_info} = [ $peeraddr, $peerport, $sockaddr, $sockport ]; $self->_send_event( $self->{_prefix} . 'connected', $peeraddr, $peerport, $sockaddr, $sockport ); return; } sub _get_filters { my ($client_filter, $client_infilter, $client_outfilter) = @_; if (defined $client_infilter or defined $client_outfilter) { return ( "InputFilter" => _load_filter($client_infilter), "OutputFilter" => _load_filter($client_outfilter) ); if (defined $client_filter) { carp( "Filter ignored with InputFilter or OutputFilter" ); } } elsif (defined $client_filter) { return ( "Filter" => _load_filter($client_filter) ); } else { return ( Filter => POE::Filter::Line->new(), ); } } # Get something: either arrayref, ref, or string # Return filter sub _load_filter { my $filter = shift; if (ref ($filter) eq 'ARRAY') { my @args = @$filter; $filter = shift @args; if ( _test_filter($filter) ){ return $filter->new(@args); } else { return POE::Filter::Line->new(@args); } } elsif (ref $filter) { return $filter->clone(); } else { if ( _test_filter($filter) ) { return $filter->new(); } else { return POE::Filter::Line->new(); } } } # Test if a Filter can be loaded, return sucess or failure sub _test_filter { my $filter = shift; my $eval = eval { (my $mod = $filter) =~ s!::!/!g; require "$mod.pm"; 1; }; if (!$eval and $@) { carp( "Failed to load [$filter]\n" . "Reason $@\nUsing defualt POE::Filter::Line " ); return 0; } return 1; } sub _socket_fail { my ($kernel,$self,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,OBJECT,ARG0..ARG3]; carp "Wheel $wheel_id generated $operation error $errnum: $errstr\n" if $self->{debug}; $kernel->delay( '_timeout' ); delete $self->{factory}; $self->_send_event( $self->{_prefix} . 'socket_failed', $operation, $errnum, $errstr ); return; } sub disconnect { my $self = shift; $poe_kernel->call( $self->{session_id}, 'disconnect', @_ ); } sub _disconnect { my ($kernel,$self) = @_[KERNEL,OBJECT]; return unless $self->{socket}; $self->{_quit} = 1; return 1; } sub terminate { my $self = shift; $poe_kernel->call( $self->{session_id}, 'terminate', @_ ); } sub _terminate { my ($kernel,$self) = @_[KERNEL,OBJECT]; return unless $self->{socket}; if ( $^O =~ /(cygwin|MSWin)/ ) { $self->{socket}->shutdown_input(); $self->{socket}->shutdown_output(); } delete $self->{socket}; delete $self->{_server_info}; $self->_send_event( $self->{_prefix} . 'disconnected' ); return 1; } sub _conn_input { my ($kernel,$self,$input,$id) = @_[KERNEL,OBJECT,ARG0,ARG1]; $self->_send_event( $self->{_prefix} . 'input', $input ); return; } sub _conn_error { my ($self,$errstr,$id) = @_[OBJECT,ARG2,ARG3]; return unless $self->{socket}; delete $self->{socket}; delete $self->{_server_info}; $self->_send_event( $self->{_prefix} . 'disconnected' ); return; } sub _conn_flushed { my ($self,$id) = @_[OBJECT,ARG0]; return unless $self->{socket}; if ( $self->{BUFFER} ) { my $item = shift @{ $self->{BUFFER} }; unless ( $item ) { delete $self->{BUFFER}; $self->_send_event( $self->{_prefix} . 'flushed' ); return; } $self->{socket}->put($item); return; } unless ( $self->{_quit} ) { $self->_send_event( $self->{_prefix} . 'flushed' ); return; } delete $self->{socket}; delete $self->{_server_info}; $self->_send_event( $self->{_prefix} . 'disconnected' ); return; } sub _shutdown { my ($kernel,$self) = @_[KERNEL,OBJECT]; delete $self->{factory}; delete $self->{socket}; delete $self->{_server_info}; $kernel->alarm_remove_all(); $kernel->alias_remove( $_ ) for $kernel->alias_list(); $kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ ) unless $self->{alias}; $self->_unregister_sessions(); return; } sub register { my ($kernel, $self, $session, $sender, @events) = @_[KERNEL, OBJECT, SESSION, SENDER, ARG0 .. $#_]; unless (@events) { warn "register: Not enough arguments"; return; } my $sender_id = $sender->ID(); foreach (@events) { $_ = $self->{_prefix} . $_ unless /^_/; $self->{events}->{$_}->{$sender_id} = $sender_id; $self->{sessions}->{$sender_id}->{'ref'} = $sender_id; unless ($self->{sessions}->{$sender_id}->{refcnt}++ or $session == $sender) { $kernel->refcount_increment($sender_id, __PACKAGE__); } } $kernel->post( $sender, $self->{_prefix} . 'registered', $self ); return; } sub unregister { my ($kernel, $self, $session, $sender, @events) = @_[KERNEL, OBJECT, SESSION, SENDER, ARG0 .. $#_]; unless (@events) { warn "unregister: Not enough arguments"; return; } $self->_unregister($session,$sender,@events); undef; } sub _unregister { my ($self,$session,$sender) = splice @_,0,3; my $sender_id = $sender->ID(); foreach (@_) { $_ = $self->{_prefix} . $_ unless /^_/; my $blah = delete $self->{events}->{$_}->{$sender_id}; unless ( $blah ) { warn "$sender_id hasn't registered for '$_' events\n"; next; } if (--$self->{sessions}->{$sender_id}->{refcnt} <= 0) { delete $self->{sessions}->{$sender_id}; unless ($session == $sender) { $poe_kernel->refcount_decrement($sender_id, __PACKAGE__); } } } undef; } sub _unregister_sessions { my $self = shift; my $testd_id = $self->session_id(); foreach my $session_id ( keys %{ $self->{sessions} } ) { if (--$self->{sessions}->{$session_id}->{refcnt} <= 0) { delete $self->{sessions}->{$session_id}; $poe_kernel->refcount_decrement($session_id, __PACKAGE__) unless ( $session_id eq $testd_id ); } } } sub __send_event { my( $self, $event, @args ) = @_[ OBJECT, ARG0, ARG1 .. $#_ ]; $self->_send_event( $event, @args ); return; } #sub send_event { # my $self = shift; # $poe_kernel->post( $self->{session_id}, '__send_event', @_ ); #} sub _send_event { my $self = shift; my ($event, @args) = @_; my $kernel = $POE::Kernel::poe_kernel; my %sessions; $sessions{$_} = $_ for (values %{$self->{events}->{$self->{_prefix} . 'all'}}, values %{$self->{events}->{$event}}); $kernel->post( $_ => $event => @args ) for values %sessions; undef; } sub send_to_server { my $self = shift; $poe_kernel->call( $self->{session_id}, '_send_to_server', @_ ); } sub _send_to_server { my ($kernel,$self,$output) = @_[KERNEL,OBJECT,ARG0]; return unless $self->{socket}; return unless $output; if ( ref $output eq 'ARRAY' ) { my $first = shift @{ $output }; $self->{BUFFER} = $output if scalar @{ $output }; $self->{socket}->put($first) if defined $first; return 1; } $self->{socket}->put($output); return 1; } q{Putting the test into POE}; __END__ =pod =encoding UTF-8 =head1 NAME Test::POE::Client::TCP - A POE Component providing TCP client services for test cases =head1 VERSION version 1.26 =head1 SYNOPSIS use strict; use Socket; use Test::More tests => 15; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use Test::POE::Client::TCP; my @data = ( 'This is a test', 'This is another test', 'This is the last test', ); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], heap => { data => \@data, }, ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{testc} = Test::POE::Client::TCP->spawn(); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); my $port = ( sockaddr_in( $_[HEAP]->{listener}->getsockname() ) )[0]; $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$heap,$sender) = @_[KERNEL,HEAP,SENDER]; pass($_[STATE]); $kernel->post( $sender, 'send_to_server', $heap->{data}->[0] ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); my $data = shift @{ $heap->{data} }; ok( $input eq $data, "Data matched: '$input'" ); unless ( scalar @{ $heap->{data} } ) { $heap->{testc}->terminate(); return; } $poe_kernel->post( $_[SENDER], 'send_to_server', $heap->{data}->[0] ); return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } =head1 DESCRIPTION Test::POE::Client::TCP is a L component that provides a TCP client framework for inclusion in client component test cases, instead of having to roll your own. Once registered with the component, a session will receive events related to connections made, disconnects, flushed output and input from the specified server. =head1 CONSTRUCTOR =over =item C Takes a number of optional arguments: 'alias', set an alias on the component; 'address', the remote address to connect to; 'port', the remote port to connect to; 'options', a hashref of POE::Session options; 'filter', specify a POE::Filter to use for client connections, default is POE::Filter::Line; 'inputfilter', specify a POE::Filter for client input; 'outputfilter', specify a POE::Filter for output to clients; 'localaddr', specify that connections be made from a particular local address; 'localport', specify that connections be made from a particular port; 'autoconnect', set to a true value to make the poco connect immediately; 'prefix', specify an event prefix other than the default of 'testc'; 'timeout', specify number of seconds to wait for socket timeouts; 'context', anything that can fit into a scalar, such as a ref, etc. 'usessl', enable SSL/TLS if POE::Component::SSLify is available; 'sslctx', set to a SSL Context to configure the SSL Connection; 'sslcert', set to a x509 Certificate(PEM encoded) to connect using a client cert; 'sslkey', set to a private Key(PEM encoded) to connect using a client cert; The semantics for C, C and C are the same as for L in that one may provide either a C, C or an C. If the component is Ced within another session it will automatically C the parent session to receive C events. C
and C are optional within C, but if they aren't specified they must be provided to subsequent Cs. If C is specified, C
and C must also be defined. C is dependent on whether L is available. =back =head1 METHODS =over =item C Initiates a connection to the given server. Takes a number of parameters: 'address', the remote address to connect to; 'port', the remote port to connect to; 'localaddr', specify that connections be made from a particular local address, optional; 'localport', specify that connections be made from a particular port, optional; 'usessl', enable SSL/TLS if POE::Component::SSLify is available; C
and C are optional if they have been already specified during C. =item C Returns the POE::Session ID of the component. =item C Terminates the component. It will terminate any pending connects or connections. =item C Retrieves socket information about the current connection. In a list context it returns a list consisting of, in order, the server address, the server TCP port, our address and our TCP port. In a scalar context it returns a HASHREF with the following keys: 'peeraddr', the server address; 'peerport', the server TCP port; 'sockaddr', our address; 'sockport', our TCP port; =item C Send some output to the connected server. The first parameter is a string of text to send. This parameter may also be an arrayref of items to send to the client. If the filter you have used requires an arrayref as input, nest that arrayref within another arrayref. =item C Places the server connection into pending disconnect state. Set this, then send an applicable message to the server using C and the server connection will be terminated. =item C Immediately disconnects a server connection. =item C Returns the underlying L object if we are currently connected to a server, C otherwise. You can use this method to call methods on the wheel object to switch filters, etc. Exercise caution. =item C Returns the currently configured alias. =item C Returns whatever was provided as C when the component was spawned. If nothing was provided then it returns nothing. =back =head1 INPUT EVENTS These are events that the component will accept: =over =item C Takes N arguments: a list of event names that your session wants to listen for, minus the 'testc_' prefix. Registering for 'all' will cause it to send all TESTC-related events to you; this is the easiest way to handle it. =item C Takes N arguments: a list of event names which you don't want to receive. If you've previously done a 'register' for a particular event which you no longer care about, this event will tell the poco to stop sending them to you. (If you haven't, it just ignores you. No big deal). =item C Initiates a connection to the given server. Takes a number of parameters: 'address', the remote address to connect to; 'port', the remote port to connect to; 'localaddr', specify that connections be made from a particular local address, optional; 'localport', specify that connections be made from a particular port, optional; C
and C are optional if they have been already specified during C. =item C Terminates the component. It will terminate any pending connects or connections. =item C Send some output to the connected server. The first parameter is a string of text to send. This parameter may also be an arrayref of items to send to the client. If the filter you have used requires an arrayref as input, nest that arrayref within another arrayref. =item C Places the server connection into pending disconnect state. Set this, then send an applicable message to the server using C and the server connection will be terminated. =item C Immediately disconnects a server connection. =back =head1 OUTPUT EVENTS The component sends the following events to registered sessions. If you have changed the C option in C then substitute C with the event prefix that you specified. =over =item C This event is sent to a registering session. ARG0 is the Test::POE::Client::TCP object. =item C Generated if the component cannot make a socket connection. ARG0 contains the name of the operation that failed. ARG1 and ARG2 hold numeric and string values for $!, respectively. =item C Generated whenever a connection is established. ARG0 is the server's IP address, ARG1 is the server's TCP port. ARG3 is our IP address and ARG4 is our socket port. =item C Generated whenever we disconnect from the server. =item C Generated whenever the server sends us some traffic. ARG0 is the data sent ( tokenised by whatever POE::Filter you specified ). =item C Generated whenever anything we send to the server is actually flushed down the 'line'. =back =head1 KUDOS Contains code borrowed from L by Rocco Caputo, Ann Barcomb and Jos Boumans. =head1 SEE ALSO L L =head1 AUTHOR Chris Williams =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2018 by Chris Williams, Rocco Caputo, Ann Barcomb and Jos Boumans. 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 Test-POE-Client-TCP-1.26/examples/synopsis.pl000644 001751 001751 00000005547 13373611641 021532 0ustar00bingosbingos000000 000000 use strict; use Socket; use Test::More tests => 15; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use Test::POE::Client::TCP; my @data = ( 'This is a test', 'This is another test', 'This is the last test', ); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], heap => { data => \@data, }, ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{testc} = Test::POE::Client::TCP->spawn(); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); my $port = ( sockaddr_in( $_[HEAP]->{listener}->getsockname() ) )[0]; $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$heap,$sender) = @_[KERNEL,HEAP,SENDER]; pass($_[STATE]); $kernel->post( $sender, 'send_to_server', $heap->{data}->[0] ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); my $data = shift @{ $heap->{data} }; ok( $input eq $data, "Data matched: '$input'" ); unless ( scalar @{ $heap->{data} } ) { $heap->{testc}->terminate(); return; } $poe_kernel->post( $_[SENDER], 'send_to_server', $heap->{data}->[0] ); return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } Test-POE-Client-TCP-1.26/t/00_use.t000644 001751 001751 00000000075 13373611641 017202 0ustar00bingosbingos000000 000000 use Test::More tests => 1; use_ok('Test::POE::Client::TCP'); Test-POE-Client-TCP-1.26/t/01_spawn.t000644 001751 001751 00000005405 13373611641 017541 0ustar00bingosbingos000000 000000 use strict; use Socket; use Test::More tests => 12; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use_ok('Test::POE::Client::TCP'); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{testc} = Test::POE::Client::TCP->spawn(); isa_ok( $heap->{testc}, 'Test::POE::Client::TCP' ); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); isa_ok( $object, 'Test::POE::Client::TCP' ); my $port = ( sockaddr_in( $_[HEAP]->{listener}->getsockname() ) )[0]; $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$sender) = @_[KERNEL,SENDER]; pass($_[STATE]); isa_ok( $_[HEAP]->{testc}->wheel, 'POE::Wheel::ReadWrite' ); $kernel->post( $sender, 'send_to_server', 'Hello, is it me you are looking for?' ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); ok( $input eq 'Hello, is it me you are looking for?', $input ); $heap->{testc}->terminate(); return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } Test-POE-Client-TCP-1.26/t/06_filter.t000644 001751 001751 00000010137 13373611641 017701 0ustar00bingosbingos000000 000000 use strict; { package TPCTParseWords; use base qw(POE::Filter); use Text::ParseWords; my $VERSION = '1.02'; sub new { my $class = shift; my %opts = @_; $opts{lc $_} = delete $opts{$_} for keys %opts; $opts{keep} = 0 unless $opts{keep}; $opts{delim} = '\s+' unless $opts{delim}; $opts{BUFFER} = []; bless \%opts, $class; } sub get { my ($self, $raw) = @_; my $events = []; push @$events, [ parse_line( $self->{delim}, $self->{keep}, $_ ) ] for @$raw; return $events; } sub get_one_start { my ($self, $raw) = @_; push @{ $self->{BUFFER} }, $_ for @$raw; } sub get_one { my $self = shift; my $events = []; my $event = shift @{ $self->{BUFFER} }; push @$events, [ parse_line( $self->{delim}, $self->{keep}, $event ) ] if defined $event; return $events; } sub put { warn "PUT is unimplemented\n"; return; } sub clone { my $self = shift; my $nself = { }; $nself->{$_} = $self->{$_} for keys %{ $self }; $nself->{BUFFER} = [ ]; return bless $nself, ref $self; } } use Socket; use Test::More tests => 10; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use_ok('Test::POE::Client::TCP'); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{testc} = Test::POE::Client::TCP->spawn( inputfilter => TPCTParseWords->new(), outputfilter => POE::Filter::Line->new(), ); isa_ok( $heap->{testc}, 'Test::POE::Client::TCP' ); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; $wheel->put('"This is just a test" "line" "so there"'); return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); # $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; delete $heap->{wheels}->{ $wheel_id } if $input eq 'quit'; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); isa_ok( $object, 'Test::POE::Client::TCP' ); my $port = ( sockaddr_in( $_[HEAP]->{listener}->getsockname() ) )[0]; $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$sender) = @_[KERNEL,SENDER]; pass($_[STATE]); # $kernel->post( $sender, 'send_to_server', 'Hello, is it me you are looking for?' ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); # ok( $input eq 'Hello, is it me you are looking for?', $input ); ok( ( $input->[0] eq 'This is just a test' and $input->[1] eq 'line' and $input->[2] eq 'so there' ) , 'Test Get' ); $heap->{testc}->send_to_server('quit'); return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } Test-POE-Client-TCP-1.26/t/08_buffer.t000644 001751 001751 00000005502 13373611641 017667 0ustar00bingosbingos000000 000000 use strict; use Socket; use Test::More tests => 14; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use_ok('Test::POE::Client::TCP'); my @data = ( 'This is a test', 'This is another test', 'This is the last test', ); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], heap => { data => \@data, }, ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{count} = @{ $heap->{data} }; $heap->{testc} = Test::POE::Client::TCP->spawn(); isa_ok( $heap->{testc}, 'Test::POE::Client::TCP' ); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); isa_ok( $object, 'Test::POE::Client::TCP' ); my $port = ( sockaddr_in( $_[HEAP]->{listener}->getsockname() ) )[0]; $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$sender) = @_[KERNEL,SENDER]; pass($_[STATE]); $kernel->post( $sender, 'send_to_server', [ @{ $_[HEAP]->{data} } ] ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); $heap->{count}--; $heap->{testc}->terminate() if $heap->{count} <= 0; return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } Test-POE-Client-TCP-1.26/t/10_prefix.t000644 001751 001751 00000005626 13373611641 017713 0ustar00bingosbingos000000 000000 use strict; use Socket; use Test::More tests => 16; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use Test::POE::Client::TCP; my @data = ( 'This is a test', 'This is another test', 'This is the last test', ); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err bingosc_registered bingosc_connected bingosc_disconnected bingosc_input bingosc_flushed )], ], heap => { data => \@data, }, ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{bingosc} = Test::POE::Client::TCP->spawn( prefix => 'bingosc' ); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub bingosc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); my $port = ( sockaddr_in( $_[HEAP]->{listener}->getsockname() ) )[0]; $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub bingosc_connected { my ($kernel,$heap,$sender) = @_[KERNEL,HEAP,SENDER]; pass($_[STATE]); $kernel->post( $sender, 'send_to_server', $heap->{data}->[0] ); return; } sub bingosc_flushed { pass($_[STATE]); return; } sub bingosc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); my $data = shift @{ $heap->{data} }; ok( $input eq $data, "Data matched: '$input'" ); unless ( scalar @{ $heap->{data} } ) { $heap->{bingosc}->terminate(); return; } $poe_kernel->post( $_[SENDER], 'send_to_server', $heap->{data}->[0] ); return; } sub bingosc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{bingosc}->shutdown(); return; } Test-POE-Client-TCP-1.26/t/00-compile.t000644 001751 001751 00000002644 13373611641 017760 0ustar00bingosbingos000000 000000 use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.058 use Test::More; plan tests => 1 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'Test/POE/Client/TCP.pm' ); # no fake home requested my @switches = ( -d 'blib' ? '-Mblib' : '-Ilib', ); use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} } $^X, @switches, '-e', "require q[$lib]")) if $ENV{PERL_COMPILE_TEST_DEBUG}; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { +require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING}; Test-POE-Client-TCP-1.26/t/02_register.t000644 001751 001751 00000001254 13373611641 020234 0ustar00bingosbingos000000 000000 use strict; use Test::More tests => 6; use POE; use_ok('Test::POE::Client::TCP'); my $testc = Test::POE::Client::TCP->spawn(); isa_ok( $testc, 'Test::POE::Client::TCP' ); POE::Session->create( package_states => [ 'main' => [qw( _start _stop testc_registered )], ], ); $poe_kernel->run(); exit 0; sub _start { pass($_[STATE]); $poe_kernel->post( $testc->session_id(), 'register', 'all' ); return; } sub _stop { $testc->shutdown; pass($_[STATE]); return; } sub testc_registered { my ($sender,$object) = @_[SENDER,ARG0]; pass($_[STATE]); isa_ok( $object, 'Test::POE::Client::TCP' ); $poe_kernel->post( $sender, 'unregister', 'all' ); return; } Test-POE-Client-TCP-1.26/t/03_register.t000644 001751 001751 00000001217 13373611641 020234 0ustar00bingosbingos000000 000000 use strict; use Test::More tests => 6; use POE; use_ok( 'Test::POE::Client::TCP' ); POE::Session->create( package_states => [ 'main' => [qw( _start _stop testc_registered )], ], ); $poe_kernel->run(); exit 0; sub _start { $_[HEAP]->{testc} = Test::POE::Client::TCP->spawn(); isa_ok( $_[HEAP]->{testc}, 'Test::POE::Client::TCP' ); pass($_[STATE]); return; } sub _stop { $_[HEAP]->{testc}->shutdown; pass($_[STATE]); return; } sub testc_registered { my ($sender,$object) = @_[SENDER,ARG0]; pass($_[STATE]); isa_ok( $object, 'Test::POE::Client::TCP' ); $poe_kernel->post( $sender, 'unregister', 'all' ); return; } Test-POE-Client-TCP-1.26/t/04_multiple.t000644 001751 001751 00000005622 13373611641 020250 0ustar00bingosbingos000000 000000 use strict; use Socket; use Test::More tests => 21; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use_ok('Test::POE::Client::TCP'); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], heap => { clients => 2, }, ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); for ( 1 .. $heap->{clients} ) { my $testc = Test::POE::Client::TCP->spawn(); isa_ok( $testc, 'Test::POE::Client::TCP' ); push @{ $heap->{testc} }, $testc; } return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); isa_ok( $object, 'Test::POE::Client::TCP' ); my $port = ( sockaddr_in( $_[HEAP]->{listener}->getsockname() ) )[0]; $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$sender) = @_[KERNEL,SENDER]; pass($_[STATE]); $kernel->post( $sender, 'send_to_server', 'Hello, is it me you are looking for?' ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); ok( $input eq 'Hello, is it me you are looking for?', $input ); $poe_kernel->post( $_[SENDER], 'terminate' ); return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); $heap->{count}++; if ( $heap->{count} >= $heap->{clients} ) { $_->shutdown() for @{ $heap->{testc} }; delete $heap->{wheels}; delete $heap->{listener}; } return; } Test-POE-Client-TCP-1.26/t/05_subclass.t000644 001751 001751 00000005510 13373611641 020231 0ustar00bingosbingos000000 000000 use strict; { package TPCTSubclass; use base qw(Test::POE::Client::TCP); my $VERSION = '0.01'; } use Socket; use Test::More tests => 12; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{testc} = TPCTSubclass->spawn(); isa_ok( $heap->{testc}, 'Test::POE::Client::TCP' ); isa_ok( $heap->{testc}, 'TPCTSubclass' ); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); isa_ok( $object, 'Test::POE::Client::TCP' ); isa_ok( $object, 'TPCTSubclass' ); my $port = ( sockaddr_in( $_[HEAP]->{listener}->getsockname() ) )[0]; $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$sender) = @_[KERNEL,SENDER]; pass($_[STATE]); $kernel->post( $sender, 'send_to_server', 'Hello, is it me you are looking for?' ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); ok( $input eq 'Hello, is it me you are looking for?', $input ); $heap->{testc}->terminate(); return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } Test-POE-Client-TCP-1.26/t/07_synopsis.t000644 001751 001751 00000005547 13373611641 020315 0ustar00bingosbingos000000 000000 use strict; use Socket; use Test::More tests => 16; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use Test::POE::Client::TCP; my @data = ( 'This is a test', 'This is another test', 'This is the last test', ); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], heap => { data => \@data, }, ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{testc} = Test::POE::Client::TCP->spawn(); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); my $port = ( sockaddr_in( $_[HEAP]->{listener}->getsockname() ) )[0]; $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$heap,$sender) = @_[KERNEL,HEAP,SENDER]; pass($_[STATE]); $kernel->post( $sender, 'send_to_server', $heap->{data}->[0] ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); my $data = shift @{ $heap->{data} }; ok( $input eq $data, "Data matched: '$input'" ); unless ( scalar @{ $heap->{data} } ) { $heap->{testc}->terminate(); return; } $poe_kernel->post( $_[SENDER], 'send_to_server', $heap->{data}->[0] ); return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } Test-POE-Client-TCP-1.26/t/01_spawn_ipv6.t000644 001751 001751 00000005530 13373611641 020504 0ustar00bingosbingos000000 000000 use strict; use Socket; use Test::More; BEGIN { eval('Socket::AF_INET6') or plan skip_all => 'AF_INET6 not available'; }; plan tests => 12; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use_ok('Test::POE::Client::TCP'); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '::1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET6, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{testc} = Test::POE::Client::TCP->spawn(); isa_ok( $heap->{testc}, 'Test::POE::Client::TCP' ); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); isa_ok( $object, 'Test::POE::Client::TCP' ); my $port = ( sockaddr_in6( $_[HEAP]->{listener}->getsockname() ) )[0]; $kernel->post( $sender, 'connect', { address => '::1', port => $port } ); return; } sub testc_connected { my ($kernel,$sender) = @_[KERNEL,SENDER]; pass($_[STATE]); isa_ok( $_[HEAP]->{testc}->wheel, 'POE::Wheel::ReadWrite' ); $kernel->post( $sender, 'send_to_server', 'Hello, is it me you are looking for?' ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); ok( $input eq 'Hello, is it me you are looking for?', $input ); $heap->{testc}->terminate(); return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } Test-POE-Client-TCP-1.26/t/09_autoconnect.t000644 001751 001751 00000005375 13373611641 020751 0ustar00bingosbingos000000 000000 use strict; use Socket; use Test::More tests => 11; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use_ok('Test::POE::Client::TCP'); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); my $port = ( sockaddr_in( $heap->{listener}->getsockname() ) )[0]; $heap->{testc} = Test::POE::Client::TCP->spawn( address => '127.0.0.1', port => $port, autoconnect => 1 ); isa_ok( $heap->{testc}, 'Test::POE::Client::TCP' ); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); isa_ok( $object, 'Test::POE::Client::TCP' ); # $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$sender) = @_[KERNEL,SENDER]; pass($_[STATE]); $kernel->post( $sender, 'send_to_server', 'Hello, is it me you are looking for?' ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); ok( $input eq 'Hello, is it me you are looking for?', $input ); $heap->{testc}->terminate(); return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } Test-POE-Client-TCP-1.26/t/09_server_info.t000644 001751 001751 00000006304 13373611641 020741 0ustar00bingosbingos000000 000000 use strict; use Socket; use Test::More tests => 22; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use_ok('Test::POE::Client::TCP'); my @data = ( 'This is a test', 'This is another test', 'This is the last test', ); POE::Session->create( package_states => [ 'main' => [qw( _start _accept _failed _sock_in _sock_err testc_registered testc_connected testc_disconnected testc_input testc_flushed )], ], heap => { data => \@data, }, ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{count} = @{ $heap->{data} }; $heap->{testc} = Test::POE::Client::TCP->spawn(); isa_ok( $heap->{testc}, 'Test::POE::Client::TCP' ); return; } sub _accept { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,HEAP,ARG0..ARG3]; die "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_[HEAP,ARG0,ARG1]; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_[HEAP,ARG3]; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_[KERNEL,SENDER,ARG0]; pass($_[STATE]); isa_ok( $object, 'Test::POE::Client::TCP' ); my $port = ( sockaddr_in( $_[HEAP]->{listener}->getsockname() ) )[0]; diag("Connecting to port: $port\n"); $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$heap,$sender) = @_[KERNEL,HEAP,SENDER]; pass($_[STATE]); my @orig = @_[ARG0..$#_]; my @test = $heap->{testc}->server_info(); my $test = $heap->{testc}->server_info(); ok( $test[$_] eq $orig[$_], "Server Info: " . $orig[$_] ) for 0 .. 3; my @test2 = map { $test->{$_} } qw(peeraddr peerport sockaddr sockport); ok( $test2[$_] eq $orig[$_], "Server Info: " . $orig[$_] ) for 0 .. 3; $kernel->post( $sender, 'send_to_server', [ @{ $_[HEAP]->{data} } ] ); return; } sub testc_flushed { pass($_[STATE]); return; } sub testc_input { my ($heap,$input) = @_[HEAP,ARG0]; pass('Got something back from the server'); $heap->{count}--; $heap->{testc}->terminate() if $heap->{count} <= 0; return; } sub testc_disconnected { my ($heap,$state) = @_[HEAP,STATE]; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } Test-POE-Client-TCP-1.26/t/author-pod-syntax.t000644 001751 001751 00000000454 13373611641 021516 0ustar00bingosbingos000000 000000 #!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Test-POE-Client-TCP-1.26/t/author-pod-coverage.t000644 001751 001751 00000000536 13373611641 021764 0ustar00bingosbingos000000 000000 #!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' });