AnyEvent-WebSocket-Client-0.55/000755 000000 000000 00000000000 14424756453 016270 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/Changes000644 000000 000000 00000022062 14424756453 017565 0ustar00rootroot000000 000000 Revision history for AnyEvent-WebSocket-Client 0.55 2023-05-04 10:28:24 -0600 [WARNING: change in behavior] - Fix the default code for close to be 1000 (gh#61, gh#62) 0.54 2021-03-19 06:13:48 -0600 - Delay loading AnyEvent::Connector until needed. - Moved git repository to new github org. 0.53 2019-04-01 08:42:05 -0400 - Add missing timeout from test that could otherwise hang with a broken combination of Debian Buster / Net::SSLeay / AnyEvent. (gh#46. gh#47) 0.52 2019-02-08 14:22:11 -0500 - Production version functionally identical to the 0.51_01 release. 0.51_01 2019-02-05 23:22:05 -0500 - You may now overide the host and port when using the AnyEvent::WebSocket::Client's connect method. 0.50 2019-01-14 10:49:47 -0500 - Fixed a testing bug that was reportd on Debian Buster. 0.49 2018-07-09 21:06:24 -0400 - Fixed a bug where adding next_message callback within a next_message callback was called immediately with the same message (gh#39 xavery++) 0.48 2018-05-21 21:08:49 -0400 - Production version functionally identical to the 0.47_01 release. 0.47_01 2018-05-20 09:35:23 -0400 - Add max_fragments attribute ot AnyEvent::WebSocket::Client - Add max_fragments attribute ot AnyEvent::WebSocket::Connection 0.46 2018-04-07 16:39:29 -0400 - Production version functionally identical to the 0.45_01 release. 0.45_01 2018-04-04 17:01:03 -0400 - add env_proxy property to AnyEvent::WebSocket::Client (gh#36 gh#37 TOSHIOITO++) 0.44 2017-12-12 15:37:51 -0500 - Compatibility with 0.22. 0.43 2017-10-19 17:06:51 -0400 - Production version functionally identical to the 0.42_01 release. 0.42_01 2017-10-18 11:45:16 -0400 - You can now unregister event callbacks. - The 'on' method for AnyEvent::WebSocket::Connection now returns a code ref that can be used to unregister the callback. - The 'each_message' event also gets a code ref that can be used to unregister the callback. [WARNING: change in behavior] - The 'on' method for AnyEvent::WebSocket::Connection used to return the connection object, the intent was to allow chaining of 'on' calls, but this was never documented, and I don't believe it was ever used. - The 'each_message' event has a different number of arguments, which could break code that is using 'pop' to get the message instead of using the second argument position. If you were following the examples in the documentation you wouldn't have done this. 0.41 2017-08-11 14:05:40 -0400 - Production version functionally identical to the 0.40_03 release. 0.40_03 2017-08-10 14:53:41 -0400 - Possible workaround for Perl 5.8.x bug (gh#19) 0.40_02 2017-08-10 12:39:28 -0400 - Fix testing testing failure introduced in 0.40_01 0.40_01 2017-08-06 22:59:50 -0400 - Add close_code, close_reason and close_error properties to AnyEvent::Connection - Significant refactor of the test suite that reduces dependencies on Mojolicious - Migrate to MakeMaker for installer 0.39 2017-07-07 18:32:02 -0400 - Require AnyEvent 7.13 or better to address SSL/TLS error (gh#22) - Updated example to use Mojo::Redis2 and modern Mojolicious (Kivanc Yazan gh#29) 0.38 2017-01-31 13:11:24 -0500 - Fix skip in t/mojo_close_codes.t which requires EV to be installed (José Joaquín Atria gh#28) 0.37 2016-11-04 22:24:11 -0400 - Added max_payload_size to AnyEvent::WebSocket::Client and AnyEvent::WebSocket::Connection for limiting the size of received frames - Sending payloads larger than 65536 no longer causes an exception - Added parse_error to AnyEvent::WebSocket::Connection 0.36 2016-10-27 11:57:12 -0400 - Production version functionally identical to the 0.35_02 release. 0.35_02 2016-10-25 13:04:54 -0400 - Added http_headers attribute which allows you to provide additional arbitrary headers 0.35_01 2016-10-24 18:28:00 -0400 - You may now specify the protocol version using the protocol_version attribute for AnyEvent::WebSocket::Client. All protocol versions supported by Protocol::WebSocket should work. - Added subprotocol attribute for AnyEvent::WebSocket::Client 0.35 2016-08-04 13:47:36 -0400 - Production version functionally identical to the 0.34_01 release. 0.34_01 2016-07-31 08:42:40 -0400 - Fixed bug where read data could be discarded when in TLS mode. (gh#25 thanks Toshio Ito) 0.34 2016-07-26 14:04:52 -0400 - Documentation improvements - Production version functionally identical to the 0.33_01 release. 0.33_01 2016-07-25 22:48:06 -0400 - Added optional code and reason arguments to $connection->close (gh#23 thanks José Joaquín Atria) 0.33 2016-04-25 12:12:12 -0400 - t/ae_ssl.t may now be skipped by setting ANYEVENT_WEBSOCKET_TEST_SKIP_SSL 0.32 2015-12-17 14:02:36 -0500 - URI 1.53 or better has been required for a while (if not since 0.01) This is now reflected in the module metadata. Thanks to Fabien Wernli (faxm0dem) for the report. 0.31 2015-10-11 06:21:29 -0400 - Removed deprecated methods for AnyEvent::WebSocket::Connection class: on_each_message on_next_message on_finish 0.30 2015-03-03 23:33:03 -0500 - Require Moo 2.0, as older versions inadvertently turn on fatal warnings 0.29 2015-01-17 10:03:16 -0500 - document when deprecated methods will be removed. 0.28 2014-12-08 12:43:53 -0500 - make confusing documentation less confusing. 0.27 2014-08-20 03:54:14 -0400 - disable t/mojo_ssl.t since it is unreliable and we test the same features with t/ae_ssl.t now. 0.26 2014-08-19 10:59:26 -0400 - if Crypt::Random::Source is already installed, require at least version 0.08 to avoid Class::MOP deprecation warnings 0.25 2014-08-11 14:35:11 -0400 - fix broken link in documentation 0.24 2014-08-11 07:29:49 -0400 - documentation (add a FAQ about AnyEvent that I keep getting) - testing ssl (without Mojo) 0.23 2014-08-04 12:41:07 -0400 - documentation improvements - use AE:: instead of AnyEvent-> for performance 0.22 2014-06-19 15:33:56 -0400 - Mojo 5.x compat (testing only) 0.21 2014-04-08 12:52:51 -0400 - Perl 5.8 support Only useful if you force install Protocol::WebSocket, since it has a failing test on 5.8 0.20 2013-11-05 10:19:20 -0500 - prevent multiple finish callbacks in unusual cases (Toshio Ito gh#15) 0.19 2013-11-04 07:26:19 -0500 [AE::WS::Connection enhacements (thanks Toshio Ito)] - Automatically respond to a close frame with a close frame (RFC6455 5.5.1) - Make sure "finish" callbacks are called only once. - Automatically shutdown the socket on "finish" event. This makes sure EOF signal is sent to the peer. - Refuse to send/receive frames after it sends/receives a close frame. (RFC6455 1.4, 5.5.1) - Abort the connection when it receives a too huge message. The size limit is imposed by Protocol::WebSocket::Frame (RFC6455 10.4) - Automatically respond to a ping frame with a pong frame of the same payload (RFC6455 5.5.2, 5.5.3) - Add "masked" attribute. If set, outgoing frames are masked. - Client's Connection now sets masked => true (RFC6455 5.3, 6.1). - documentation 0.18 2013-10-21 14:55:47 -0400 - documentation 0.17 2013-10-16 10:58:41 -0400 - public API for creating Connection instance (thanks Toshio Ito gh#10) - bug fix messages sent by server immediately after connect may have been lost (thanks Toshio Ito gh#12) 0.16 2013-10-15 13:05:36 -0400 - skip ssl test if you have a bad combination of Mojolicious and Net::SSLeay (gh#11) 0.15 2013-10-10 13:20:00 -0400 - actually require moo 1.001000, and use scalar default value that feature should have been there to begin with. 0.14 2013-10-10 13:09:42 -0400 - fix older Moo compat 0.12 2013-10-10 07:07:42 -0400 - deprecate on_next_message, on_each_message and on_finish (use $connection->on($event => sub { }) instead see documentation for different calling convention. - added AnyEvent::WebSocket::Message class - You can now use Connection#send method to send Message objects in addition to strings. 0.11 2013-10-03 17:10:38 -0400 - fix mojo_ test plans for when mojo is not installed 0.10 2013-10-03 16:55:28 -0400 - added a close method for the AnyEvent::WebSocket::Connection class - better test coverage 0.09 2013-10-03 09:42:47 -0400 - Fix for messages that Perl considers "false" (thanks Toshio Ito gh#4) 0.08 2013-09-22 03:47:32 -0400 - require mojolicious 3.x or better for optional mojo tests (not required for test or install) 0.07 2013-09-20 10:13:32 -0400 - documentation 0.06 2013-09-07 04:29:10 -0400 - require PerlX::Maybe 0.003 for "provided" method 0.05 2013-09-05 15:34:56 -0400 - propagate connect error properly 0.04 2013-08-30 09:52:42 -0400 - kill some memory cycles 0.03 2013-08-30 08:53:30 -0400 - added SSL/TLS support 0.02 2013-08-29 15:38:34 -0400 - added AnyEvent only test for when Mojo isn't installed 0.01 2013-08-29 14:49:38 -0400 - initial version AnyEvent-WebSocket-Client-0.55/INSTALL000644 000000 000000 00000004712 14424756453 017325 0ustar00rootroot000000 000000 This is the Perl distribution AnyEvent-WebSocket-Client. Installing AnyEvent-WebSocket-Client is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm AnyEvent::WebSocket::Client If it does not have permission to install modules to the current perl, cpanm will automatically set up and install to a local::lib in your home directory. See the local::lib documentation (https://metacpan.org/pod/local::lib) for details on enabling it in your environment. ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan AnyEvent::WebSocket::Client ## Manual installation As a last resort, you can manually install it. If you have not already downloaded the release tarball, you can find the download link on the module's MetaCPAN page: https://metacpan.org/pod/AnyEvent::WebSocket::Client Untar the tarball, install configure prerequisites (see below), then build it: % perl Makefile.PL % make && make test Then install it: % make install On Windows platforms, you should use `dmake` or `nmake`, instead of `make`. If your perl is system-managed, you can create a local::lib in your home directory to install modules to. For details, see the local::lib documentation: https://metacpan.org/pod/local::lib The prerequisites of this distribution will also have to be installed manually. The prerequisites are listed in one of the files: `MYMETA.yml` or `MYMETA.json` generated by running the manual build process described above. ## Configure Prerequisites This distribution requires other modules to be installed before this distribution's installer can be run. They can be found under the "configure_requires" key of META.yml or the "{prereqs}{configure}{requires}" key of META.json. ## Other Prerequisites This distribution may require additional modules to be installed after running Makefile.PL. Look for prerequisites in the following phases: * to run make, PHASE = build * to use the module code itself, PHASE = runtime * to run tests, PHASE = test They can all be found in the "PHASE_requires" key of MYMETA.yml or the "{prereqs}{PHASE}{requires}" key of MYMETA.json. ## Documentation AnyEvent-WebSocket-Client documentation is available as POD. You can run `perldoc` from a shell to read the documentation: % perldoc AnyEvent::WebSocket::Client For more information on installing Perl modules via CPAN, please see: https://www.cpan.org/modules/INSTALL.html AnyEvent-WebSocket-Client-0.55/LICENSE000644 000000 000000 00000043667 14424756453 017315 0ustar00rootroot000000 000000 This software is copyright (c) 2013-2022 by Graham Ollis. 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) 2013-2022 by Graham Ollis. 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) 2013-2022 by Graham Ollis. 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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End AnyEvent-WebSocket-Client-0.55/MANIFEST000644 000000 000000 00000002646 14424756453 017431 0ustar00rootroot000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.025. Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README author.yml dist.ini example/README example/cpanfile example/jobrunner example/jobserver example/jobviewer example/slowlast lib/AnyEvent/WebSocket/Client.pm lib/AnyEvent/WebSocket/Connection.pm lib/AnyEvent/WebSocket/Message.pm maint/cip-before-install maint/proxy.pl perlcriticrc t/00_diag.t t/01_use.t t/anyevent_websocket_client.t t/anyevent_websocket_client__proxy.t t/anyevent_websocket_client__scope.t t/anyevent_websocket_client__server_initial_data_shutdown.t t/anyevent_websocket_client__ssl.t t/anyevent_websocket_connection.t t/anyevent_websocket_connection__counter_shutdown.t t/anyevent_websocket_connection__destroy_in_callbacks.t t/anyevent_websocket_connection__finish_callback.t t/anyevent_websocket_connection__payload_size.t t/anyevent_websocket_message.t t/lib/Test2/Plugin/AnyEvent/Timeout.pm t/lib/Test2/Plugin/EV.pm t/lib/Test2/Require/NotWindows.pm t/lib/Test2/Require/SSL.pm t/lib/Test2/Tools/WebSocket/Connection.pm t/lib/Test2/Tools/WebSocket/Mojo.pm t/lib/Test2/Tools/WebSocket/Server.pm t/mojo.t t/mojo_echo.t t/mojo_receive.t xt/author/critic.t xt/author/eol.t xt/author/no_tabs.t xt/author/pod.t xt/author/pod_coverage.t xt/author/pod_spelling_common.t xt/author/pod_spelling_system.t xt/author/strict.t xt/author/version.t xt/release/changes.t xt/release/fixme.t AnyEvent-WebSocket-Client-0.55/META.json000644 000000 000000 00000016733 14424756453 017723 0ustar00rootroot000000 000000 { "abstract" : "WebSocket client for AnyEvent", "author" : [ "Graham Ollis " ], "dynamic_config" : 1, "generated_by" : "Dist::Zilla version 6.025, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "AnyEvent-WebSocket-Client", "no_index" : { "directory" : [ "example" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0", "perl" : "5.006" } }, "develop" : { "recommends" : { "Dist::Zilla::Plugin::Author::Plicease::Thanks" : "0", "Dist::Zilla::Plugin::Author::Plicease::Upload" : "0", "Dist::Zilla::Plugin::DynamicPrereqs" : "0", "Dist::Zilla::Plugin::Meta::Dynamic::Config" : "0", "Dist::Zilla::Plugin::MetaNoIndex" : "0", "Dist::Zilla::Plugin::Prereqs" : "0", "Dist::Zilla::Plugin::RemovePrereqs" : "0", "Dist::Zilla::PluginBundle::Author::Plicease" : "2.69", "Perl::Critic::Policy::BuiltinFunctions::ProhibitBooleanGrep" : "0", "Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit" : "0", "Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidGrep" : "0", "Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap" : "0", "Perl::Critic::Policy::ClassHierarchies::ProhibitExplicitISA" : "0", "Perl::Critic::Policy::ClassHierarchies::ProhibitOneArgBless" : "0", "Perl::Critic::Policy::CodeLayout::ProhibitHardTabs" : "0", "Perl::Critic::Policy::CodeLayout::ProhibitTrailingWhitespace" : "0", "Perl::Critic::Policy::CodeLayout::RequireConsistentNewlines" : "0", "Perl::Critic::Policy::ControlStructures::ProhibitLabelsWithSpecialBlockNames" : "0", "Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions" : "0", "Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode" : "0", "Perl::Critic::Policy::Freenode::ArrayAssignAref" : "0", "Perl::Critic::Policy::Freenode::BarewordFilehandles" : "0", "Perl::Critic::Policy::Freenode::ConditionalDeclarations" : "0", "Perl::Critic::Policy::Freenode::ConditionalImplicitReturn" : "0", "Perl::Critic::Policy::Freenode::DeprecatedFeatures" : "0", "Perl::Critic::Policy::Freenode::DollarAB" : "0", "Perl::Critic::Policy::Freenode::Each" : "0", "Perl::Critic::Policy::Freenode::IndirectObjectNotation" : "0", "Perl::Critic::Policy::Freenode::LexicalForeachIterator" : "0", "Perl::Critic::Policy::Freenode::LoopOnHash" : "0", "Perl::Critic::Policy::Freenode::ModPerl" : "0", "Perl::Critic::Policy::Freenode::OpenArgs" : "0", "Perl::Critic::Policy::Freenode::OverloadOptions" : "0", "Perl::Critic::Policy::Freenode::POSIXImports" : "0", "Perl::Critic::Policy::Freenode::PackageMatchesFilename" : "0", "Perl::Critic::Policy::Freenode::PreferredAlternatives" : "0", "Perl::Critic::Policy::Freenode::StrictWarnings" : "0", "Perl::Critic::Policy::Freenode::Threads" : "0", "Perl::Critic::Policy::Freenode::Wantarray" : "0", "Perl::Critic::Policy::Freenode::WarningsSwitch" : "0", "Perl::Critic::Policy::Freenode::WhileDiamondDefaultAssignment" : "0", "Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles" : "0", "Perl::Critic::Policy::InputOutput::ProhibitJoinedReadline" : "0", "Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen" : "0", "Perl::Critic::Policy::Miscellanea::ProhibitFormats" : "0", "Perl::Critic::Policy::Miscellanea::ProhibitUselessNoCritic" : "0", "Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements" : "0", "Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish" : "0", "Perl::Critic::Policy::Objects::ProhibitIndirectSyntax" : "0", "Perl::Critic::Policy::RegularExpressions::ProhibitUselessTopic" : "0", "Perl::Critic::Policy::Subroutines::ProhibitNestedSubs" : "0", "Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros" : "0", "Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators" : "0", "Perl::Critic::Policy::ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator" : "0", "Perl::Critic::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator" : "0", "Perl::Critic::Policy::Variables::ProhibitPerl4PackageNames" : "0", "Perl::Critic::Policy::Variables::ProhibitUnusedVariables" : "0", "Software::License::Perl_5" : "0" }, "requires" : { "File::Spec" : "0", "Perl::Critic" : "0", "Test2::Require::Module" : "0.000121", "Test2::Tools::PerlCritic" : "0", "Test2::V0" : "0.000121", "Test::CPAN::Changes" : "0", "Test::EOL" : "0", "Test::Fixme" : "0.07", "Test::More" : "0.98", "Test::NoTabs" : "0", "Test::Pod" : "0", "Test::Pod::Coverage" : "0", "Test::Pod::Spelling::CommonMistakes" : "0", "Test::Spelling" : "0", "Test::Strict" : "0", "YAML" : "0" } }, "runtime" : { "recommends" : { "EV" : "0", "IO::Socket::SSL" : "0", "Math::Random::Secure" : "0", "Net::SSLeay" : "0", "PerlX::Maybe::XS" : "0" }, "requires" : { "AnyEvent" : "7.13", "AnyEvent::Connector" : "0.03", "Moo" : "2.0", "PerlX::Maybe" : "0.003", "Protocol::WebSocket" : "0.20", "URI" : "1.53", "URI::ws" : "0", "perl" : "5.008" } }, "test" : { "recommends" : { "Devel::Cycle" : "0", "EV" : "0", "Mojolicious" : "3.0", "Test::Memory::Cycle" : "0" }, "requires" : { "Protocol::WebSocket" : "0.20", "Test2::API" : "1.302015", "Test2::Require" : "0.000121", "Test2::Require::Module" : "0.000121", "Test2::V0" : "0.000121", "perl" : "5.008" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/uperl/AnyEvent-WebSocket-Client/issues" }, "homepage" : "https://metacpan.org/pod/AnyEvent::WebSocket::Client", "repository" : { "type" : "git", "url" : "git://github.com/uperl/AnyEvent-WebSocket-Client.git", "web" : "https://github.com/uperl/AnyEvent-WebSocket-Client" } }, "version" : "0.55", "x_contributors" : [ "Graham Ollis ", "Toshio Ito (debug-ito, TOSHIOITO)", "Jos\u00e9 Joaqu\u00edn Atria (JJATRIA)", "Kivanc Yazan (KYZN)", "Yanick Champoux (YANICK)", "Fayland Lam (FAYLAND)", "Daniel Kamil Kozar (xavery)" ], "x_generated_by_perl" : "v5.37.4", "x_serialization_backend" : "Cpanel::JSON::XS version 4.32", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later", "x_use_unsafe_inc" : 0 } AnyEvent-WebSocket-Client-0.55/META.yml000644 000000 000000 00000002777 14424756453 017556 0ustar00rootroot000000 000000 --- abstract: 'WebSocket client for AnyEvent' author: - 'Graham Ollis ' build_requires: Protocol::WebSocket: '0.20' Test2::API: '1.302015' Test2::Require: '0.000121' Test2::Require::Module: '0.000121' Test2::V0: '0.000121' perl: '5.008' configure_requires: ExtUtils::MakeMaker: '0' perl: '5.006' dynamic_config: 1 generated_by: 'Dist::Zilla version 6.025, 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: AnyEvent-WebSocket-Client no_index: directory: - example recommends: EV: '0' IO::Socket::SSL: '0' Math::Random::Secure: '0' Net::SSLeay: '0' PerlX::Maybe::XS: '0' requires: AnyEvent: '7.13' AnyEvent::Connector: '0.03' Moo: '2.0' PerlX::Maybe: '0.003' Protocol::WebSocket: '0.20' URI: '1.53' URI::ws: '0' perl: '5.008' resources: bugtracker: https://github.com/uperl/AnyEvent-WebSocket-Client/issues homepage: https://metacpan.org/pod/AnyEvent::WebSocket::Client repository: git://github.com/uperl/AnyEvent-WebSocket-Client.git version: '0.55' x_contributors: - 'Graham Ollis ' - 'Toshio Ito (debug-ito, TOSHIOITO)' - 'José Joaquín Atria (JJATRIA)' - 'Kivanc Yazan (KYZN)' - 'Yanick Champoux (YANICK)' - 'Fayland Lam (FAYLAND)' - 'Daniel Kamil Kozar (xavery)' x_generated_by_perl: v5.37.4 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' x_use_unsafe_inc: 0 AnyEvent-WebSocket-Client-0.55/Makefile.PL000644 000000 000000 00000007132 14424756453 020245 0ustar00rootroot000000 000000 BEGIN { use strict; use warnings; unless(eval q{ use 5.008; 1}) { print "Perl 5.008 or better required\n"; exit; } } # This file was automatically generated by Dist::Zilla::Plugin::Author::Plicease::MakeMaker v2.75. use strict; use warnings; use 5.008; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "WebSocket client for AnyEvent", "AUTHOR" => "Graham Ollis ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "AnyEvent-WebSocket-Client", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.008", "NAME" => "AnyEvent::WebSocket::Client", "PM" => { "lib/AnyEvent/WebSocket/Client.pm" => "\$(INST_LIB)/AnyEvent/WebSocket/Client.pm", "lib/AnyEvent/WebSocket/Connection.pm" => "\$(INST_LIB)/AnyEvent/WebSocket/Connection.pm", "lib/AnyEvent/WebSocket/Message.pm" => "\$(INST_LIB)/AnyEvent/WebSocket/Message.pm" }, "PREREQ_PM" => { "AnyEvent" => "7.13", "AnyEvent::Connector" => "0.03", "Moo" => "2.0", "PerlX::Maybe" => "0.003", "Protocol::WebSocket" => "0.20", "URI" => "1.53", "URI::ws" => 0 }, "TEST_REQUIRES" => { "Protocol::WebSocket" => "0.20", "Test2::API" => "1.302015", "Test2::Require" => "0.000121", "Test2::Require::Module" => "0.000121", "Test2::V0" => "0.000121" }, "VERSION" => "0.55", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "AnyEvent" => "7.13", "AnyEvent::Connector" => "0.03", "Moo" => "2.0", "PerlX::Maybe" => "0.003", "Protocol::WebSocket" => "0.20", "Test2::API" => "1.302015", "Test2::Require" => "0.000121", "Test2::Require::Module" => "0.000121", "Test2::V0" => "0.000121", "URI" => "1.53", "URI::ws" => 0 ); # inserted by Dist::Zilla::Plugin::DynamicPrereqs 0.040 if ( can_use('Crypt::Random::Source') ) { requires( 'Crypt::Random::Source', '0.08' ); } 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); # inserted by Dist::Zilla::Plugin::DynamicPrereqs 0.040 sub _add_prereq { my ( $mm_key, $module, $version_or_range ) = @_; $version_or_range ||= 0; warn "$module already exists in $mm_key (at version $WriteMakefileArgs{$mm_key}{$module}) -- need to do a sane metamerge!" if exists $WriteMakefileArgs{$mm_key}{$module} and $WriteMakefileArgs{$mm_key}{$module} ne '0' and $WriteMakefileArgs{$mm_key}{$module} ne $version_or_range; warn "$module already exists in FallbackPrereqs (at version $FallbackPrereqs{$module}) -- need to do a sane metamerge!" if exists $FallbackPrereqs{$module} and $FallbackPrereqs{$module} ne '0' and $FallbackPrereqs{$module} ne $version_or_range; $WriteMakefileArgs{$mm_key}{$module} = $FallbackPrereqs{$module} = $version_or_range; return; } sub can_use { my ( $module, $version ) = @_; return 0 if not eval "require $module; 1"; return 1 if not defined $version or eval "$module->VERSION($version); 1"; return 0; } sub requires { goto &runtime_requires } sub runtime_requires { my ( $module, $version_or_range ) = @_; _add_prereq( PREREQ_PM => $module, $version_or_range ); }AnyEvent-WebSocket-Client-0.55/README000644 000000 000000 00000016336 14424756453 017161 0ustar00rootroot000000 000000 NAME AnyEvent::WebSocket::Client - WebSocket client for AnyEvent VERSION version 0.55 SYNOPSIS use AnyEvent::WebSocket::Client 0.12; my $client = AnyEvent::WebSocket::Client->new; $client->connect("ws://localhost:1234/service")->cb(sub { # make $connection an our variable rather than # my so that it will stick around. Once the # connection falls out of scope any callbacks # tied to it will be destroyed. our $connection = eval { shift->recv }; if($@) { # handle error... warn $@; return; } # send a message through the websocket... $connection->send('a message'); # recieve message from the websocket... $connection->on(each_message => sub { # $connection is the same connection object # $message isa AnyEvent::WebSocket::Message my($connection, $message) = @_; ... }); # handle a closed connection... $connection->on(finish => sub { # $connection is the same connection object my($connection) = @_; ... }); # close the connection (either inside or # outside another callback) $connection->close; }); ## uncomment to enter the event loop before exiting. ## Note that calling recv on a condition variable before ## it has been triggered does not work on all event loops #AnyEvent->condvar->recv; DESCRIPTION This class provides an interface to interact with a web server that provides services via the WebSocket protocol in an AnyEvent context. It uses Protocol::WebSocket rather than reinventing the wheel. You could use AnyEvent and Protocol::WebSocket directly if you wanted finer grain control, but if that is not necessary then this class may save you some time. The recommended API was added to the AnyEvent::WebSocket::Connection class with version 0.12, so it is recommended that you include that version when using this module. The older version of the API has since been deprecated and removed. ATTRIBUTES timeout Timeout for the initial connection to the web server. The default is 30. ssl_no_verify If set to true, then secure WebSockets (those that use SSL/TLS) will not be verified. The default is false. ssl_ca_file Provide your own CA certificates file instead of using the system default for SSL/TLS verification. protocol_version The protocol version. See Protocol::WebSocket for the list of supported WebSocket protocol versions. subprotocol List of subprotocols to request from the server. This class will throw an exception if none of the protocols are supported by the server. http_headers Extra headers to include in the initial request. May be either specified as a hash reference, or an array reference. For example: AnyEvent::WebSocket::Client->new( http_headers => { 'X-Foo' => 'bar', 'X-Baz' => [ 'abc', 'def' ], }, ); AnyEvent::WebSocket::Client->new( http_headers => [ 'X-Foo' => 'bar', 'X-Baz' => 'abc', 'X-Baz' => 'def', ], ); Will generate: X-Foo: bar X-Baz: abc X-Baz: def Although, the order cannot be guaranteed when using the hash style. max_payload_size The maximum payload size for received frames. Currently defaults to whatever Protocol::WebSocket defaults to. max_fragments The maximum number of fragments for received frames. Currently defaults to whatever Protocol::WebSocket defaults to. env_proxy If you set true to this boolean attribute, it loads proxy settings from environment variables. If it finds valid proxy settings, connect method will use that proxy. Default: false. For ws WebSocket end-points, first it reads ws_proxy (or WS_PROXY) environment variable. If it is not set or empty string, then it reads http_proxy (or HTTP_PROXY). For wss WebSocket end-points, it reads wss_proxy (WSS_PROXY) and https_proxy (HTTPS_PROXY) environment variables. METHODS connect my $cv = $client->connect($uri) my $cv = $client->connect($uri, $host, $port); Open a connection to the web server and open a WebSocket to the resource defined by the given URL. The URL may be either an instance of URI::ws, URI::wss, or a string that represents a legal WebSocket URL. You can override the connection host and port by passing them in as the second and third argument. These values (if provided) are passed directly into AnyEvent::Socket's tcp_connect function, so please note that function's idiosyncrasies in the AnyEvent::Socket documentation. In particular, you can pass in unix/ as the host and a filesystem path as the "port" to connect to a unix domain socket. This method will return an AnyEvent condition variable which you can attach a callback to. The value sent through the condition variable will be either an instance of AnyEvent::WebSocket::Connection or a croak message indicating a failure. The synopsis above shows how to catch such errors using eval. FAQ My program exits before doing anything, what is up with that? See this FAQ from AnyEvent: AnyEvent::FAQ#My-program-exits-before-doing-anything-whats-going-on. It is probably also a good idea to review the AnyEvent documentation if you are new to AnyEvent or event-based programming. My callbacks aren't being called! Make sure that the connection object is still in scope. This often happens if you use a my $connection variable and don't save it somewhere. For example: $client->connect("ws://foo/service")->cb(sub { my $connection = eval { shift->recv }; if($@) { warn $@; return; } ... }); Unless $connection is saved somewhere it will get deallocated along with any associated message callbacks will also get deallocated once the connect callback is executed. One way to make sure that the connection doesn't get deallocated is to make it a our variable (as in the synopsis above) instead. CAVEATS This is pretty simple minded and there are probably WebSocket features that you might like to use that aren't supported by this distribution. Patches are encouraged to improve it. SEE ALSO * AnyEvent::WebSocket::Connection * AnyEvent::WebSocket::Message * AnyEvent::WebSocket::Server * AnyEvent * URI::ws * URI::wss * Protocol::WebSocket * Net::WebSocket::Server * Net::Async::WebSocket * RFC 6455 The WebSocket Protocol AUTHOR Author: Graham Ollis Contributors: Toshio Ito (debug-ito, TOSHIOITO) José Joaquín Atria (JJATRIA) Kivanc Yazan (KYZN) Yanick Champoux (YANICK) Fayland Lam (FAYLAND) Daniel Kamil Kozar (xavery) COPYRIGHT AND LICENSE This software is copyright (c) 2013-2022 by Graham Ollis. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. AnyEvent-WebSocket-Client-0.55/author.yml000644 000000 000000 00000001073 14424756453 020316 0ustar00rootroot000000 000000 --- pod_spelling_system: # list of words that are spelled correctly # (regardless of what spell check thinks) stopwords: - AnyEvent - WebSocket - WebSockets - unencrypted - Toshio - subprotocol - subprotocols - Kivanc - Yazan - unregisters - Champoux - JJATRIA - KYZN - TOSHIOITO - YANICK - Yanick - ito - FAYLAND - Fayland - Kamil - Kozar - xavery pod_coverage: # format is "Class#method" or "Class", regex allowed # for either Class or method. private: - .*#BUILD AnyEvent-WebSocket-Client-0.55/dist.ini000644 000000 000000 00000004075 14424756453 017742 0ustar00rootroot000000 000000 name = AnyEvent-WebSocket-Client author = Graham Ollis license = Perl_5 copyright_holder = Graham Ollis copyright_year = 2013-2022 version = 0.55 [@Author::Plicease] :version = 2.69 release_tests = 1 test2_v0 = 1 github_user = uperl workflow = linux workflow = windows workflow = macos workflow = msys2-mingw [RemovePrereqs] ; comes with perl 5.8 remove = strict remove = warnings remove = utf8 remove = lib remove = base remove = Scalar::Util remove = Carp remove = Encode remove = FindBin remove = Exporter ; comes with mojo remove = Mojo::Server::Daemon remove = AE remove = AnyEvent::Handle remove = AnyEvent::Socket remove = Mojolicious remove = Mojolicious::Lite remove = Capture::Tiny remove = Test::Memory::Cycle remove = Protocol::WebSocket::Frame remove = Protocol::WebSocket::Handshake::Client remove = Protocol::WebSocket::Handshake::Server remove = Protocol::WebSocket::Request [Prereqs] URI = 1.53 URI::ws = 0 Protocol::WebSocket = 0.20 Moo = 2.0 AnyEvent = 7.13 AnyEvent::Connector = 0.03 [Prereqs / SuggestedPrereqs] -relationship = recommends Math::Random::Secure = 0 IO::Socket::SSL = 0 Net::SSLeay = 0 [Prereqs / SuggestedTestPrereqs] -relationship = recommends -phase = test Mojolicious = 3.0 Test::Memory::Cycle = 0 Devel::Cycle = 0 [Author::Plicease::Upload] [MetaNoIndex] directory = example [Author::Plicease::Thanks] current = Graham Ollis contributor = Toshio Ito (debug-ito, TOSHIOITO) contributor = José Joaquín Atria (JJATRIA) contributor = Kivanc Yazan (KYZN) contributor = Yanick Champoux (YANICK) contributor = Fayland Lam (FAYLAND) contributor = Daniel Kamil Kozar (xavery) [Meta::Dynamic::Config] [DynamicPrereqs] ; if Crypt::Random::Source is installed, ; require at least version 0.08 to avoid ; deprecation messages from Class::MOP -condition = can_use('Crypt::Random::Source') -body = requires('Crypt::Random::Source', '0.08') AnyEvent-WebSocket-Client-0.55/example/000755 000000 000000 00000000000 14424756453 017723 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/example/README000644 000000 000000 00000003277 14424756453 020614 0ustar00rootroot000000 000000 This is a silly little example that shows how you can use AnyEvent::WebSocket::Client. - jobserver is a Mojolicious::Lite app (also requires Mojo::Redis2 and a redis server running on localhost) that cordinates and displays job output. - jobrunner is an AnyEvent::WebSocket::Client program that runs a program locally and sends the output as events via WebSocket to jobserver. - slowlast is just a program that runs `last -30` very slowly so that you can see the output update on the server. - jobviewer is an AnyEvent::WebSocket::Client program that attaches to the jobserver and displays a job as it is running via WebSockets. There are probably a few bugs and race conditions (in particular events may be missing for currently running jobs in the webapp or from the jobviewer) and there are probably better ways to do this sort of thing, but it demonstrates the library so there it is. Instructions: - install the prereqs if they aren't there: % cpanm --installdeps . - start redis (if it isn't already started): % redis-server - start the jobserver % ./jobserver daemon - in another window run a slow running process that produces some output, you can use slowlast as an example that comes with this distro % ./jobrunner ./slowlast - in your web browser, go to the jobserver url and navigate to the slow running process. You should see the existing output, plus any new output as it gets sent through the job server. http://localhost:3000 - in another window (again!) you can use jobviewer to watch a job in process: % jobviewer ... lists jobs managed by jobserver % jobviewer 1234:1 ... watch job 1234:1 AnyEvent-WebSocket-Client-0.55/example/cpanfile000644 000000 000000 00000000472 14424756453 021432 0ustar00rootroot000000 000000 requires 'AnyEvent'; requires 'AnyEvent::Open3::Simple'; requires 'AnyEvent::WebSocket::Client', '0.12'; requires 'JSON'; requires 'LWP::UserAgent'; requires 'Mojo::JSON'; requires 'Mojo::Redis2'; requires 'Mojolicious::Lite'; requires 'Text::Table'; requires 'URI'; requires 'autodie'; requires 'perl', 'v5.8.0'; AnyEvent-WebSocket-Client-0.55/example/jobrunner000755 000000 000000 00000002337 14424756453 021662 0ustar00rootroot000000 000000 #!/usr/bin/perl use strict; use warnings; use JSON qw( to_json ); use AnyEvent::Open3::Simple; use AnyEvent::WebSocket::Client 0.12; unless(@ARGV > 0) { print "usage: $0 command [arg1 [ arg2 [ ... ] ]\n"; exit 1; } my $client = AnyEvent::WebSocket::Client->new; my $connection = $client->connect("ws://localhost:3000/run")->recv; # error stdout stderr signal exit my $done = AnyEvent->condvar; my $ipc = AnyEvent::Open3::Simple->new( on_stdout => sub { my($proc, $line) = @_; print $line, "\n"; $connection->send(to_json({ type => 'out', data => $line })); }, on_stderr => sub { my($proc, $line) = @_; print STDERR $line, "\n"; $connection->send(to_json({ type => 'err', data => $line })); }, on_exit => sub { my($proc, $exit, $signal) = @_; $connection->send(to_json({ type => 'exit', exit => $exit, signal => $signal })); $done->send([$exit,$signal]); }, on_error => sub { my($error) = @_; $connection->send(to_json({ type => 'error', data => $error })); $done->croak($error); }, ); $connection->send(to_json(\@ARGV)); $ipc->run(@ARGV); my($exit,$signal) = @{ $done->recv }; if($signal) { print STDERR "died with signal $signal\n"; exit 1; } else { exit $exit; } AnyEvent-WebSocket-Client-0.55/example/jobserver000755 000000 000000 00000013052 14424756453 021653 0ustar00rootroot000000 000000 #!/usr/bin/perl use autodie; use strict; use warnings; use Mojo::Redis2; use Mojo::JSON qw/encode_json decode_json/; use Mojolicious::Lite; helper redis => sub { state $redis = Mojo::Redis2->new; }; my $jobnumber = 0; sub get_job_hash { my ($c, $cb) = @_; my $redis = $c->redis; my %redis_jobs = @{$redis->hgetall('jobs')}; my %jobs; foreach my $key (keys %redis_jobs){ my ($server, $id) = split /\./, $key; $jobs{$server}->{$id} = decode_json($redis_jobs{$key}); } $c->stash(jobs => \%jobs); $cb->(); $c->render_later; } get '/' => sub { shift->redirect_to('index'); }; get '/server.json' => sub { my $self = shift; get_job_hash($self, sub { $self->render(json => $self->stash('jobs')); }); }; get '/server' => sub { my $self = shift; get_job_hash($self, sub { $self->render('index'); }); } => 'index'; get '/server/:server' => sub { my $self = shift; get_job_hash($self, sub { my $server = $self->param('server'); if(defined $self->stash->{jobs}->{$server}) { $self->stash(server => $server); $self->render('server'); } else { $self->reply->not_found; } }); } => 'server'; sub get_old_events { my ($c, $cb) = @_; my $redis = $c->redis; my $id = $c->param('id'); my $server = $c->param('server'); my $key = join('.', $server, $id); my $list = join('.', qw( job event ), $key); my $command = decode_json($redis->hget('jobs',$key)); my $json_events = $redis->lrange($list, 0, -1); my @events; foreach my $event (@$json_events){ push @events, decode_json($event); } my $url = $c->req->url->to_abs; $url->path($c->url_for('events', server => $server, id => $id)); $url->scheme($url->scheme eq 'https' ? 'wss' : 'ws'); $c->stash({ command => $command, url => $url, events => \@events, encoded_events => encode_json(\@events), }); $cb->(); $c->render_later; } get '/job/:server/:id/json' => sub { my $self = shift; get_old_events($self, sub { $self->render(json => { command => $self->stash->{command}, events => $self->stash->{events}, event_url => $self->stash->{url}, }); }); }; get '/job/:server/:id' => sub { my $self = shift; get_old_events($self, sub { $self->render('job'); }); } => 'job'; websocket '/events/:server/:id' => sub { my $c = shift; my $redis = $c->redis; my $id = $c->param('id'); my $server = $c->param('server'); my $list = join('.', qw( job event ), $server, $id); $c->inactivity_timeout(600); $redis->subscribe([$list]); my $cb = $redis->on(message => sub{ $c->send($_[1]) }); $c->on(finish => sub { $redis->unsubscribe(message => $cb) }); } => 'events'; websocket '/run' => sub { my $c = shift; my $redis = $c->redis; my $id1 = join('.', $$, $jobnumber); my $id2 = join('.', qw( job event ), $$, $jobnumber++); $c->inactivity_timeout(600); $c->on(message => sub { my($c, $message) = @_; my $payload = decode_json($message); unless(defined $payload) { warn "error decoding: $message"; return; } if(ref($payload) eq 'ARRAY') { $redis->hset('jobs', $id1, $message); } else { $redis->rpush($id2, $message); $redis->publish($id2, $message); } }); $c->on(finish => sub { my $message = encode_json({ type => 'closed' }); $redis->rpush($id2, $message); $redis->publish($id2, $message); undef $id1; undef $id2; }); }; app->start; __DATA__ @@ index.html.ep % layout 'default'; % title 'job server';
    % foreach my $server (sort keys %$jobs) {
  • server <%= $server %>
  • % } @@ server.html.ep % layout 'default'; % title 'server ' . $server; @@ job.html.ep % layout 'default'; % title 'job';
    
    
    
    
    @@ layouts/default.html.ep
    
    
      
        <%= title %>
        
      
      <%= content %>
    
    
    @@ not_found.html.ep
    Not found
    AnyEvent-WebSocket-Client-0.55/example/jobviewer000755 000000 000000 00000003531 14424756453 021647 0ustar00rootroot000000 000000 #!/usr/bin/perl
    
    use strict;
    use warnings;
    use AnyEvent;
    use JSON qw( from_json );
    use AnyEvent::WebSocket::Client 0.12;
    use LWP::UserAgent;
    use URI;
    use Text::Table;
    
    my $uri = URI->new("http://localhost:3000");
    
    if(@ARGV == 0)
    {
      $uri->path("/server.json");
      my $ua = LWP::UserAgent->new;
      my $res = $ua->get($uri);
      die $res->status_line unless $res->is_success;
      my $data = from_json($res->decoded_content);
    
      my $table = Text::Table->new( 'id', 'command' );
    
      foreach my $server (sort keys %$data)
      {
        foreach my $id (sort keys %{ $data->{$server} })
        {
          $table->load([ "$server:$id", join(' ', '%', @{ $data->{$server}->{$id}}) ]);
        }
      }
    
      print $table;
      print "\n";
      print "usage: $0 [ id ]\n";
      exit;
    }
    
    my($server, $id) = split /:/, shift @ARGV;
    unless(defined $server && defined $id)
    {
      print "usage: $0 [ id ]\n";
      exit 2;
    }
    
    $uri->path("/job/$server/$id/json");
    my $ua = LWP::UserAgent->new;
    my $res = $ua->get($uri);
    die $res->status_line unless $res->is_success;
    my $job = from_json($res->decoded_content);
    
    my $done = AnyEvent->condvar;
    
    print(join(' ', '%', @{ $job->{command} }), "\n");
    process_message($_) for @{ $job->{events} };
    
    sub process_message
    {
      my $msg = shift;
      if($msg->{type} eq 'out')
      {
        print $msg->{data}, "\n";
      }
      elsif($msg->{type} eq 'err')
      {
        print $msg->{data}, "\n";
      }
      elsif($msg->{type} eq 'exit')
      {
        print "EXIT: " . $msg->{exit};
        print " SIGNAL: " . $msg->{signal} if $msg->{signal};
        print "\n";
      }
      elsif($msg->{type} eq 'error')
      {
        print "ERROR: " . $msg->{data}, "\n";
      }
      elsif($msg->{type} eq 'closed')
      {
        print "CONNECTION CLOSED", "\n";
        $done->send;
      }
    }
    
    my $ws = AnyEvent::WebSocket::Client->new->connect($job->{event_url})->recv;
    
    $ws->on(each_message => sub {
      my $msg = from_json( pop->decoded_body );
      process_message($msg);
    });
    
    $done->recv;
    AnyEvent-WebSocket-Client-0.55/example/slowlast000755 000000 000000 00000000116 14424756453 021517 0ustar00rootroot000000 000000 #!/usr/bin/perl
    $|=1;
    my @lines = `last -30`;
    print($_) && sleep 2 for @lines;AnyEvent-WebSocket-Client-0.55/lib/000755 000000 000000 00000000000 14424756453 017036 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/lib/AnyEvent/000755 000000 000000 00000000000 14424756453 020567 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/lib/AnyEvent/WebSocket/000755 000000 000000 00000000000 14424756453 022455 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/lib/AnyEvent/WebSocket/Client.pm000644 000000 000000 00000030331 14424756453 024231 0ustar00rootroot000000 000000 package AnyEvent::WebSocket::Client;
    
    use strict;
    use warnings;
    use Moo;
    use AE;
    use AnyEvent;
    use AnyEvent::Handle;
    use AnyEvent::Socket ();
    use Protocol::WebSocket::Request;
    use Protocol::WebSocket::Handshake::Client;
    use AnyEvent::WebSocket::Connection;
    use PerlX::Maybe qw( maybe provided );
    
    # ABSTRACT: WebSocket client for AnyEvent
    our $VERSION = '0.55'; # VERSION
    
    
    has timeout => (
      is      => 'ro',
      default => sub { 30 },
    );
    
    
    has ssl_no_verify => (
      is => 'ro',
    );
    
    
    has ssl_ca_file => (
      is => 'ro',
    );
    
    
    has protocol_version => (
      is => 'ro',
    );
    
    
    has subprotocol => (
      is     => 'ro',
      coerce => sub { ref $_[0] ? $_[0] : [$_[0]] },
    );
    
    
    has http_headers => (
      is => 'ro',
      coerce => sub {
        ref $_[0] eq 'ARRAY' ? $_[0] : do {
          my $h = shift;
          [
            map {
              my($k,$v) = ($_, $h->{$_});
              $v = [$v] unless ref $v;
              map { $k => $_ } @$v;
              # sorted to make testing easier.
              # may be removed in the future
              # so do not depend on it.
            } sort keys %$h
          ],
        };
      },
    );
    
    
    has max_payload_size => (
      is => 'ro',
    );
    
    
    has max_fragments => (
      is => 'ro',
    );
    
    
    has env_proxy => (
      is => 'ro',
      default => sub { 0 },
    );
    
    
    
    sub connect
    {
      my($self, $uri, $host, $port) = @_;
      unless(ref $uri)
      {
        require URI;
        $uri = URI->new($uri);
      }
    
      my $done = AE::cv;
    
      # TODO: should we also accept http and https URLs?
      # probably.
      if($uri->scheme ne 'ws' && $uri->scheme ne 'wss')
      {
        $done->croak("URI is not a websocket");
        return $done;
      }
    
      $host = $uri->host unless defined $host;
      $port = $uri->port unless defined $port;
    
      $self->_make_tcp_connection($uri->scheme, $host, $port, sub {
        my $fh = shift;
        unless($fh)
        {
          $done->croak("unable to connect");
          return;
        }
        my $req = Protocol::WebSocket::Request->new( maybe headers => $self->http_headers );
        my $handshake = Protocol::WebSocket::Handshake::Client->new(
                url     => $uri->as_string,
          maybe version => $self->protocol_version,
                req     => $req,
        );
    
        my %subprotocol;
        if($self->subprotocol)
        {
          %subprotocol = map { $_ => 1 } @{ $self->subprotocol };
          $handshake->req->subprotocol(join(',', @{ $self->subprotocol }));
        }
    
        my $hdl = AnyEvent::Handle->new(
                                                          fh       => $fh,
          provided $uri->secure,                          tls      => 'connect',
          provided $uri->secure && !$self->ssl_no_verify, peername => $uri->host,
          provided $uri->secure && !$self->ssl_no_verify, tls_ctx  => {
                                                                  verify => 1,
                                                                  verify_peername => "https",
                                                            maybe ca_file => $self->ssl_ca_file,
                                                          },
                                                          on_error => sub {
                                                            my ($hdl, $fatal, $msg) = @_;
                                                            if($fatal)
                                                            { $done->croak("connect error: " . $msg) }
                                                            else
                                                            { warn $msg }
                                                          },
        );
    
        $hdl->push_write($handshake->to_string);
        $hdl->on_read(sub {
          $handshake->parse($_[0]{rbuf});
          if($handshake->error)
          {
            $done->croak("handshake error: " . $handshake->error);
            undef $hdl;
            undef $handshake;
            undef $done;
          }
          elsif($handshake->is_done)
          {
            my $sb;
            if($self->subprotocol)
            {
              $sb = $handshake->res->subprotocol;
              if(defined $sb)
              {
                unless($subprotocol{$sb})
                {
                  $done->croak("subprotocol mismatch, requested: @{[ join ', ', @{ $self->subprotocol } ]}, got: $sb");
                }
              }
              else
              {
                $done->croak("no subprotocol in response");
              }
            }
            undef $handshake;
            $done->send(
              AnyEvent::WebSocket::Connection->new(
                      handle               => $hdl,
                      masked               => 1,
                maybe subprotocol          => $sb,
                maybe max_payload_size     => $self->max_payload_size,
                maybe max_fragments        => $self->max_fragments,
              )
            );
            undef $hdl;
            undef $done;
          }
        });
      }, sub { $self->timeout });
      $done;
    }
    
    sub _make_tcp_connection
    {
      my $self = shift;
      my $scheme = shift;
      my ($host, $port) = @_;
      if(!$self->env_proxy)
      {
        return &AnyEvent::Socket::tcp_connect(@_);
      }
      require AnyEvent::Connector;
      my @connectors =
          $scheme eq "ws"
          ? (map { AnyEvent::Connector->new(env_proxy => $_) } qw(ws http))
          : $scheme eq "wss"
          ? (map { AnyEvent::Connector->new(env_proxy => $_) } qw(wss https))
          : ();
      foreach my $connector (@connectors)
      {
        if(defined($connector->proxy_for($host, $port)))
        {
          return $connector->tcp_connect(@_);
        }
      }
      return &AnyEvent::Socket::tcp_connect(@_);
    }
    
    1;
    
    __END__
    
    =pod
    
    =encoding UTF-8
    
    =head1 NAME
    
    AnyEvent::WebSocket::Client - WebSocket client for AnyEvent
    
    =head1 VERSION
    
    version 0.55
    
    =head1 SYNOPSIS
    
     use AnyEvent::WebSocket::Client 0.12;
     
     my $client = AnyEvent::WebSocket::Client->new;
     
     $client->connect("ws://localhost:1234/service")->cb(sub {
     
       # make $connection an our variable rather than
       # my so that it will stick around.  Once the
       # connection falls out of scope any callbacks
       # tied to it will be destroyed.
       our $connection = eval { shift->recv };
       if($@) {
         # handle error...
         warn $@;
         return;
       }
     
       # send a message through the websocket...
       $connection->send('a message');
     
       # recieve message from the websocket...
       $connection->on(each_message => sub {
         # $connection is the same connection object
         # $message isa AnyEvent::WebSocket::Message
         my($connection, $message) = @_;
         ...
       });
     
       # handle a closed connection...
       $connection->on(finish => sub {
         # $connection is the same connection object
         my($connection) = @_;
         ...
       });
     
       # close the connection (either inside or
       # outside another callback)
       $connection->close;
     
     });
     
     ## uncomment to enter the event loop before exiting.
     ## Note that calling recv on a condition variable before
     ## it has been triggered does not work on all event loops
     #AnyEvent->condvar->recv;
    
    =head1 DESCRIPTION
    
    This class provides an interface to interact with a web server that provides
    services via the WebSocket protocol in an L context.  It uses
    L rather than reinventing the wheel.  You could use
    L and L directly if you wanted finer grain
    control, but if that is not necessary then this class may save you some time.
    
    The recommended API was added to the L
    class with version 0.12, so it is recommended that you include that version
    when using this module.  The older version of the API has since been
    deprecated and removed.
    
    =head1 ATTRIBUTES
    
    =head2 timeout
    
    Timeout for the initial connection to the web server.  The default
    is 30.
    
    =head2 ssl_no_verify
    
    If set to true, then secure WebSockets (those that use SSL/TLS) will
    not be verified.  The default is false.
    
    =head2 ssl_ca_file
    
    Provide your own CA certificates file instead of using the system default for
    SSL/TLS verification.
    
    =head2 protocol_version
    
    The protocol version.  See L for the list of supported
    WebSocket protocol versions.
    
    =head2 subprotocol
    
    List of subprotocols to request from the server.  This class will throw an
    exception if none of the protocols are supported by the server.
    
    =head2 http_headers
    
    Extra headers to include in the initial request.  May be either specified
    as a hash reference, or an array reference.  For example:
    
     AnyEvent::WebSocket::Client->new(
       http_headers => {
         'X-Foo' => 'bar',
         'X-Baz' => [ 'abc', 'def' ],
       },
     );
     
     AnyEvent::WebSocket::Client->new(
       http_headers => [
         'X-Foo' => 'bar',
         'X-Baz' => 'abc',
         'X-Baz' => 'def',
       ],
     );
    
    Will generate:
    
     X-Foo: bar
     X-Baz: abc
     X-Baz: def
    
    Although, the order cannot be guaranteed when using the hash style.
    
    =head2 max_payload_size
    
    The maximum payload size for received frames.  Currently defaults to whatever
    L defaults to.
    
    =head2 max_fragments
    
    The maximum number of fragments for received frames.  Currently defaults to whatever
    L defaults to.
    
    =head2 env_proxy
    
    If you set true to this boolean attribute, it loads proxy settings
    from environment variables. If it finds valid proxy settings,
    C method will use that proxy.
    
    Default: false.
    
    For C WebSocket end-points, first it reads C (or
    C) environment variable. If it is not set or empty string,
    then it reads C (or C). For C WebSocket
    end-points, it reads C (C) and C
    (C) environment variables.
    
    =head1 METHODS
    
    =head2 connect
    
     my $cv = $client->connect($uri)
     my $cv = $client->connect($uri, $host, $port);
    
    Open a connection to the web server and open a WebSocket to the resource
    defined by the given URL.  The URL may be either an instance of L,
    L, or a string that represents a legal WebSocket URL.
    
    You can  override the connection host and port by passing them in as the
    second and third argument.  These values (if provided) are passed directly
    into L's C function, so please note that
    function's idiosyncrasies in the L documentation.  In
    particular,  you can pass in C as the host and a filesystem path
    as the "port" to connect to a unix domain socket.
    
    This method will return an L condition variable which you can
    attach a callback to.  The value sent through the condition variable will
    be either an instance of L or a croak
    message indicating a failure.  The synopsis above shows how to catch
    such errors using C.
    
    =head1 FAQ
    
    =head2 My program exits before doing anything, what is up with that?
    
    See this FAQ from L:
    L.
    
    It is probably also a good idea to review the L documentation
    if you are new to L or event-based programming.
    
    =head2 My callbacks aren't being called!
    
    Make sure that the connection object is still in scope.  This often happens
    if you use a C variable and don't save it somewhere.  For
    example:
    
     $client->connect("ws://foo/service")->cb(sub {
     
       my $connection = eval { shift->recv };
     
       if($@)
       {
         warn $@;
         return;
       }
     
       ...
     });
    
    Unless C<$connection> is saved somewhere it will get deallocated along with
    any associated message callbacks will also get deallocated once the connect
    callback is executed.  One way to make sure that the connection doesn't
    get deallocated is to make it a C variable (as in the synopsis above)
    instead.
    
    =head1 CAVEATS
    
    This is pretty simple minded and there are probably WebSocket features
    that you might like to use that aren't supported by this distribution.
    Patches are encouraged to improve it.
    
    =head1 SEE ALSO
    
    =over 4
    
    =item *
    
    L
    
    =item *
    
    L
    
    =item *
    
    L
    
    =item *
    
    L
    
    =item *
    
    L
    
    =item *
    
    L
    
    =item *
    
    L
    
    =item *
    
    L
    
    =item *
    
    L
    
    =item *
    
    L
    
    =back
    
    =for stopwords Joaquín José
    
    =head1 AUTHOR
    
    Author: Graham Ollis Eplicease@cpan.orgE
    
    Contributors:
    
    Toshio Ito (debug-ito, TOSHIOITO)
    
    José Joaquín Atria (JJATRIA)
    
    Kivanc Yazan (KYZN)
    
    Yanick Champoux (YANICK)
    
    Fayland Lam (FAYLAND)
    
    Daniel Kamil Kozar (xavery)
    
    =head1 COPYRIGHT AND LICENSE
    
    This software is copyright (c) 2013-2022 by Graham Ollis.
    
    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
    AnyEvent-WebSocket-Client-0.55/lib/AnyEvent/WebSocket/Connection.pm000644 000000 000000 00000032747 14424756453 025127 0ustar00rootroot000000 000000 package AnyEvent::WebSocket::Connection;
    
    use strict;
    use warnings;
    use Moo;
    use Protocol::WebSocket::Frame;
    use Scalar::Util ();
    use Encode ();
    use AE;
    use AnyEvent::WebSocket::Message;
    use PerlX::Maybe qw( maybe provided );
    use Carp ();
    
    # ABSTRACT: WebSocket connection for AnyEvent
    our $VERSION = '0.55'; # VERSION
    
    
    has handle => (
      is       => 'ro',
      required => 1,
    );
    
    
    has masked => (
      is      => 'ro',
      default => sub { 0 },
    );
    
    
    has subprotocol => (
      is => 'ro',
    );
    
    
    has max_payload_size => (
      is => 'ro',
    );
    
    
    has max_fragments => (
      is => 'ro',
    );
    
    
    has close_code => (
      is => 'rw',
    );
    
    
    has close_reason => (
      is => 'rw',
    );
    
    
    has close_error => (
      is => 'rw',
    );
    
    foreach my $type (qw( each_message next_message finish parse_error ))
    {
      has "_${type}_cb" => (
        is       => 'ro',
        init_arg => undef,
        default  => sub { [] },
      );
    }
    
    foreach my $flag (qw( _is_read_open _is_write_open ))
    {
      has $flag => (
        is       => 'rw',
        init_arg => undef,
        default  => sub { 1 },
      );
    }
    
    has "_is_finished" => (
      is       => 'rw',
      init_arg => undef,
      default  => sub { 0 },
    );
    
    sub BUILD
    {
      my $self = shift;
      Scalar::Util::weaken $self;
    
      my @temp_messages = ();
      my $are_callbacks_supposed_to_be_ready = 0;
    
      my $finish = sub {
        my(undef, undef, $message) = @_;
        my $strong_self = $self; # preserve $self because otherwise $self can be destroyed in the callbacks.
        return if $self->_is_finished;
        eval
        {
          $self->_process_message($_) foreach @temp_messages;
        };
        @temp_messages = ();
        $self->_is_finished(1);
        $self->handle->push_shutdown;
        $self->_is_read_open(0);
        $self->_is_write_open(0);
        $self->close_error($message) if defined $message;
        $_->($self, $message) for @{ $self->_finish_cb };
      };
      $self->handle->on_error($finish);
      $self->handle->on_eof($finish);
    
      my $frame = Protocol::WebSocket::Frame->new(
        maybe max_payload_size => $self->max_payload_size,
        maybe max_fragments_amount => $self->max_fragments,
      );
    
      my $read_cb = sub {
        my ($handle) = @_;
        local $@;
        my $strong_self = $self; # preserve $self because otherwise $self can be destroyed in the callbacks
        my $success = eval
        {
          $frame->append($handle->{rbuf});
          while(defined(my $body = $frame->next_bytes))
          {
            next if !$self->_is_read_open; # not 'last' but 'next' in order to consume data in $frame buffer.
            my $message = AnyEvent::WebSocket::Message->new(
              body   => $body,
              opcode => $frame->opcode,
            );
            if($are_callbacks_supposed_to_be_ready)
            {
              $self->_process_message($message);
            }
            else
            {
              push(@temp_messages, $message);
            }
          }
          1; # succeed to parse.
        };
        if(!$success)
        {
          $self->_force_shutdown();
          $_->($self, $@) for @{ $self->_parse_error_cb };
        }
      };
    
    
      # Message processing (calling _process_message) is delayed by
      # $are_callbacks_supposed_to_be_ready flag. This is necessary to
      # make sure all received messages are delivered to each_message and
      # next_message callbacks. If there is some data in rbuf, changing
      # the on_read callback makes the callback fire, but there is of
      # course no each_message/next_message callback to receive the
      # message yet. So we put messages to @temp_messages for a
      # while. After the control is returned to the user, who sets up
      # each_message/next_message callbacks, @temp_messages are processed.
    
      # An alternative approach would be temporarily disabling on_read by
      # $self->handle->on_read(undef). However, this can cause a weird
      # situation in TLS mode, because on_eof can fire even if we don't
      # have any on_read (
      # https://metacpan.org/pod/AnyEvent::Handle#I-get-different-callback-invocations-in-TLS-mode-Why-cant-I-pause-reading
      # )
      $self->handle->on_read($read_cb);
      my $idle_w; $idle_w = AE::idle sub {
        undef $idle_w;
        if(defined($self))
        {
          my $strong_self = $self;
          $are_callbacks_supposed_to_be_ready = 1;
          local $@;
          my $success = eval
          {
            $self->_process_message($_) foreach @temp_messages;
            1;
          };
          @temp_messages = ();
          if(!$success)
          {
            $self->_force_shutdown();
          }
        }
      };
    }
    
    sub _process_message
    {
      my ($self, $received_message) = @_;
      return if !$self->_is_read_open;
    
      if($received_message->is_text || $received_message->is_binary)
      {
        # make a copy in order to allow specifying new callbacks inside the
        # currently executed next_callback itself. otherwise, any next_callback
        # added inside the currently executed callback would be added to the end
        # of the array and executed for the currently processed message instead of
        # actually the next one.
        my @next_callbacks = @{ $self->_next_message_cb };
        @{ $self->_next_message_cb } = ();
        $_->($self, $received_message) for @next_callbacks;
    
        # make a copy in case one of the callbacks get
        # unregistered in the middle of the loop
        my @callbacks = @{ $self->_each_message_cb };
        $_->($self, $received_message, $self->_cancel_for(each_message => $_) )
            for @callbacks;
      }
      elsif($received_message->is_close)
      {
        my $body = $received_message->body;
        if($body)
        {
          my($code, $reason) = unpack 'na*', $body;
          $self->close_code($code);
          $self->close_reason(Encode::decode('UTF-8', $reason));
        }
        $self->_is_read_open(0);
        $self->close();
      }
      elsif($received_message->is_ping)
      {
        $self->send(AnyEvent::WebSocket::Message->new(opcode => 10, body => $received_message->body));
      }
    }
    
    sub _force_shutdown
    {
      my ($self) = @_;
      $self->handle->push_shutdown;
      $self->_is_write_open(0);
      $self->_is_read_open(0);
    }
    
    
    sub send
    {
      my($self, $message) = @_;
      my $frame;
    
      return $self if !$self->_is_write_open;
    
      if(ref $message)
      {
        $frame = Protocol::WebSocket::Frame->new(opcode => $message->opcode, buffer => $message->body, masked => $self->masked, max_payload_size => 0);
      }
      else
      {
        $frame = Protocol::WebSocket::Frame->new(buffer => $message, masked => $self->masked, max_payload_size => 0);
      }
      $self->handle->push_write($frame->to_bytes);
      $self;
    }
    
    
    sub _cancel_for
    {
      my( $self, $event, $handler ) = @_;
    
      my $handler_id = Scalar::Util::refaddr($handler);
    
      return sub {
        my $accessor = "_${event}_cb";
        @{ $self->$accessor } = grep { Scalar::Util::refaddr($_) != $handler_id }
                                @{ $self->$accessor };
      };
    }
    
    sub on
    {
      my($self, $event, $cb) = @_;
    
      if($event eq 'next_message')
      {
        push @{ $self->_next_message_cb }, $cb;
      }
      elsif($event eq 'each_message')
      {
        push @{ $self->_each_message_cb }, $cb;
      }
      elsif($event eq 'finish')
      {
        push @{ $self->_finish_cb }, $cb;
      }
      elsif($event eq 'parse_error')
      {
        push @{ $self->_parse_error_cb }, $cb;
      }
      else
      {
        Carp::croak "unrecongized event: $event";
      }
    
      return $self->_cancel_for($event,$cb);
    }
    
    
    sub close
    {
      my($self, $code, $reason) = @_;
    
      my $body = pack('n', ($code) ? $code : '1000');
    
      $body .= Encode::encode 'UTF-8', $reason if defined $reason;
    
      $self->send(AnyEvent::WebSocket::Message->new(
        opcode => 8,
        body => $body,
      ));
      $self->handle->push_shutdown;
      $self->_is_write_open(0);
      $self;
    }
    
    if($] < 5.010)
    {
      # This is a workaround for GH#19
      # https://github.com/plicease/AnyEvent-WebSocket-Client/issues/19
      # I am not 100% sure about this, but maybe as a trade off it isn't
      # too bad?  The previous workaround was to downgrade to AE 6.x
      # something.  Unfortunately, we now require AE 7.x something for
      # SSL bug fixes.
      *DEMOLISH = sub
      {
        my($self) = @_;
        eval { $self->handle->push_shutdown } if $self->_is_write_open;
      };
    }
    
    1;
    
    __END__
    
    =pod
    
    =encoding UTF-8
    
    =head1 NAME
    
    AnyEvent::WebSocket::Connection - WebSocket connection for AnyEvent
    
    =head1 VERSION
    
    version 0.55
    
    =head1 SYNOPSIS
    
     # send a message through the websocket...
     $connection->send('a message');
     
     # recieve message from the websocket...
     $connection->on(each_message => sub {
       # $connection is the same connection object
       # $message isa AnyEvent::WebSocket::Message
       my($connection, $message) = @_;
       ...
     });
     
     # handle a closed connection...
     $connection->on(finish => sub {
       # $connection is the same connection object
       my($connection) = @_;
       ...
     });
     
     # close an opened connection
     # (can do this either inside or outside of
     # a callback)
     $connection->close;
    
    (See L or L on
    how to create a connection)
    
    =head1 DESCRIPTION
    
    This class represents a WebSocket connection with a remote server or a
    client.
    
    If the connection object falls out of scope then the connection will be
    closed gracefully.
    
    This class was created for a client to connect to a server via
    L, and was later extended to work on the
    server side via L.  Once a WebSocket
    connection is established, the API for both client and server is
    identical.
    
    =head1 ATTRIBUTES
    
    =head2 handle
    
    The underlying L object used for the connection.
    WebSocket handshake MUST be already completed using this handle.
    You should not use the handle directly after creating L object.
    
    Usually only useful for creating server connections, see below.
    
    =head2 masked
    
    If set to true, it masks outgoing frames. The default is false.
    
    =head2 subprotocol
    
    The subprotocol returned by the server.  If no subprotocol was requested, it
    may be C.
    
    =head2 max_payload_size
    
    The maximum payload size for received frames.  Currently defaults to whatever
    L defaults to.
    
    =head2 max_fragments
    
    The maximum number of fragments for received frames.  Currently defaults to whatever
    L defaults to.
    
    =head2 close_code
    
    If provided by the other side, the code that was provided when the
    connection was closed.
    
    =head2 close_reason
    
    If provided by the other side, the reason for closing the connection.
    
    =head2 close_error
    
    If the connection is closed due to a network error, this will hold the
    message.
    
    =head1 METHODS
    
    =head2 send
    
     $connection->send($message);
    
    Send a message to the other side.  C<$message> may either be a string
    (in which case a text message will be sent), or an instance of
    L.
    
    =head2 on
    
     $connection->on(each_message => $cb);
     $connection->on(each_message => $cb);
     $connection->on(finish => $cb);
    
    Register a callback to a particular event.
    
    For each event C<$connection> is the L and
    and C<$message> is an L (if available).
    
    Returns a coderef that unregisters the callback when invoked.
    
     my $cancel = $connection->on( each_message => sub { ...  });
     
     # later on...
     $cancel->();
    
    =head3 each_message
    
     $cb->($connection, $message, $unregister)
    
    Called each time a message is received from the WebSocket.
    C<$unregister> is a coderef that removes this callback from
    the active listeners when invoked.
    
    =head3 next_message
    
     $cb->($connection, $message)
    
    Called only for the next message received from the WebSocket.
    
    [0.49]
    
    Adding a next_message callback from within a next_message callback will
    result in a callback called on the next message instead of the current
    one. There was a bug in previous versions where the callback would be
    called immediately after current set of callbacks with the same message.
    
    =head3 parse_error
    
     $cb->($connection, $text_error_message)
    
    Called if there is an error parsing a message sent from the remote end.
    After this callback is called, the connection will be closed.
    Among other possible errors, this event will trigger if a frame has a
    payload which is larger that C.
    
    =head3 finish
    
     $cb->($connection, $message)
    
    Called when the connection is terminated.  If the connection is terminated
    due to an error, the message will be provided as the second argument.
    On a cleanly closed connection this will be `undef`.
    
    =head2 close
    
     $connection->close;
     $connection->close($code);
     $connection->close($code, $reason);
    
    Close the connection.  You may optionally provide a code and a reason.
    See L
    and L
    of RFC6455. The code is a 16-bit unsigned integer value that indicates why you close the connection. By default the code is 1000. The reason is a character string (not an octet string) that further describes why you close the connection. By default the reason is an empty string. =head1 SERVER CONNECTIONS Although written originally to work with L, this class was designed to be used for either client or server WebSocket connections. For details, contact the author and/or take a look at the source for L and the examples that come with L. =head1 SEE ALSO =over 4 =item * L =item * L =item * L =item * L =item * L =back =for stopwords Joaquín José =head1 AUTHOR Author: Graham Ollis Eplicease@cpan.orgE Contributors: Toshio Ito (debug-ito, TOSHIOITO) José Joaquín Atria (JJATRIA) Kivanc Yazan (KYZN) Yanick Champoux (YANICK) Fayland Lam (FAYLAND) Daniel Kamil Kozar (xavery) =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2013-2022 by Graham Ollis. 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 AnyEvent-WebSocket-Client-0.55/lib/AnyEvent/WebSocket/Message.pm000644 000000 000000 00000005056 14424756453 024405 0ustar00rootroot000000 000000 package AnyEvent::WebSocket::Message; use strict; use warnings; use Moo; use Encode (); # ABSTRACT: WebSocket message for AnyEvent our $VERSION = '0.55'; # VERSION has body => ( is => 'ro', required => 1 ); has opcode => ( is => 'ro', default => 1 ); sub decoded_body { Encode::decode("UTF-8", shift->body) } sub is_text { $_[0]->opcode == 1 } sub is_binary { $_[0]->opcode == 2 } sub is_close { $_[0]->opcode == 8 } sub is_ping { $_[0]->opcode == 9 } sub is_pong { $_[0]->opcode == 10 } 1; __END__ =pod =encoding UTF-8 =head1 NAME AnyEvent::WebSocket::Message - WebSocket message for AnyEvent =head1 VERSION version 0.55 =head1 SYNOPSIS $connection->send( AnyEvent::WebSocket::Message->new(body => "some message"), ); $connection->on(each_message => sub { my($connection, $message) = @_; if($message->is_text || $message->is_binary) { my $body = $message->body; } }); =head1 DESCRIPTION Instances of this class represent a single WebSocket message. They are the objects that come through from the other end of your L instance. They can also be sent through that class using its C method. =head1 ATTRIBUTES =head2 body The body or payload of the message. =head2 opcode The integer code for the type of message. =head1 METHODS =head2 decoded_body my $body = $message->decoded_body; Returns the body decoded from UTF-8. =head2 is_text my $bool = $message->is_text; True if the message is text. =head2 is_binary my $bool = $message->is_binary; True if the message is binary. =head2 is_close my $bool = $message->is_close; True if the message is a close message. =head2 is_ping my $bool = $message->is_ping True if the message is a ping. =head2 is_pong my $bool = $message->is_pong; True if the message is a pong. =head1 SEE ALSO =over 4 =item * L =item * L =item * L =item * L =item * L =back =for stopwords Joaquín José =head1 AUTHOR Author: Graham Ollis Eplicease@cpan.orgE Contributors: Toshio Ito (debug-ito, TOSHIOITO) José Joaquín Atria (JJATRIA) Kivanc Yazan (KYZN) Yanick Champoux (YANICK) Fayland Lam (FAYLAND) Daniel Kamil Kozar (xavery) =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2013-2022 by Graham Ollis. 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 AnyEvent-WebSocket-Client-0.55/maint/000755 000000 000000 00000000000 14424756453 017400 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/maint/cip-before-install000755 000000 000000 00000000335 14424756453 023006 0ustar00rootroot000000 000000 #!/bin/bash set -ex cip exec cpanm -n Net::SSLeay IO::Socket::SSL Capture::Tiny Test::Memory::Cycle HTTP::Proxy cip exec cpanm -n EV || true cip exec cpanm -n Mojolicious || true cip exec-background perl maint/proxy.pl AnyEvent-WebSocket-Client-0.55/maint/proxy.pl000644 000000 000000 00000000151 14424756453 021113 0ustar00rootroot000000 000000 use strict; use warnings; use HTTP::Proxy; my $proxy = HTTP::Proxy->new( port => 3128 ); $proxy->start; AnyEvent-WebSocket-Client-0.55/perlcriticrc000644 000000 000000 00000003603 14424756453 020702 0ustar00rootroot000000 000000 severity = 1 only = 1 [Freenode::ArrayAssignAref] [Freenode::BarewordFilehandles] [Freenode::ConditionalDeclarations] [Freenode::ConditionalImplicitReturn] [Freenode::DeprecatedFeatures] [Freenode::DollarAB] [Freenode::Each] [Freenode::IndirectObjectNotation] [Freenode::LexicalForeachIterator] [Freenode::LoopOnHash] [Freenode::ModPerl] [Freenode::OpenArgs] [Freenode::OverloadOptions] [Freenode::POSIXImports] [Freenode::PackageMatchesFilename] [Freenode::PreferredAlternatives] [Freenode::StrictWarnings] extra_importers = Test2::V0 [Freenode::Threads] [Freenode::Wantarray] [Freenode::WarningsSwitch] [Freenode::WhileDiamondDefaultAssignment] [BuiltinFunctions::ProhibitBooleanGrep] ;[BuiltinFunctions::ProhibitStringyEval] [BuiltinFunctions::ProhibitStringySplit] [BuiltinFunctions::ProhibitVoidGrep] [BuiltinFunctions::ProhibitVoidMap] [ClassHierarchies::ProhibitExplicitISA] [ClassHierarchies::ProhibitOneArgBless] [CodeLayout::ProhibitHardTabs] allow_leading_tabs = 0 [CodeLayout::ProhibitTrailingWhitespace] [CodeLayout::RequireConsistentNewlines] [ControlStructures::ProhibitLabelsWithSpecialBlockNames] [ControlStructures::ProhibitMutatingListFunctions] [ControlStructures::ProhibitUnreachableCode] [InputOutput::ProhibitBarewordFileHandles] [InputOutput::ProhibitJoinedReadline] [InputOutput::ProhibitTwoArgOpen] [Miscellanea::ProhibitFormats] [Miscellanea::ProhibitUselessNoCritic] [Modules::ProhibitConditionalUseStatements] ;[Modules::RequireEndWithOne] [Modules::RequireNoMatchVarsWithUseEnglish] [Objects::ProhibitIndirectSyntax] [RegularExpressions::ProhibitUselessTopic] [Subroutines::ProhibitNestedSubs] [ValuesAndExpressions::ProhibitLeadingZeros] [ValuesAndExpressions::ProhibitMixedBooleanOperators] [ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator] [ValuesAndExpressions::RequireUpperCaseHeredocTerminator] [Variables::ProhibitPerl4PackageNames] [Variables::ProhibitUnusedVariables] AnyEvent-WebSocket-Client-0.55/t/000755 000000 000000 00000000000 14424756453 016533 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/t/00_diag.t000644 000000 000000 00000003056 14424756453 020127 0ustar00rootroot000000 000000 use Test2::V0 -no_srand => 1; use Config; eval { require 'Test/More.pm' }; # This .t file is generated. # make changes instead to dist.ini my %modules; my $post_diag; BEGIN { eval q{ use EV; } } $modules{$_} = $_ for qw( AnyEvent AnyEvent::Connector Devel::Cycle EV ExtUtils::MakeMaker IO::Socket::SSL Math::Random::Secure Mojolicious Moo Net::SSLeay PerlX::Maybe PerlX::Maybe::XS Protocol::WebSocket Test2::API Test2::Require Test2::Require::Module Test2::V0 Test::Memory::Cycle URI URI::ws ); my @modules = sort keys %modules; sub spacer () { diag ''; diag ''; diag ''; } pass 'okay'; my $max = 1; $max = $_ > $max ? $_ : $max for map { length $_ } @modules; our $format = "%-${max}s %s"; spacer; my @keys = sort grep /(MOJO|PERL|\A(LC|HARNESS)_|\A(SHELL|LANG)\Z)/i, keys %ENV; if(@keys > 0) { diag "$_=$ENV{$_}" for @keys; if($ENV{PERL5LIB}) { spacer; diag "PERL5LIB path"; diag $_ for split $Config{path_sep}, $ENV{PERL5LIB}; } elsif($ENV{PERLLIB}) { spacer; diag "PERLLIB path"; diag $_ for split $Config{path_sep}, $ENV{PERLLIB}; } spacer; } diag sprintf $format, 'perl', "$] $^O $Config{archname}"; foreach my $module (sort @modules) { my $pm = "$module.pm"; $pm =~ s{::}{/}g; if(eval { require $pm; 1 }) { my $ver = eval { $module->VERSION }; $ver = 'undef' unless defined $ver; diag sprintf $format, $module, $ver; } else { diag sprintf $format, $module, '-'; } } if($post_diag) { spacer; $post_diag->(); } spacer; done_testing; AnyEvent-WebSocket-Client-0.55/t/01_use.t000644 000000 000000 00000001111 14424756453 020006 0ustar00rootroot000000 000000 use Test2::V0 -no_srand => 1; sub require_ok ($); require_ok 'AnyEvent::WebSocket::Client'; require_ok 'AnyEvent::WebSocket::Connection'; require_ok 'AnyEvent::WebSocket::Message'; done_testing; sub require_ok ($) { # special case of when I really do want require_ok. # I just want a test that checks that the modules # will compile okay. I won't be trying to use them. my($mod) = @_; my $ctx = context(); eval qq{ require $mod }; my $error = $@; my $ok = !$error; $ctx->ok($ok, "require $mod"); $ctx->diag("error: $error") if $error ne ''; $ctx->release; } AnyEvent-WebSocket-Client-0.55/t/anyevent_websocket_client.t000644 000000 000000 00000021667 14424756453 024171 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Plugin::EV; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use Test2::Tools::WebSocket::Server qw( start_server start_echo ); use AnyEvent::WebSocket::Client; subtest 'new' => sub { my $client = AnyEvent::WebSocket::Client->new; isa_ok $client, 'AnyEvent::WebSocket::Client'; }; subtest 'tests against count server' => sub { my $counter; my $max; my $last_handshake; my $uri = start_server( customize_server_response => sub { my($handshake) = @_; if($handshake->req->subprotocol) { note "sub protocols requested: @{[ $handshake->req->subprotocol ]}"; my %sb = map { $_ => 1 } split(/,/, $handshake->req->subprotocol); if($sb{bar}) { $handshake->res->subprotocol('bar'); } if($sb{klingon}) { $handshake->res->subprotocol('romulan'); } } }, handshake => sub { # handshake my $opt = { @_ }; $counter = 1; $max = 15; note "max = $max"; $last_handshake = $opt->{handshake}; #note $opt->{handshake}->req->to_string; #note $opt->{handshake}->to_string; note "resource = " . $opt->{handshake}->req->resource_name; note "version = " . $opt->{handshake}->version; if($opt->{handshake}->req->resource_name =~ /\/count\/(\d+)/) { $max = $1 } note "max = $max"; }, message => sub { # message my $opt = { @_ }; eval q{ note "send $counter"; $opt->{hdl}->push_write($opt->{frame}->new($counter++)->to_bytes); if($counter >= $max) { $opt->{hdl}->push_write($opt->{frame}->new(type => 'close')->to_bytes); $opt->{hdl}->push_shutdown; } }; }, ); $uri->path('/count/10'); note $uri; subtest basic => sub { my $connection = AnyEvent::WebSocket::Client->new->connect($uri)->recv; isa_ok $connection, 'AnyEvent::WebSocket::Connection'; my $done = AnyEvent->condvar; $connection->send('ping'); my $last; $connection->on(each_message => sub { my $message = $_[1]->body; note "recv $message"; $connection->send('ping'); $last = $message; }); $connection->on(finish => sub { $done->send(1); }); is $done->recv, '1', 'friendly disconnect'; is $last, 9, 'last = 9'; }; subtest 'override' => sub { subtest 'host' => sub { my $uri = $uri->clone; my $host = $uri->host; $uri->host('bogus.test'); my @args = ($uri, $host); note "args=$_" for @args; my $connection = eval { AnyEvent::WebSocket::Client->new->connect(@args)->recv }; is $@, '', 'connect okay'; }; subtest 'port' => sub { my $uri = $uri->clone; my $port = $uri->port; $uri->port($port+1); my @args = ($uri, undef, $port); note "args=$_" for map { defined $_ ? $_ : 'undef' } @args; my $connection = eval { AnyEvent::WebSocket::Client->new->connect(@args)->recv }; is $@, '', 'connect okay'; }; subtest 'port' => sub { my $uri = $uri->clone; my $host = $uri->host; my $port = $uri->port; $uri->host("bogus.test"); $uri->port($port+1); my @args = ($uri, $host, $port); note "args=$_" for @args; my $connection = eval { AnyEvent::WebSocket::Client->new->connect(@args)->recv }; is $@, '', 'connect okay'; }; }; subtest 'version' => sub { my $connection = AnyEvent::WebSocket::Client->new( protocol_version => 'draft-ietf-hybi-10', )->connect($uri)->recv; is $last_handshake->version, 'draft-ietf-hybi-10', 'server side protool_version = draft-ietf-hybi-10'; }; subtest 'subprotocol' => sub { is( AnyEvent::WebSocket::Client->new( subprotocol => ['foo','bar','baz'] )->subprotocol, ['foo','bar','baz'], ); is( AnyEvent::WebSocket::Client->new( subprotocol => ['foo'] )->subprotocol, ['foo'], ); is( AnyEvent::WebSocket::Client->new( subprotocol => 'foo' )->subprotocol, ['foo'], ); my $connection = AnyEvent::WebSocket::Client->new(subprotocol => ['foo','bar','baz'])->connect($uri)->recv; is($last_handshake->res->subprotocol, 'bar', 'server agreed to bar'); is($connection->subprotocol, 'bar', 'connection also has bar'); eval { AnyEvent::WebSocket::Client->new(subprotocol => ['foo','baz'])->connect($uri)->recv }; my $error = $@; like $error, qr{no subprotocol in response}, 'bad protocol throws an exception'; eval { AnyEvent::WebSocket::Client->new(subprotocol => ['klingon','cardasian'])->connect($uri)->recv }; $error = $@; like $error, qr{subprotocol mismatch, requested: klingon, cardasian, got: romulan}, 'bad protocol throws an exception'; }; subtest http_headers => sub { is( AnyEvent::WebSocket::Client->new( http_headers => { 'X-Foo' => 'bar', 'X-Baz' => [ 'abc', 'def' ] } )->http_headers, [ 'X-Baz' => 'abc', 'X-Baz' => 'def', 'X-Foo' => 'bar', ] ); my $client = AnyEvent::WebSocket::Client->new( http_headers => [ 'X-Foo' => 'bar', 'X-Baz' => 'abc', 'X-Baz' => 'def' ] ); is( $client->http_headers, [ 'X-Foo' => 'bar', 'X-Baz' => 'abc', 'X-Baz' => 'def', ] ); # Note: Protocol::WebSocket does not currently support headers with multiple instances of the same # key, so we just won't test that. $client = AnyEvent::WebSocket::Client->new( http_headers => [ 'X-Foo' => 'bar', 'X-Baz' => 'abc' ] ); my $connection = $client->connect($uri)->recv; is($last_handshake->req->fields->{'x-foo'}, 'bar'); is($last_handshake->req->fields->{'x-baz'}, 'abc'); }; }; subtest 'Client Connection should set masked => true' => sub { my $uri = start_echo; my $connection = AnyEvent::WebSocket::Client->new()->connect($uri)->recv; ok $connection->masked, "Client Connection should set masked => true"; }; subtest 'payload size' => sub { my $uri = start_echo; my $client = AnyEvent::WebSocket::Client->new( max_payload_size => 65538 ); subtest 'connection gets same max_payload_size as client' => sub { my $connection = $client->connect($uri)->recv; is $connection->max_payload_size, 65538; }; subtest 'send message > 65536' => sub { my $data = 'x' x 65537; my $connection = $client->connect($uri)->recv; my $cv = AE::cv; $connection->on(next_message => sub { my($connection, $message) = @_; is $message->body, $data; $cv->send; }); eval { $connection->send($data) }; is $@, ''; $cv->recv; }; # test the double standard that we can send any sized # frame, but will not accept large ones. subtest 'receive message > max_payload_size' => sub { my $data = 'x' x 65540; my $connection = $client->connect($uri)->recv; my $cv = AE::cv; $connection->on(parse_error => sub { my($connection, $error) = @_; isnt $error, '', "Error is: $error"; $cv->send; }); eval { $connection->send($data) }; is $@, ''; $cv->recv; }; }; subtest 'client connection should receive the initial message sent from server' => sub { my $url = start_server( handshake => sub { my $opt = { @_ }; $opt->{hdl}->push_write(Protocol::WebSocket::Frame->new("initial message from server")->to_bytes); }, message => sub { my $opt = { @_ }; $opt->{hdl}->push_shutdown; }, ); my $conn = AnyEvent::WebSocket::Client->new->connect($url)->recv; my $cv_finish = AnyEvent->condvar; my @received_messages = (); $conn->on(each_message => sub { my ($conn, $message) = @_; push(@received_messages, $message->body); $conn->send("finish"); }); $conn->on(finish => sub { $cv_finish->send(); }); $cv_finish->recv; is(\@received_messages, ["initial message from server"]); }; subtest 'callbacks can be unregistered' => sub { my $url = start_server( handshake => sub { my $opt = { @_ }; $opt->{hdl}->push_write(Protocol::WebSocket::Frame->new("initial message from server")->to_bytes) for 1..10; }, message => sub { my $opt = { @_ }; $opt->{hdl}->push_shutdown; }, ); my $conn = AnyEvent::WebSocket::Client->new->connect($url)->recv; my $cv_finish = AnyEvent->condvar; my @received_messages = (); my @counters = (0,0); # using the returned callback my $cancel; $cancel = $conn->on( each_message => sub { $cancel->() if 2 == ++$counters[0]; }); # # using the provided coderef $conn->on( each_message => sub { $_[2]->() if 2 == ++$counters[1]; }); my $countdown = 10; $conn->on(each_message => sub { my ($conn, $message) = @_; push(@received_messages, $message->body); $conn->send("finish") unless --$countdown; }); $conn->on(finish => sub { $cv_finish->send(); }); $cv_finish->recv; is(\@received_messages, [("initial message from server")x10]); is(\@counters, [2,2], "callbacks got unregistered after second message"); }; done_testing; AnyEvent-WebSocket-Client-0.55/t/anyevent_websocket_client__proxy.t000644 000000 000000 00000004252 14424756453 025560 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use AnyEvent; use AnyEvent::WebSocket::Client; sub get_env { my ($env_name, $desc) = @_; my $val = $ENV{$env_name}; if(!defined($val) || $val eq "") { skip_all "Set $env_name environment variable to $desc to enable this test."; } return $val; } sub test_client_at { my ($client, $echo_url, $exp_conn_success) = @_; my $conn = eval { $client->connect($echo_url)->recv }; my $err = $@; if(!$exp_conn_success) { is $conn, undef; like $err, qr/unable to connect/i; return; } isnt $conn, undef; is $err, ''; my $res_cv = AnyEvent->condvar; $conn->on(next_message => sub { $res_cv->send($_[1]->decoded_body); }); $conn->send("foo bar"); my $got = $res_cv->recv; is $got, "foo bar", $echo_url; } sub test_client { my ($client, $exp_conn_success) = @_; test_client_at($client, "ws://echo.websocket.org/", $exp_conn_success); test_client_at($client, "wss://echo.websocket.org/", $exp_conn_success); } my $PROXY_URL = get_env("PERL_AE_WS_C_TEST_PROXY_URL", "the proxy URL"); my $PROXY_ON = get_env("PERL_AE_WS_C_TEST_PROXY_ON", "0 (if the proxy is down) or 1 (if the proxy is up)"); note(<<'NOTE'); squid HTTP proxy denies connection to ports other than 443 (HTTPS) by default. In this case, this test fails. To pass the test, you have to configure squid.conf to allow connection to 80 (HTTP) and 443. For example, ## http_access deny !Safe_ports http_access allow CONNECT Safe_ports NOTE foreach my $n (qw(ws http wss https)) { my $e = "${n}_proxy"; delete $ENV{lc($e)}; delete $ENV{uc($e)}; } subtest "no proxy", sub { test_client(AnyEvent::WebSocket::Client->new(), 1); }; subtest "ws and wss proxy", sub { local $ENV{ws_proxy} = $PROXY_URL; local $ENV{wss_proxy} = $PROXY_URL; test_client(AnyEvent::WebSocket::Client->new(env_proxy => 1), $PROXY_ON); }; subtest "http and https proxy", sub { local $ENV{http_proxy} = $PROXY_URL; local $ENV{https_proxy} = $PROXY_URL; test_client(AnyEvent::WebSocket::Client->new(env_proxy => 1), $PROXY_ON); }; done_testing; AnyEvent-WebSocket-Client-0.55/t/anyevent_websocket_client__scope.t000644 000000 000000 00000002452 14424756453 025510 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Require::Module 'Capture::Tiny'; use Test2::Require::Module 'Test::Memory::Cycle'; use Test2::Require::Module 'Devel::Cycle'; use Test2::Plugin::EV; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use Test2::Tools::WebSocket::Server qw( start_server ); use AnyEvent::WebSocket::Client; use Capture::Tiny qw( capture_stderr ); use Test::Memory::Cycle; my $finished = 0; my $done1 = AnyEvent->condvar; my $done2 = AnyEvent->condvar; my $uri = start_server( message => sub { my $opt = { @_ }; return if !$opt->{frame}->is_text && !$opt->{frame}->is_binary; $opt->{hdl}->push_write($opt->{frame}->new(buffer => $opt->{message}, max_payload_size => 0 )->to_bytes); }, end => sub { $finished = 1; $done1->send; }, ); my $client = AnyEvent::WebSocket::Client->new; my $connection = $client->connect($uri)->recv; $connection->on(each_message => sub { $done2->send }); isa_ok $connection, 'AnyEvent::WebSocket::Connection'; is $finished, 0, 'finished = 0'; $connection->send('foo'); is $finished, 0, 'finished = 0'; note capture_stderr { memory_cycle_ok $connection }; $done2->recv; $connection->close; note capture_stderr { memory_cycle_ok $connection }; undef $connection; $done1->recv; is $finished, 1, 'finished = 1'; done_testing; AnyEvent-WebSocket-Client-0.55/t/anyevent_websocket_client__server_initial_data_shutdown.t000644 000000 000000 00000010731 14424756453 032341 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Require::SSL (); use Test2::Plugin::EV; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use Test2::Tools::WebSocket::Server qw( start_server ); use AnyEvent::WebSocket::Client; my @test_cases = ( { label => 'without TLS', tls => 0, }, { label => 'with TLS', tls => 1, tls_cert => do { local $/; } }, ); foreach my $test_case (@test_cases) { subtest $test_case->{label}, sub { if($test_case->{tls}) { my $reason = Test2::Require::SSL->skip; skip_all $reason if $reason; } my %server_args = ( handshake => sub { my $opt = { @_ }; $opt->{hdl}->push_write(Protocol::WebSocket::Frame->new("initial message from server")->to_bytes); $opt->{hdl}->push_shutdown(); }, message => sub { fail("server should not receive a message"); }, ); if($test_case->{tls}) { $server_args{tls} = AnyEvent::TLS->new(cert => $test_case->{tls_cert}); } my $url = start_server(%server_args); my $cv_finish = AnyEvent->condvar; my $conn = eval { AnyEvent::WebSocket::Client->new(ssl_no_verify => 1)->connect($url)->recv }; if($@) { my $error = $@; die $error; } my @received_messages = (); $conn->on(each_message => sub { my ($conn, $message) = @_; push(@received_messages, $message->body); }); $conn->on(finish => sub { $cv_finish->send; }); $cv_finish->recv; is( \@received_messages, ["initial message from server"], "client should receive the initial message sent from the server, even if the server immediately shuts down." ); }; } done_testing; __DATA__ -----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEA02VwAqlQzCrPenkxUjawHcXzJreJ9LDhX7Bkg3E/RB6Ilm4D LBeilCmzkY7avp57+WCiVw2qkg+kH4Ef2sd+r10UCGPh/1diLehRAzp3Ho1bixyg w+zkDm79OnN3uHxuKigkAxx3GGz9HhQA83U+RUns+39/OnFh0RY6/f5rV2ziA9jD 6HK3Mnsuxocd46YbVdiqlQK430CgiGj8dV44JG6+R6x3r5qXDbbRtGubC29kQOUq kYslbpTo7ml8ShyqAP6qa8BpeSIaNG1CQQ/7JkAdxSWyFHqMQ0HR3BUiaEfUElZt DFgXcCkKB5F8jx+wYoLzlPHHZaUvfP2nueYjcwIDAQABAoIBAQCtRDMuu0ByV5R/ Od5nGFP500mcrkrwuBnBqH56DdRhLPWe9sS62xRyhEuePoykOJo8qCvnVlg8J33K JLfLRkBb09qbleKiuyjJn+Tm1IDWFd62gtxyOjQicG41/nZeS/6vpv79XdNvvcUp ZhPxeGN1v0XyTWomqNAX5DSuAl5Q5HxkaRYNeuLZaPYkqmEVTgYqNSes/wRLKUb6 MaVrZ9AA/oHJMmmV4evf06s7l7ICjxAWeas7CI6UGkEz8ZFoVRJsLk5xtTsnZLgf f24/pqHz1vApPs7CsJhK2HsLZcxMPD+hmTNI/Njl51WoH8zGhkv+p88vDzybpNSF Hpkl+ZlBAoGBAOyfjVLD0OznJKSFksoCZKS4dlPHgXUb47Qb/XchIySQ/DNO6ff9 AA6r6doDFp51A8N1GRtGQN4LKujFPOdZ5ah7zbc2PfuOJGHku0Oby+ydgHJ19eW4 s3CIM20TuzLndFPrEGFgOrt+i5qKisti2OOZhjsDwfd48vsBm9U20lUpAoGBAOS1 Chm+vA7JevPzl+acbDSiyELaNRAXZ73CX4NIxJURjsgDeOurnBtLQEQyagZbNHcx W4pc59Ql5KDLzu/Sne8oC3pxhaWeIPhc2d3cd/8UyGtQLtN2QnilwkjHgi3x1JGb RPRsgAV6nwn10qUrze1XLkHsTCRI4QYD/k0uXcs7AoGBAMStJaFag2i2Ax4ArG7e KFtFu4yNckwtv0kwTrBbScOWAxp+iDiJASgwunJsSLuylUs8JH8oGLi23ZaWgrXl Yd918BpNqp1Rm2oG3aQndguZKm95Hscvi26Itv39/YYlHeq2omndu1OmrlDowM6m vZIIRKr+x5Vz4brCro09QPxpAoGARJAdghBTEl/Gc2HgdOsJ6VGvlZMS+0r498NQ nOvwuvuzgTTBSG1+9BPAJXGzpUosVVs/pSArA8eEXcwbsnvCixLHNiLYPQlFuw8i 5UcV1iul1b4I+63lSYPv1Z+x4BIydqBEsL3iN0JGcVb3mjqilndfT7YGMY6DnykN UJgI2EcCgYAMfZHnD06XFM8ny+NsFILItpGqjCmAhkEPGwl1Zhy5Hx16CFDPDwGt CmIbxNSLsDyiiK+i5tuSUFhV2Bw/iT539979INTIdNL1ughfhATR8MVNiOKCvZBa uoEeE19szmG7Mj2eV2IDH0e8iaikjRFcfN89s39tNn1AjBNmEccUJA== -----END RSA PRIVATE KEY----- ----- -----BEGIN CERTIFICATE----- MIIDHTCCAgWgAwIBAgIJAPASTbY2HCx0MA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV BAMTCEFueUV2ZW50MB4XDTEyMDQwNTA1NTk1MFoXDTM3MDQwNTA1NTk1MFowEzER MA8GA1UEAxMIQW55RXZlbnQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB AQDTZXACqVDMKs96eTFSNrAdxfMmt4n0sOFfsGSDcT9EHoiWbgMsF6KUKbORjtq+ nnv5YKJXDaqSD6QfgR/ax36vXRQIY+H/V2It6FEDOncejVuLHKDD7OQObv06c3e4 fG4qKCQDHHcYbP0eFADzdT5FSez7f386cWHRFjr9/mtXbOID2MPocrcyey7Ghx3j phtV2KqVArjfQKCIaPx1Xjgkbr5HrHevmpcNttG0a5sLb2RA5SqRiyVulOjuaXxK HKoA/qprwGl5Iho0bUJBD/smQB3FJbIUeoxDQdHcFSJoR9QSVm0MWBdwKQoHkXyP H7BigvOU8cdlpS98/ae55iNzAgMBAAGjdDByMB0GA1UdDgQWBBTHphJ9Il0PtIWD DI9aueToXo9DYzBDBgNVHSMEPDA6gBTHphJ9Il0PtIWDDI9aueToXo9DY6EXpBUw EzERMA8GA1UEAxMIQW55RXZlbnSCCQDwEk22NhwsdDAMBgNVHRMEBTADAQH/MA0G CSqGSIb3DQEBBQUAA4IBAQA/vY+qg2xjNeOuDySW/VOsStEwcaiAm/t24z3TYoZG 2ZzyKuvFXolhXsalCahNPcyUxZqDAekODPRaq+geFaZrOn41cq/LABTKv5Theukv H7IruIFARBo1pTPFCKMnDqESBdHvV1xTOcKGxGH5I9iMgiUrd/NnlAaloT/cCNFI OwhEPsF9kBsZwJBGWrjjVttU2lzMzizS7vaSIWLBuEDObWbSXiU+IdG+nODOe2Dv W7PL43yd4fz4HQvN4IaZrtwkd7XiKodRR1gWjLjW/3y5kuXL+DA/jkTjrRgiH8K7 lVjm7gvkULRV2POQqtc2DUVXLubQmmGSjmQmxSwFX65t -----END CERTIFICATE----- AnyEvent-WebSocket-Client-0.55/t/anyevent_websocket_client__ssl.t000644 000000 000000 00000010441 14424756453 025175 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Require::SSL; use Test2::Plugin::EV; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use Test2::Tools::WebSocket::Server qw( start_server ); use AnyEvent::WebSocket::Client; my $counter; my $max; my $uri = start_server( tls => AnyEvent::TLS->new(cert => do { local $/; }), handshake => sub { # handshake my $opt = { @_ }; $counter = 1; $max = 15; note "max = $max"; note "resource = " . $opt->{handshake}->req->resource_name; if($opt->{handshake}->req->resource_name =~ /\/count\/(\d+)/) { $max = $1 } note "max = $max"; }, message => sub { # message my $opt = { @_ }; eval q{ note "send $counter"; $opt->{hdl}->push_write($opt->{frame}->new($counter++)->to_bytes); if($counter >= $max) { $opt->{hdl}->push_write($opt->{frame}->new(type => 'close')->to_bytes); $opt->{hdl}->push_shutdown; } }; }, ); $uri->path('/count/10'); note $uri; my $connection = eval { AnyEvent::WebSocket::Client->new( ssl_no_verify => 1 )->connect($uri)->recv }; if(my $error = $@) { die $error; } isa_ok $connection, 'AnyEvent::WebSocket::Connection'; my $done = AnyEvent->condvar; $connection->send('ping'); my $last; $connection->on(each_message => sub { my $message = $_[1]->body; note "recv $message"; $connection->send('ping'); $last = $message; }); $connection->on(finish => sub { $done->send(1); }); is $done->recv, '1', 'friendly disconnect'; is $last, 9, 'last = 9'; done_testing; __DATA__ -----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEA02VwAqlQzCrPenkxUjawHcXzJreJ9LDhX7Bkg3E/RB6Ilm4D LBeilCmzkY7avp57+WCiVw2qkg+kH4Ef2sd+r10UCGPh/1diLehRAzp3Ho1bixyg w+zkDm79OnN3uHxuKigkAxx3GGz9HhQA83U+RUns+39/OnFh0RY6/f5rV2ziA9jD 6HK3Mnsuxocd46YbVdiqlQK430CgiGj8dV44JG6+R6x3r5qXDbbRtGubC29kQOUq kYslbpTo7ml8ShyqAP6qa8BpeSIaNG1CQQ/7JkAdxSWyFHqMQ0HR3BUiaEfUElZt DFgXcCkKB5F8jx+wYoLzlPHHZaUvfP2nueYjcwIDAQABAoIBAQCtRDMuu0ByV5R/ Od5nGFP500mcrkrwuBnBqH56DdRhLPWe9sS62xRyhEuePoykOJo8qCvnVlg8J33K JLfLRkBb09qbleKiuyjJn+Tm1IDWFd62gtxyOjQicG41/nZeS/6vpv79XdNvvcUp ZhPxeGN1v0XyTWomqNAX5DSuAl5Q5HxkaRYNeuLZaPYkqmEVTgYqNSes/wRLKUb6 MaVrZ9AA/oHJMmmV4evf06s7l7ICjxAWeas7CI6UGkEz8ZFoVRJsLk5xtTsnZLgf f24/pqHz1vApPs7CsJhK2HsLZcxMPD+hmTNI/Njl51WoH8zGhkv+p88vDzybpNSF Hpkl+ZlBAoGBAOyfjVLD0OznJKSFksoCZKS4dlPHgXUb47Qb/XchIySQ/DNO6ff9 AA6r6doDFp51A8N1GRtGQN4LKujFPOdZ5ah7zbc2PfuOJGHku0Oby+ydgHJ19eW4 s3CIM20TuzLndFPrEGFgOrt+i5qKisti2OOZhjsDwfd48vsBm9U20lUpAoGBAOS1 Chm+vA7JevPzl+acbDSiyELaNRAXZ73CX4NIxJURjsgDeOurnBtLQEQyagZbNHcx W4pc59Ql5KDLzu/Sne8oC3pxhaWeIPhc2d3cd/8UyGtQLtN2QnilwkjHgi3x1JGb RPRsgAV6nwn10qUrze1XLkHsTCRI4QYD/k0uXcs7AoGBAMStJaFag2i2Ax4ArG7e KFtFu4yNckwtv0kwTrBbScOWAxp+iDiJASgwunJsSLuylUs8JH8oGLi23ZaWgrXl Yd918BpNqp1Rm2oG3aQndguZKm95Hscvi26Itv39/YYlHeq2omndu1OmrlDowM6m vZIIRKr+x5Vz4brCro09QPxpAoGARJAdghBTEl/Gc2HgdOsJ6VGvlZMS+0r498NQ nOvwuvuzgTTBSG1+9BPAJXGzpUosVVs/pSArA8eEXcwbsnvCixLHNiLYPQlFuw8i 5UcV1iul1b4I+63lSYPv1Z+x4BIydqBEsL3iN0JGcVb3mjqilndfT7YGMY6DnykN UJgI2EcCgYAMfZHnD06XFM8ny+NsFILItpGqjCmAhkEPGwl1Zhy5Hx16CFDPDwGt CmIbxNSLsDyiiK+i5tuSUFhV2Bw/iT539979INTIdNL1ughfhATR8MVNiOKCvZBa uoEeE19szmG7Mj2eV2IDH0e8iaikjRFcfN89s39tNn1AjBNmEccUJA== -----END RSA PRIVATE KEY----- ----- -----BEGIN CERTIFICATE----- MIIDHTCCAgWgAwIBAgIJAPASTbY2HCx0MA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV BAMTCEFueUV2ZW50MB4XDTEyMDQwNTA1NTk1MFoXDTM3MDQwNTA1NTk1MFowEzER MA8GA1UEAxMIQW55RXZlbnQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB AQDTZXACqVDMKs96eTFSNrAdxfMmt4n0sOFfsGSDcT9EHoiWbgMsF6KUKbORjtq+ nnv5YKJXDaqSD6QfgR/ax36vXRQIY+H/V2It6FEDOncejVuLHKDD7OQObv06c3e4 fG4qKCQDHHcYbP0eFADzdT5FSez7f386cWHRFjr9/mtXbOID2MPocrcyey7Ghx3j phtV2KqVArjfQKCIaPx1Xjgkbr5HrHevmpcNttG0a5sLb2RA5SqRiyVulOjuaXxK HKoA/qprwGl5Iho0bUJBD/smQB3FJbIUeoxDQdHcFSJoR9QSVm0MWBdwKQoHkXyP H7BigvOU8cdlpS98/ae55iNzAgMBAAGjdDByMB0GA1UdDgQWBBTHphJ9Il0PtIWD DI9aueToXo9DYzBDBgNVHSMEPDA6gBTHphJ9Il0PtIWDDI9aueToXo9DY6EXpBUw EzERMA8GA1UEAxMIQW55RXZlbnSCCQDwEk22NhwsdDAMBgNVHRMEBTADAQH/MA0G CSqGSIb3DQEBBQUAA4IBAQA/vY+qg2xjNeOuDySW/VOsStEwcaiAm/t24z3TYoZG 2ZzyKuvFXolhXsalCahNPcyUxZqDAekODPRaq+geFaZrOn41cq/LABTKv5Theukv H7IruIFARBo1pTPFCKMnDqESBdHvV1xTOcKGxGH5I9iMgiUrd/NnlAaloT/cCNFI OwhEPsF9kBsZwJBGWrjjVttU2lzMzizS7vaSIWLBuEDObWbSXiU+IdG+nODOe2Dv W7PL43yd4fz4HQvN4IaZrtwkd7XiKodRR1gWjLjW/3y5kuXL+DA/jkTjrRgiH8K7 lVjm7gvkULRV2POQqtc2DUVXLubQmmGSjmQmxSwFX65t -----END CERTIFICATE----- AnyEvent-WebSocket-Client-0.55/t/anyevent_websocket_connection.t000644 000000 000000 00000032157 14424756453 025046 0ustar00rootroot000000 000000 use utf8; use lib 't/lib'; use Test2::Plugin::EV; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use Test2::Tools::WebSocket::Connection qw( create_connection_pair create_connection_and_handle ); use AnyEvent::WebSocket::Connection; subtest 'send' => sub { my($x,$y) = create_connection_pair; my $round_trip = sub { my($message) = @_; my $done = AnyEvent->condvar; $y->on(next_message => sub { my(undef, $message) = @_; $done->send($message); }); $x->send($message); $done->recv; }; subtest 'string' => sub { is( $round_trip->('hello world'), object { call body => 'hello world'; }, ); }; require AnyEvent::WebSocket::Message; subtest 'message object' => sub { is( $round_trip->(AnyEvent::WebSocket::Message->new( body => 'And another one', )), object { call body => 'And another one'; }, ); }; subtest 'is_text' => sub { is( $round_trip->(AnyEvent::WebSocket::Message->new( opcode => 1, body => 'xx', )), object { call body => 'xx'; call is_text => T(); call is_binary => F(); }, ); }; subtest 'is_binary' => sub { is( $round_trip->(AnyEvent::WebSocket::Message->new( opcode => 2, body => 'yy', )), object { call body => 'yy'; call is_text => F(); call is_binary => T(); }, ); }; subtest 'ping' => sub { skip_all 'no pong callback... yet'; $x->send( AnyEvent::WebSocket::Message->new( opcode => 9, body => 'zz', ) ); }; { my @test_data = ( {label => "single character", data => "a"}, {label => "5k bytes", data => "a" x 5000}, {label => "empty", data => ""}, {label => "0", data => 0}, {label => "utf8 charaters", data => 'UTF8 WIDE CHARACTERS'}, ); foreach my $case (@test_data) { subtest $case->{label} => sub { is( $round_trip->($case->{data}), object { call decoded_body => $case->{data}; }, 'string' ); is( $round_trip->(AnyEvent::WebSocket::Message->new(body => $case->{data})), object { call decoded_body => $case->{data}; }, 'object' ); }; } } subtest 'close' => sub { my $done = AnyEvent->condvar; $y->on(finish => sub { $done->send; }); $x->send( AnyEvent::WebSocket::Message->new( opcode => 8, body => pack('naa', 1005, 'b','b'), ), ); $done->recv; is( $y, object { call close_code => 1005; call close_reason => 'bb'; }, ); }; }; subtest 'masked attribute should control whether the frames sent by the Connection are masked or not' => sub { foreach my $masked (0,1) { subtest "masked = $masked" => sub { my ($x_conn, $y_handle) = create_connection_and_handle({masked => $masked}); my $cv_finish = AnyEvent->condvar; $y_handle->on_read(sub { my ($handle) = @_; return if length($handle->{rbuf}) < 2; is substr($handle->{rbuf}, 0, 2), pack("C*", 0x81, ($masked ? 0x85 : 0x05)), "frame header OK"; $cv_finish->send; }); $x_conn->send("Hello"); $cv_finish->recv; }; } }; subtest 'Connection should respond to a ping frame with a pong frame' => sub { my ($x_conn, $y_handle) = create_connection_and_handle; my $parser = Protocol::WebSocket::Frame->new; my $cv_finish = AnyEvent->condvar; $y_handle->on_read(sub { my ($handle) = @_; $parser->append($handle->{rbuf}); my $payload = $parser->next_bytes; return if !defined($payload); is $parser->opcode, 10, "pong frame received"; is $payload, "foobar", "... payload is identical to what b_handle has sent."; $cv_finish->send; }); $y_handle->push_write(Protocol::WebSocket::Frame->new(type => "ping", buffer => "foobar")->to_bytes); $cv_finish->recv; }; subtest 'connection close data' => sub { subtest 'ascii' => sub { my($x, $y) = create_connection_pair; my $cv = AnyEvent->condvar; my $reason; my $code; $y->on(finish => sub { my($con) = @_; $code = $con->close_code; $reason = $con->close_reason; $cv->send; }); $x->close(1009 => 'anything'); $cv->recv; is $code, 1009, 'code is available in finish callback'; is $reason, 'anything', 'reason is available in finish callback'; is( $y, object { call close_code => 1009; call close_reason => 'anything'; }, 'connection has finish code and reason', ); }; subtest 'unicode' => sub { my($x, $y) = create_connection_pair; my $cv = AnyEvent->condvar; my $reason; my $code; $y->on(finish => sub { my($con) = @_; $code = $con->close_code; $reason = $con->close_reason; $cv->send; }); $x->close(1009 => 'UTF8 WIDE CHARACTERS'); $cv->recv; is $code, 1009, 'code is available in finish callback'; is $reason, 'UTF8 WIDE CHARACTERS', 'reason is available in finish callback'; is( $y, object { call close_code => 1009; call close_reason => 'UTF8 WIDE CHARACTERS'; }, 'connection has finish code and reason', ); }; }; subtest 'Connection should not send after sending close frame, should not receive after receiving close frame' => sub { subtest "it should not send after sending close frame", sub { my ($x_conn, $y_handle) = create_connection_and_handle; my $y_received; my $cv_finish = AnyEvent->condvar; $cv_finish->begin; $cv_finish->begin; $y_handle->on_read(sub { }); $y_handle->on_error(sub { $y_received = $_[0]->{rbuf}; $_[0]->{rbuf} = ""; $cv_finish->end; }); $x_conn->on(finish => sub { $cv_finish->end; }); $x_conn->close(); $x_conn->send("hoge"); $cv_finish->recv; my $parser = Protocol::WebSocket::Frame->new(); $parser->append($y_received); ok defined($parser->next_bytes), "received a complete frame"; ok $parser->is_close, "... and it's a close frame"; ok !defined($parser->next_bytes), "no more frame"; }; my $make_frame = sub { Protocol::WebSocket::Frame->new(@_)->to_bytes; }; subtest "it should not receive after receiving close frame", sub { my ($x_conn, $y_handle) = create_connection_and_handle; my @received_messages = (); my $cv_finish = AnyEvent->condvar; $x_conn->on(each_message => sub { push(@received_messages, $_[1]) }); $x_conn->on(finish => sub { $cv_finish->send }); $y_handle->push_write($make_frame->(type => "close")); $y_handle->push_write($make_frame->(buffer => "hoge")); $y_handle->push_shutdown; $cv_finish->recv; is scalar(@received_messages), 0, "the message 'hoge' should be discarded" or diag($received_messages[0]->body); }; }; subtest 'Connection should respond with close frame to close frame' => sub { my ($x_conn, $y_handle) = create_connection_and_handle; my $cv_b_recv = AnyEvent->condvar; $y_handle->on_error(sub { my $h = shift; $cv_b_recv->send($h->{rbuf}); $h->{rbuf} = ""; }); $y_handle->on_read(sub {}); $y_handle->push_write(Protocol::WebSocket::Frame->new(buffer => "", type => "close")->to_bytes); my $y_recv = $cv_b_recv->recv; my $parser = Protocol::WebSocket::Frame->new; $parser->append($y_recv); ok defined($parser->next_bytes), "received a complete frame"; ok $parser->is_close, "... and it's a close frame"; }; subtest 'Connection should refuse extremely huge messages' => sub { subtest "Connection should refuse huge frames", sub { my ($x_conn, $y_handle) = create_connection_and_handle(); my $cv_finish = AnyEvent->condvar; $cv_finish->begin; $cv_finish->begin; my @received_messages = (); $x_conn->on(finish => sub { $cv_finish->end; }); $x_conn->on(each_message => sub { push(@received_messages, $_[1]); }); $y_handle->on_error(sub { my $handle = shift; $handle->push_shutdown; $cv_finish->end; }); $y_handle->on_read(sub { }); my $frame_header = pack("H*", "827f00000000ffffffff"); # frame payload size = 2**32 - 1 bytes my $MAX_SEND_PAYLOAD = 1024; # for safety my $count_send_payload = 0; $y_handle->push_write($frame_header); $y_handle->on_drain(sub { my $handle = shift; $count_send_payload++; if($count_send_payload >= $MAX_SEND_PAYLOAD) { fail("Connection should be aborted by now."); $handle->on_drain(undef); $handle->push_shutdown; $cv_finish->send; return; } # push_write is delayed to prevent deep-recursion and to give # $x_conn chance to receive data. my $w; $w = AnyEvent->idle(cb => sub { undef $w; $handle->push_write("A" x 256); }); }); $cv_finish->recv; is scalar(@received_messages), 0, "the frame is too huge to receive."; }; subtest "Connection should refuse messages with too many fragments", sub { my ($x_conn, $y_handle) = create_connection_and_handle; my $cv_finish = AnyEvent->condvar; $cv_finish->begin; $cv_finish->begin; my @received_messages = (); $x_conn->on(finish => sub { $cv_finish->end; }); $x_conn->on(each_message => sub { push(@received_messages, $_[1]) }); $y_handle->on_error(sub { my $handle = shift; $handle->push_shutdown; $cv_finish->end; }); $y_handle->on_read(sub {}); my $MAX_SEND_FRAMES = 10000; my $count_send_frame = 0; $y_handle->push_write(Protocol::WebSocket::Frame->new(fin => 0, opcode => 1, buffer => "A")->to_bytes); $y_handle->on_drain(sub { my $handle = shift; $count_send_frame++; if($count_send_frame >= $MAX_SEND_FRAMES) { fail("Connection should be aborted by now."); $handle->on_drain(undef); $handle->push_shutdown; $cv_finish->send; return; } my $w; $w = AnyEvent->idle(cb => sub { undef $w; $handle->push_write(Protocol::WebSocket::Frame->new(fin => 0, opcode => 0, buffer => "A")->to_bytes); }); }); $cv_finish->recv; is scalar(@received_messages), 0, "the message consists of too many fragments to receive."; }; }; subtest 'other end is closed' => sub { my($x,$y) = create_connection_pair; my $round_trip = sub { my($message) = @_; my $done = AnyEvent->condvar; $y->on(next_message => sub { my(undef, $message) = @_; $done->send($message); }); $x->send($message); $done->recv; }; my $closed = 0; my $quit_cv = AnyEvent->condvar; $y->on(finish => sub { $closed = 1; $quit_cv->send("finished"); }); is( $round_trip->('a'), object { call decoded_body => 'a'; }, 'single character', ); is( $round_trip->('quit'), object { call decoded_body => 'quit'; }, 'quit', ); $x->close; $quit_cv->recv; is $closed, 1, "closed"; }; subtest 'close codes' => sub { my @test_data = ( [ [], [1000, ''], 'empty list defaults to 1005' ], [ [undef, undef], [1000, ''] , 'both undef' ], [ [undef, 'error'], [1000, 'error'] , 'undef code with explicit reason' ], [ [1003, undef], [1003, ''] , 'other code with undef reason' ], [ [1001], [1001, ''], 'normal close code' ], [ [1001, 'a reason'], [1001, 'a reason'], 'normal close code with reason' ], ); foreach my $test_data (@test_data) { my($xrgs, $expected, $label) = @$test_data; subtest $label => sub { my($x,$y) = create_connection_pair; my $done = AnyEvent->condvar; $y->on(finish => sub { $done->send }); $x->close(@$xrgs); $done->recv; is( $y, object { call close_code => $expected->[0]; call close_reason => $expected->[1]; }, ); }; } }; subtest 'next_message callback can be set from within a next_message callback' => sub { my($x,$y) = create_connection_pair; my($first_msg, $second_msg); my $round_trip = sub { my $done = AnyEvent->condvar; $y->on(next_message => sub { my(undef, $message) = @_; $first_msg = $message; $x->send('second'); $y->on(next_message => sub { my(undef, $message) = @_; $second_msg = $message; $done->send; }); }); $x->send('first'); $done->recv; }; my $quit_cv = AnyEvent->condvar; $y->on(finish => sub { $quit_cv->send; }); $round_trip->(); is( $first_msg, object { call decoded_body => 'first'; }, 'first message', ); is( $second_msg, object { call decoded_body => 'second'; }, 'second message', ); $x->close; $quit_cv->recv; }; done_testing; AnyEvent-WebSocket-Client-0.55/t/anyevent_websocket_connection__counter_shutdown.t000644 000000 000000 00000002463 14424756453 030674 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Plugin::EV; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use AnyEvent::WebSocket::Connection; use Test2::Tools::WebSocket::Connection qw( create_connection_and_handle ); note(<condvar; $cv_finish->begin; $cv_finish->begin; $a_conn->on(finish => sub { my(undef, $message) = @_; note "finish with message: $message" if $message; $cv_finish->end; }); $b_handle->on_read(sub {}); $b_handle->on_eof(sub { $cv_finish->end }); $code->($a_conn, $b_handle); $cv_finish->recv; pass "OK"; }; } test_case "on_eof of a_conn", sub { my ($a_conn, $b_handle) = @_; $b_handle->push_shutdown(); }; test_case "on_error of a_conn", sub { my ($a_conn, $b_handle) = @_; # force connection error on a_conn $a_conn->handle->push_shutdown; $a_conn->send("foo"); $a_conn->send("bar"); }; done_testing; AnyEvent-WebSocket-Client-0.55/t/anyevent_websocket_connection__destroy_in_callbacks.t000644 000000 000000 00000004741 14424756453 031441 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Plugin::EV; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use Test2::Tools::WebSocket::Connection qw( create_connection_pair ); use AnyEvent::WebSocket::Connection; use Scalar::Util qw(weaken); note("It should be safe (exception-free) to destroy the Connection object in callbacks."); sub test_case { my ($label, $a_conn_code, $b_conn_code) = @_; subtest $label, sub { my $b_conn; my $a_conn_weak; my $cv_finish = AnyEvent->condvar; $cv_finish->begin; $cv_finish->begin; { my $a_conn; ($a_conn, $b_conn) = create_connection_pair; $a_conn_weak = $a_conn; weaken($a_conn_weak); $a_conn_code->($a_conn, $cv_finish); } ok(defined($a_conn_weak), "a_conn is alive due to the cyclic ref in callback"); $b_conn->on(finish => sub { $cv_finish->end; }); $b_conn_code->($b_conn, $cv_finish); $cv_finish->recv; ok(!defined($a_conn_weak), "a_conn is now destroyed"); }; } test_case "destroy in 'finish' callback", sub { my ($a_conn, $cv_finish) = @_; $a_conn->on(finish => sub { undef $a_conn; # cyclic ref that breaks when executed. }); $a_conn->on(finish => sub { my ($conn) = @_; ok defined($conn), "conn is still alive in finish callback"; $cv_finish->end; }); }, sub { my ($b_conn) = @_; $b_conn->close; }; test_case "destroy in 'next_message' callback", sub { my ($a_conn, $cv_finish) = @_; $a_conn->on(next_message => sub { my ($conn, $msg) = @_; undef $a_conn; # cyclic ref that breaks when executed. is $msg->body, "foobar", "message OK (first callback)"; }); $a_conn->on(next_message => sub { my ($conn, $msg) = @_; is $msg->body, "foobar", "message OK (second callback)"; ok defined($conn), "conn is still alive in second next_message callback"; $cv_finish->end; }); }, sub { my ($b_conn) = @_; $b_conn->send("foobar"); }; test_case "destroy in 'each_message' callback", sub { my ($a_conn, $cv_finish) = @_; $a_conn->on(each_message => sub { my ($conn, $msg) = @_; undef $a_conn; # cyclic ref that breaks when executed. is $msg->body, "FOOBAR", "message OK (first callback)"; }); $a_conn->on(each_message => sub { my ($conn, $msg) = @_; is $msg->body, "FOOBAR", "message OK (second callback)"; ok defined($conn), "conn is still alive in second next_message callback"; $cv_finish->end; }); }, sub { my ($b_conn) = @_; $b_conn->send("FOOBAR"); }; done_testing; AnyEvent-WebSocket-Client-0.55/t/anyevent_websocket_connection__finish_callback.t000644 000000 000000 00000002524 14424756453 030354 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Plugin::EV; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use Test2::Tools::WebSocket::Connection qw( create_connection_pair ); use AnyEvent::WebSocket::Connection; note("finish callback should be called only once"); sub test_case { my ($label, $code) = @_; subtest $label, sub { my @conns = create_connection_pair; my $finish_count = 0; my $cv_finish = AnyEvent->condvar; $conns[0]->on(finish => sub { $finish_count++; $cv_finish->send }); $code->(\@conns); $cv_finish->recv; $conns[0]->send("hoge"); $conns[0]->send("foo"); $conns[0]->send("bar"); is $finish_count, 1; }; } test_case "delete conn 1", sub { my $conns = shift; undef $conns->[1]; }; test_case "close conn 1", sub { my $conns = shift; $conns->[1]->close(); }; test_case "close conn 0", sub { my $conns = shift; $conns->[0]->close(); }; test_case "recursively fire on_error event (in AE::Handle sense) while in on_eof handler", sub { my $conns = shift; $conns->[0]->on(finish => sub { # It is very rude and unusual to use the handle directly. We don't # have to support it, but it may happen. $conns->[0]->handle->push_shutdown; $conns->[0]->send("FOO"); # sending via a shutdown socket fires on_error ("Broken Pipe") }); undef $conns->[1]; }; done_testing; AnyEvent-WebSocket-Client-0.55/t/anyevent_websocket_connection__payload_size.t000644 000000 000000 00000004630 14424756453 027743 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Plugin::EV; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use Test2::Tools::WebSocket::Connection qw( create_connection_and_handle ); use AnyEvent::WebSocket::Connection; use AE; use AnyEvent::WebSocket::Connection; use Protocol::WebSocket::Frame; my $connection; { my @messages; my $message_cv = AE::cv; my $handle; ($connection, $handle) = create_connection_and_handle({ max_payload_size => 65538}); note "connection.max_payload_size = @{[ $connection->max_payload_size ]}"; my $frame = Protocol::WebSocket::Frame->new( max_payload_size => 0 ); $handle->on_read(sub { #my($handle) = @_; $frame->append($handle->{rbuf}); while(defined(my $body = $frame->next_bytes)) { push @messages, AnyEvent::WebSocket::Message->new( body => $body, opcode => $frame->opcode, ); $message_cv->send; } }); sub get_next_message { $message_cv->recv; $message_cv = AE::cv; shift @messages; } sub send_message { my($body,$cb) = @_; my $cv = AE::cv; if($cb) { $connection->on(next_message => sub { $cb->(@_); $cv->send; }); } my $frame = Protocol::WebSocket::Frame->new( max_payload_size => 0, buffer => $body, ); $handle->push_write($frame->to_bytes); $cv->recv if $cb; } } subtest 'send payload with size > 65536' => sub { my $data = 'x' x 65537; subtest 'plain string' => sub { eval { $connection->send($data) }; is $@, ''; my $rmessage = get_next_message(); ok $rmessage; is $rmessage->body, $data; }; subtest 'message object' => sub { my $smessage = AnyEvent::WebSocket::Message->new( body => $data, ); eval { $connection->send($smessage) }; is $@, ''; my $rmessage = get_next_message(); ok $rmessage; is $rmessage->body, $data; }; }; subtest 'receive payload with size > 65536' => sub { my $data = 'x' x 65537; send_message($data, sub { my($connection, $message) = @_; is $message->body, $data; }); }; subtest 'receieve payload with size > max_payload_size' => sub { my $data = 'x' x 65540; my $here = 1; my $cv = AE::cv; $connection->on(parse_error => sub { my($connection, $error) = @_; return unless $here; ok $error, "error is: $error"; $cv->send; }); send_message($data); $cv->recv; $here = 0; }; done_testing; AnyEvent-WebSocket-Client-0.55/t/anyevent_websocket_message.t000644 000000 000000 00000002075 14424756453 024327 0ustar00rootroot000000 000000 use Test2::V0 -no_srand => 1; use AnyEvent::WebSocket::Message; my %ops = qw( text 1 binary 2 close 8 ping 9 pong 10 ); my @methods = map { "is_$_" } keys %ops; foreach my $type (keys %ops) { my $opcode = $ops{$type}; subtest $type => sub { plan tests => 8; my $message = AnyEvent::WebSocket::Message->new(body => 'body', opcode => $opcode); is $message->body, 'body', 'message.body = body'; is $message->opcode, $opcode, "message.opcode = $opcode"; isa_ok $message, 'AnyEvent::WebSocket::Message'; foreach my $method (@methods) { next if $method eq "is_$type"; ok !$message->$method, "\$message->$method is false"; } my $method = "is_$type"; ok $message->$method, "\$message->$method is true"; }; } subtest default => sub { plan tests => 3; my $message = eval { AnyEvent::WebSocket::Message->new(body => 'foo') }; diag $@ if $@; isa_ok $message, 'AnyEvent::WebSocket::Message'; is $message->opcode, 1, 'message.opcode = 1'; ok $message->is_text, 'message.is_text is true'; }; done_testing; AnyEvent-WebSocket-Client-0.55/t/lib/000755 000000 000000 00000000000 14424756453 017301 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/t/lib/Test2/000755 000000 000000 00000000000 14424756453 020302 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Plugin/000755 000000 000000 00000000000 14424756453 021540 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Plugin/AnyEvent/000755 000000 000000 00000000000 14424756453 023271 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Plugin/AnyEvent/Timeout.pm000644 000000 000000 00000001753 14424756453 025263 0ustar00rootroot000000 000000 package Test2::Plugin::AnyEvent::Timeout; use strict; use warnings; use Test2::API qw( context ); use AnyEvent; our $timeout; # ABSTRACT: Set a timeout for tests that use AnyEvent # VERSION =head1 SYNOPSIS use Test2::V0; use Test2::Plugin::AnyEvent::Timeout; use AnyEvent; my $cv = AnyEvent->condvar; $cv->recv; =head1 DESCRIPTION Every now and then I used to get bug reports from cpantesters that my L based modules were getting stuck in an infinite loop. That is not a nice thing to do! So I woul rewrite the tests to add a timeout and cause the test to bailout if it ran for more than 30 seconds. This is a L plugin that does this without the boilerplate. =cut sub import { return if defined $timeout; $timeout = AnyEvent->timer( after => 30, cb => sub { my $ctx = context(); $ctx->bail("Test exceeded timeout of 30s"); $ctx->release; }, ); } 1; =head1 SEE ALSO =over4 =item L =item L =back =cut AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Plugin/EV.pm000644 000000 000000 00000000142 14424756453 022405 0ustar00rootroot000000 000000 package Test2::Plugin::EV; use strict; use warnings; eval q{ require EV; EV->import; }; 1; AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Require/000755 000000 000000 00000000000 14424756453 021716 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Require/NotWindows.pm000644 000000 000000 00000000265 14424756453 024372 0ustar00rootroot000000 000000 package Test2::Require::NotWindows; use strict; use warnings; use base qw( Test2::Require ); sub skip { return 'Test unreliable on windows' if $^O eq 'MSWin32'; return; } 1; AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Require/SSL.pm000644 000000 000000 00000000635 14424756453 022721 0ustar00rootroot000000 000000 package Test2::Require::SSL; use strict; use warnings; use Test2::API qw( context ); use base qw( Test2::Require ); sub skip { eval "use Net::SSLeay 1.33 (); 1" or return "test requires Net::SSLeay 1.33"; eval "use AnyEvent::TLS (); 1" or return "test requires AnyEvent::TLS"; return 'user requested skip of SSL tests via environment' if $ENV{ANYEVENT_WEBSOCKET_TEST_SKIP_SSL}; return; } 1; AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Tools/000755 000000 000000 00000000000 14424756453 021402 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Tools/WebSocket/000755 000000 000000 00000000000 14424756453 023270 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Tools/WebSocket/Connection.pm000644 000000 000000 00000005767 14424756453 025744 0ustar00rootroot000000 000000 package Test2::Tools::WebSocket::Connection; use strict; use warnings; use Test2::API qw( context ); use AnyEvent::Handle; use AnyEvent::Socket qw(tcp_server); use base qw( Exporter ); our @EXPORT_OK = qw( create_connection_pair create_connection_and_handle ); # ABSTRACT: Test AnyEvent::WebSocket::Connection without a server or client # VERSION =head1 SYNOPSIS use Test2::Tools::WebSocket::Connection qw( create_connection_pair ); my($a, $b) = create_connection_pair; =head1 DESCRIPTION This module provides a function for building a pair of L objects that can be used for testing. =cut sub _create_handle_pair { my @ports; my $cv_port = AnyEvent->condvar; my $cv_server_fh = AnyEvent->condvar; my $server = tcp_server undef, undef, sub { my ($fh, $host, $port) = @_; $ports[0] = $port; $cv_server_fh->send($fh); }, sub { my($fh, $host, $port) = @_; $ports[1] = $port; $cv_port->send($port); }; my $cv_connect = AnyEvent->condvar; my $a_handle = AnyEvent::Handle->new( connect => ["127.0.0.1", $cv_port->recv], on_error => sub { die "connect error: $_[2]" }, on_connect => sub { $cv_connect->send() } ); $cv_connect->recv; my $b_handle = AnyEvent::Handle->new( fh => $cv_server_fh->recv ); my $ctx = context(); $ctx->note("create connection pair " . join(':', @ports)); $ctx->release; return ($a_handle, $b_handle); } =head1 FUNCTIONS =head2 create_connection_pair my($a,$b) = create_connection_pair; my($a,$b) = create_connection_pair(\%a_options, \%b_options); This function creates a pair of connection object which are connected. When you send a message on one end it will be received on the other. The optional option hashes are passed into L so you can use any option that is legal there. =cut sub create_connection_pair { my ($a_options_ref, $b_options_ref) = @_; $a_options_ref ||= {}; $b_options_ref ||= {}; my ($a_handle, $b_handle) = _create_handle_pair(); require AnyEvent::WebSocket::Connection; return ( AnyEvent::WebSocket::Connection->new(%$a_options_ref, handle => $a_handle), AnyEvent::WebSocket::Connection->new(%$b_options_ref, handle => $b_handle), ); } =head2 create_connection_and_handle my($connection, $handle) = create_connection_and_handle; my($connection, $handle) = create_connection_and_handle(\%connection_options); This is the same as create_connection_pair, except a L object is returned for one end. This can be useful for some lower level testing. =cut sub create_connection_and_handle { my ($a_options_ref) = @_; my ($a_handle, $b_handle) = _create_handle_pair(); require AnyEvent::WebSocket::Connection; return ( AnyEvent::WebSocket::Connection->new(%$a_options_ref, handle => $a_handle), $b_handle ); } 1; =head1 SEEL ALSO =over 4 =item L =item L =item L Also provides methods for testing websockets. =back =cut AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Tools/WebSocket/Mojo.pm000644 000000 000000 00000001213 14424756453 024527 0ustar00rootroot000000 000000 package Test2::Tools::WebSocket::Mojo; use strict; use warnings; use base qw( Exporter ); use Mojo::Server::Daemon; use Test2::API qw( context ); our @EXPORT_OK = qw( start_mojo ); sub start_mojo { my (%args) = @_; my $app = $args{app}; my $scheme = $args{ssl} ? "https" : "http"; my $server = Mojo::Server::Daemon->new; my $port = generate_port(); my $ctx = context(); $ctx->note("port = $port"); $ctx->release; $server->app($app); $server->listen(["$scheme://127.0.0.1:$port"]); $server->start; return ($server, $port); } sub generate_port { IO::Socket::INET->new(Listen => 5, LocalAddr => '127.0.0.1')->sockport } 1; AnyEvent-WebSocket-Client-0.55/t/lib/Test2/Tools/WebSocket/Server.pm000644 000000 000000 00000004735 14424756453 025105 0ustar00rootroot000000 000000 package Test2::Tools::WebSocket::Server; use strict; use warnings; use base qw( Exporter ); use URI; use Test2::API qw( context ); use AnyEvent::Handle; use AnyEvent::Socket qw( tcp_server); use Protocol::WebSocket::Handshake::Server; use Protocol::WebSocket::Frame; use PerlX::Maybe qw( maybe ); our @EXPORT_OK = qw( start_server start_echo ); sub start_server { my $opt = { @_ }; $opt->{handshake} ||= sub {}; $opt->{customize_server_response} ||= sub {}; my $server_cv = AnyEvent->condvar; tcp_server undef, undef, sub { my $handshake = Protocol::WebSocket::Handshake::Server->new; my $frame = Protocol::WebSocket::Frame->new( max_payload_size => 0 ); my $hdl = AnyEvent::Handle->new( $opt->{tls} ? (tls => 'accept', tls_ctx => $opt->{tls}) : (), fh => shift, on_eof => sub { my $ctx = context(); $ctx->note("on_eof called."); $ctx->release; $opt->{end}->() if $opt->{end}; }, on_error => sub { my(undef, undef, $error) = @_; my $ctx = context(); $ctx->note("error = $error"); $ctx->release; $opt->{end}->() if $opt->{end}; }, ); $hdl->on_read( sub { my $chunk = $_[0]{rbuf}; $_[0]{rbuf} = ''; unless($handshake->is_done) { $handshake->parse($chunk); if($handshake->is_done) { $opt->{customize_server_response}->($handshake); $hdl->push_write($handshake->to_string); $opt->{handshake}->(handshake => $handshake, hdl => $hdl); } return; } $frame->append($chunk); while(defined(my $message = $frame->next)) { $opt->{message}->(frame => $frame, message => $message, hdl => $hdl); } } ); }, sub { my($fh, $host, $port) = @_; $server_cv->send($port); }; my $port = $server_cv->recv; my $uri = URI->new('ws://127.0.0.1/echo'); $uri->port($port); $uri->scheme('wss') if $opt->{tls}; my $ctx = context(); $ctx->note("$uri"); $ctx->release; $uri; } sub start_echo { start_server(message => sub { my $opt = { @_ }; return if !$opt->{frame}->is_text && !$opt->{frame}->is_binary; $opt->{hdl}->push_write($opt->{frame}->new(buffer => $opt->{message}, max_payload_size => 0 )->to_bytes); if($opt->{message} eq 'quit') { $opt->{hdl}->push_write($opt->{frame}->new(type => 'close')->to_bytes); $opt->{hdl}->push_shutdown; } }); } 1; AnyEvent-WebSocket-Client-0.55/t/mojo.t000644 000000 000000 00000002773 14424756453 017675 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Require::NotWindows; use Test2::Require::Module 'EV'; use Test2::Require::Module 'Mojolicious' => '3.0'; use Test2::Require::Module 'Mojolicious::Lite'; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use Test2::Tools::WebSocket::Mojo qw( start_mojo ); use AnyEvent::WebSocket::Client; use Mojolicious::Lite; # NOTE: The mojo_* tests are to test interoperability with a really # good implementation that is also written in Perl. Mojolicious # tests should not be written for new features and to test bugs, # unless they are also accompanied by a non-Mojolicious test as well! app->log->level('fatal'); websocket '/count/:num' => sub { my($self) = shift; my $max = $self->param('num'); my $counter = 1; $self->on(message => sub { my($self, $payload) = @_; note "send $counter"; $self->send($counter++); if($counter >= $max) { $self->finish; } }); }; my ($server, $port) = start_mojo(app => app()); my $client = AnyEvent::WebSocket::Client->new; my $connection = $client->connect("ws://127.0.0.1:$port/count/10")->recv; isa_ok $connection, 'AnyEvent::WebSocket::Connection'; my $done = AnyEvent->condvar; $connection->send('ping'); my $last; $connection->on(each_message => sub { my $message = $_[1]->body; note "recv $message"; $connection->send('ping'); $last = $message; }); $connection->on(finish => sub { $done->send(1); }); is $done->recv, '1', 'friendly disconnect'; is $last, 9, 'last = 9'; done_testing; AnyEvent-WebSocket-Client-0.55/t/mojo_echo.t000644 000000 000000 00000003431 14424756453 020663 0ustar00rootroot000000 000000 use lib 't/lib'; use Test2::Require::NotWindows; use Test2::Require::Module 'EV'; use Test2::Require::Module 'Mojolicious' => '3.0'; use Test2::Require::Module 'Mojolicious::Lite'; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use Test2::Tools::WebSocket::Mojo qw( start_mojo ); use AnyEvent::WebSocket::Client; use Mojolicious::Lite; # NOTE: The mojo_* tests are to test interoperability with a really # good implementation that is also written in Perl. Mojolicious # tests should not be written for new features and to test bugs, # unless they are also accompanied by a non-Mojolicious test as well! app->log->level('fatal'); websocket '/echo' => sub { my($self) = shift; $self->on(message => sub { my($self, $payload) = @_; $self->send($payload); if($payload eq "quit") { $self->finish; } }); }; my ($server, $port) = start_mojo(app => app()); my $client = AnyEvent::WebSocket::Client->new; my $connection = $client->connect("ws://127.0.0.1:$port/echo")->recv; isa_ok $connection, 'AnyEvent::WebSocket::Connection'; my $quit_cv = AnyEvent->condvar; $connection->on(finish => sub { $quit_cv->send("finished"); }); for my $testcase ( {label => "single character", data => "a"}, {label => "5k bytes", data => "a" x 5000}, {label => "empty", data => ""}, {label => "0", data => 0}, {label => "utf8 charaters", data => 'UTF8 WIDE CHARACTERS'}, {label => "quit", data => "quit"}, ) { my $cv = AnyEvent->condvar; $connection->on(next_message => sub { my $message = pop->decoded_body; $cv->send($message); }); $connection->send($testcase->{data}); is $cv->recv, $testcase->{data}, "$testcase->{label}: echo succeeds"; } is $quit_cv->recv, "finished", "friendly disconnect"; done_testing; AnyEvent-WebSocket-Client-0.55/t/mojo_receive.t000644 000000 000000 00000005312 14424756453 021367 0ustar00rootroot000000 000000 use utf8; use lib 't/lib'; use Test2::Require::NotWindows; use Test2::Require::Module 'EV'; use Test2::Require::Module 'Mojolicious' => '3.0'; use Test2::Require::Module 'Mojolicious::Lite'; use Test2::Plugin::AnyEvent::Timeout; use Test2::V0 -no_srand => 1; use Test2::Tools::WebSocket::Mojo qw( start_mojo ); use AnyEvent::WebSocket::Client; use Mojolicious::Lite; use Protocol::WebSocket; use Encode qw(encode); # NOTE: The mojo_* tests are to test interoperability with a really # good implementation that is also written in Perl. Mojolicious # tests should not be written for new features and to test bugs, # unless they are also accompanied by a non-Mojolicious test as well! my @test_cases = ( { send => { binary => "hoge"}, recv_exp => ["hoge", "is_binary"] }, { send => { text => "foobar"}, recv_exp => ["foobar", "is_text"] }, { send => { binary => encode("utf8", "UTFー8") }, recv_exp => [encode("utf8", "UTFー8"), "is_binary"] }, { send => { text => encode("utf8", "UTFー8") }, recv_exp => [encode("utf8", "UTFー8"), "is_text"] }, ); app->log->level('fatal'); websocket '/data' => sub { my($self) = shift; $self->on(message => sub { my($self, $index) = @_; $self->send($test_cases[$index]{send}); }); }; my ($server, $port) = start_mojo(app => app()); my $client = AnyEvent::WebSocket::Client->new; my $connection = $client->connect("ws://127.0.0.1:$port/data")->recv; isa_ok $connection, 'AnyEvent::WebSocket::Connection'; subtest 'on_next_data' => sub { my $cb_count = 0; for my $test_index (0 .. $#test_cases) { my $cv = AnyEvent->condvar; $connection->on(next_message => sub { $cb_count++; $cv->send(@_) }); $connection->send($test_index); my($connection, $message) = $cv->recv; isa_ok $connection, 'AnyEvent::WebSocket::Connection'; is $message->body, $test_cases[$test_index]->{recv_exp}->[0], "body = " . $message->body; my $method = $test_cases[$test_index]->{recv_exp}->[1]; ok $message->$method, "\$message->$method is true"; } is($cb_count, scalar(@test_cases), "callback count OK"); }; subtest 'on_each_data' => sub { my $cv; my $cb_count = 0; $connection->on(each_message => sub { $cb_count++; $cv->send(@_) }); for my $test_index (0 .. $#test_cases) { $cv = AnyEvent->condvar; $connection->send($test_index); my($connection, $message) = $cv->recv; isa_ok $connection, 'AnyEvent::WebSocket::Connection'; is $message->body, $test_cases[$test_index]->{recv_exp}->[0], "body = " . $message->body; my $method = $test_cases[$test_index]->{recv_exp}->[1]; ok $message->$method, "\$message->$method is true"; } is($cb_count, scalar(@test_cases), "callback count OK"); }; done_testing; AnyEvent-WebSocket-Client-0.55/xt/000755 000000 000000 00000000000 14424756453 016723 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/xt/author/000755 000000 000000 00000000000 14424756453 020225 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/xt/author/critic.t000644 000000 000000 00000000515 14424756453 021670 0ustar00rootroot000000 000000 use Test2::Require::Module 'Test2::Tools::PerlCritic'; use Test2::Require::Module 'Perl::Critic'; use Test2::Require::Module 'Perl::Critic::Freenode'; use Test2::V0; use Perl::Critic; use Test2::Tools::PerlCritic; my $critic = Perl::Critic->new( -profile => 'perlcriticrc', ); perl_critic_ok ['lib','t'], $critic; done_testing; AnyEvent-WebSocket-Client-0.55/xt/author/eol.t000644 000000 000000 00000000510 14424756453 021165 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::EOL' unless eval q{ use Test::EOL; 1 }; }; use Test::EOL; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); all_perl_files_ok(grep { -e $_ } qw( bin lib t Makefile.PL )); AnyEvent-WebSocket-Client-0.55/xt/author/no_tabs.t000644 000000 000000 00000000522 14424756453 022036 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::NoTabs' unless eval q{ use Test::NoTabs; 1 }; }; use Test::NoTabs; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); all_perl_files_ok( grep { -e $_ } qw( bin lib t Makefile.PL )); AnyEvent-WebSocket-Client-0.55/xt/author/pod.t000644 000000 000000 00000000472 14424756453 021177 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::Pod' unless eval q{ use Test::Pod; 1 }; }; use Test::Pod; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); all_pod_files_ok( grep { -e $_ } qw( bin lib )); AnyEvent-WebSocket-Client-0.55/xt/author/pod_coverage.t000644 000000 000000 00000004001 14424756453 023042 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires 5.010 or better' unless $] >= 5.010; plan skip_all => 'test requires Test::Pod::Coverage' unless eval q{ use Test::Pod::Coverage; 1 }; plan skip_all => 'test requires YAML' unless eval q{ use YAML; 1; }; plan skip_all => 'test does not always work in cip check' if defined $ENV{CIPSTATIC} && $ENV{CIPSTATIC} eq 'true'; }; use Test::Pod::Coverage; use YAML qw( LoadFile ); use FindBin; use File::Spec; my $config_filename = File::Spec->catfile( $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml' ); my $config; $config = LoadFile($config_filename) if -r $config_filename; plan skip_all => 'disabled' if $config->{pod_coverage}->{skip}; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); my @private_classes; my %private_methods; push $config->{pod_coverage}->{private}->@*, 'Alien::.*::Install::Files#Inline'; foreach my $private ($config->{pod_coverage}->{private}->@*) { my($class,$method) = split /#/, $private; if(defined $class && $class ne '') { my $regex = eval 'qr{^' . $class . '$}'; if(defined $method && $method ne '') { push @private_classes, { regex => $regex, method => $method }; } else { push @private_classes, { regex => $regex, all => 1 }; } } elsif(defined $method && $method ne '') { $private_methods{$_} = 1 for split /,/, $method; } } my @classes = all_modules; plan tests => scalar @classes; foreach my $class (@classes) { SKIP: { my($is_private_class) = map { 1 } grep { $class =~ $_->{regex} && $_->{all} } @private_classes; skip "private class: $class", 1 if $is_private_class; my %methods = map {; $_ => 1 } map { split /,/, $_->{method} } grep { $class =~ $_->{regex} } @private_classes; $methods{$_} = 1 for keys %private_methods; my $also_private = eval 'qr{^' . join('|', keys %methods ) . '$}'; pod_coverage_ok $class, { also_private => [$also_private] }; }; } AnyEvent-WebSocket-Client-0.55/xt/author/pod_spelling_common.t000644 000000 000000 00000001350 14424756453 024440 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::Pod::Spelling::CommonMistakes' unless eval q{ use Test::Pod::Spelling::CommonMistakes; 1 }; plan skip_all => 'test requires YAML' unless eval q{ use YAML qw( LoadFile ); 1 }; }; use Test::Pod::Spelling::CommonMistakes; use FindBin; use File::Spec; my $config_filename = File::Spec->catfile( $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml' ); my $config; $config = LoadFile($config_filename) if -r $config_filename; plan skip_all => 'disabled' if $config->{pod_spelling_common}->{skip}; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); # TODO: test files in bin too. all_pod_files_ok; AnyEvent-WebSocket-Client-0.55/xt/author/pod_spelling_system.t000644 000000 000000 00000002367 14424756453 024505 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::Spelling' unless eval q{ use Test::Spelling; 1 }; plan skip_all => 'test requires YAML' unless eval q{ use YAML; 1; }; }; use Test::Spelling; use YAML qw( LoadFile ); use FindBin; use File::Spec; my $config_filename = File::Spec->catfile( $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml' ); my $config; $config = LoadFile($config_filename) if -r $config_filename; plan skip_all => 'disabled' if $config->{pod_spelling_system}->{skip}; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); add_stopwords($config->{pod_spelling_system}->{stopwords}->@*); add_stopwords(qw( Plicease stdout stderr stdin subref loopback username os Ollis Mojolicious plicease CPAN reinstall TODO filename filenames login callback callbacks standalone VMS hostname hostnames TCP UDP IP API MSWin32 OpenBSD FreeBSD NetBSD unencrypted WebSocket WebSockets timestamp timestamps poney BackPAN portably RedHat AIX BSD XS FFI perlish optimizations subdirectory RESTful SQLite JavaScript dir plugins munge jQuery namespace PDF PDFs usernames DBI pluggable APIs SSL JSON YAML uncommented Solaris OpenVMS URI URL CGI )); all_pod_files_spelling_ok; AnyEvent-WebSocket-Client-0.55/xt/author/strict.t000644 000000 000000 00000001031 14424756453 021715 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::Strict' unless eval q{ use Test::Strict; 1 }; }; use Test::Strict; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); unshift @Test::Strict::MODULES_ENABLING_STRICT, 'ozo', 'Test2::Bundle::SIPS', 'Test2::V0', 'Test2::Bundle::Extended'; note "enabling strict = $_" for @Test::Strict::MODULES_ENABLING_STRICT; all_perl_files_ok( grep { -e $_ } qw( bin lib t Makefile.PL )); AnyEvent-WebSocket-Client-0.55/xt/author/version.t000644 000000 000000 00000001473 14424756453 022104 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; use FindBin (); BEGIN { plan skip_all => "test requires Test::Version 2.00" unless eval q{ use Test::Version 2.00 qw( version_all_ok ), { has_version => 1, filename_match => sub { $_[0] !~ m{/(ConfigData|Install/Files)\.pm$} }, }; 1 }; plan skip_all => 'test requires YAML' unless eval q{ use YAML; 1; }; } use YAML qw( LoadFile ); use FindBin; use File::Spec; my $config_filename = File::Spec->catfile( $FindBin::Bin, File::Spec->updir, File::Spec->updir, 'author.yml' ); my $config; $config = LoadFile($config_filename) if -r $config_filename; if($config->{version}->{dir}) { note "using dir " . $config->{version}->{dir} } version_all_ok($config->{version}->{dir} ? ($config->{version}->{dir}) : ()); done_testing; AnyEvent-WebSocket-Client-0.55/xt/release/000755 000000 000000 00000000000 14424756453 020343 5ustar00rootroot000000 000000 AnyEvent-WebSocket-Client-0.55/xt/release/changes.t000644 000000 000000 00000001113 14424756453 022134 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::CPAN::Changes' unless eval q{ use Test::CPAN::Changes; 1 }; }; use Test::CPAN::Changes; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); do { my $old = \&Test::Builder::carp; my $new = sub { my($self, @messages) = @_; return if $messages[0] =~ /^Date ".*" is not in the recommend format/; $old->($self, @messages); }; no warnings 'redefine'; *Test::Builder::carp = $new; }; changes_file_ok; done_testing; AnyEvent-WebSocket-Client-0.55/xt/release/fixme.t000644 000000 000000 00000000616 14424756453 021643 0ustar00rootroot000000 000000 use strict; use warnings; use Test::More; BEGIN { plan skip_all => 'test requires Test::Fixme' unless eval q{ use Test::Fixme 0.14; 1 }; }; use Test::Fixme 0.07; use FindBin; use File::Spec; chdir(File::Spec->catdir($FindBin::Bin, File::Spec->updir, File::Spec->updir)); run_tests( match => qr/FIXME/, where => [ grep { -e $_ } qw( bin lib t Makefile.PL Build.PL )], warn => 1, );