POE-Component-Client-DNS-1.054/000755 000765 000024 00000000000 12621127646 016065 5ustar00trocstaff000000 000000 POE-Component-Client-DNS-1.054/CHANGES000644 000765 000024 00000002273 12621127646 017064 0ustar00trocstaff000000 000000 ================================================== Changes from 2014-11-12 00:00:00 +0000 to present. ================================================== ------------------------------------------ version 1.054 at 2015-11-12 15:26:29 +0000 ------------------------------------------ Change: 3c9796c2513572da0a41e1ef55db9f86c8b41c59 Author: Chris 'BinGOs' Williams Date : 2015-11-12 10:24:50 +0000 Support Net::DNS 1.03. Change: 1cea2d126d1d32dc3ecb01e90a0cdef6541127ce Author: Rocco Caputo Date : 2015-11-12 10:24:50 +0000 Udpate Dist::Zilla configuration for changes to plugins. Change: a6be0cf34adb445e82a166506a42f07e86f3d929 Author: Rocco Caputo Date : 2014-09-06 14:02:05 +0000 Merge pull request #2 from Hugmeir/master /etc/hosts in Android is in /system/etc/hosts Change: 8f45959868c5154741c0162178c3a95308ede185 Author: Brian Fraser Date : 2014-07-27 14:42:40 +0000 /etc/hosts in Android is in /system/etc/hosts ================================================= Plus 19 releases after 2014-11-12 00:00:00 +0000. ================================================= POE-Component-Client-DNS-1.054/dist.ini000644 000765 000024 00000002331 12621127646 017530 0ustar00trocstaff000000 000000 name = POE-Component-Client-DNS author = Rocco Caputo copyright_holder = Rocco Caputo license = Perl_5 [Prereqs] POE = 1.294 Net::DNS = 0.65 Test::More = 0.96 Test::NoWarnings = 1.02 [MetaResources] bugtracker.mailto = bug-poe-component-client-dns@rt.cpan.org bugtracker.web = http://rt.cpan.org/Public/Dist/Display.html?Name=POE-Component-Client-DNS homepage = http://search.cpan.org/dist/POE-Component-Client-DNS license = http://dev.perl.org/licenses/ ;repository.type = git ;repository.url = git@github.com:rcaputo/poe-component-client-dns.git ;repository.web = https://github.com/rcaputo/poe-component-client-dns [Repository] git_remote = gh [ReadmeFromPod] [ReadmeMarkdownFromPod] [ReportVersions] ; Require everything to be checked in. ; Must exclude tarball directories from .gitignore. [Git::Check] ; Calculate the release version. [Git::NextVersion] first_version = 1.053 version_regexp = ^v(\d+\.\d+)$ ; Generate the changelog. [ChangelogFromGit] tag_regexp = v(\d+[_.]\d+) ; Tag the repository after release. [Git::Tag] tag_format = v%v tag_message = Release %v. [@Classic] [MetaJSON] POE-Component-Client-DNS-1.054/lib/000755 000765 000024 00000000000 12621127646 016633 5ustar00trocstaff000000 000000 POE-Component-Client-DNS-1.054/LICENSE000644 000765 000024 00000043746 12621127646 017110 0ustar00trocstaff000000 000000 This software is copyright (c) 2015 by Rocco Caputo . 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) 2015 by Rocco Caputo . 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) 2015 by Rocco Caputo . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End POE-Component-Client-DNS-1.054/Makefile.PL000644 000765 000024 00000002132 12621127646 020035 0ustar00trocstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.041. use strict; use warnings; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "non-blocking, parallel DNS client", "AUTHOR" => "Rocco Caputo ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "POE-Component-Client-DNS", "LICENSE" => "perl", "NAME" => "POE::Component::Client::DNS", "PREREQ_PM" => { "Net::DNS" => "0.65", "POE" => "1.294", "Test::More" => "0.96", "Test::NoWarnings" => "1.02" }, "VERSION" => "1.054", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Net::DNS" => "0.65", "POE" => "1.294", "Test::More" => "0.96", "Test::NoWarnings" => "1.02" ); 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); POE-Component-Client-DNS-1.054/MANIFEST000644 000765 000024 00000000555 12621127646 017223 0ustar00trocstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.041. CHANGES LICENSE MANIFEST MANIFEST.SKIP META.json META.yml Makefile.PL README README.mkdn dist.ini lib/POE/Component/Client/DNS.pm t/000-report-versions.t t/01_resolve.t t/02_tag_args.t t/03_api_3.t t/04_errors.t t/05_api_4.t t/06_hosts.t t/author-pod-coverage.t t/author-pod-syntax.t POE-Component-Client-DNS-1.054/MANIFEST.SKIP000600 000765 000024 00000000320 12621127646 017746 0ustar00trocstaff000000 000000 CVS \.\# \.bak$ \.cvsignore \.git \.gz$ \.orig$ \.patch$ \.ppd$ \.rej$ \.rej$ \.svn \.swo$ \.swp$ ^Makefile$ ^Makefile\.old$ ^\. ^_Inline ^_build ^blib/ ^comptest ^cover_db ^coverage\.report$ ^pm_to_blib$ ~$ POE-Component-Client-DNS-1.054/META.json000644 000765 000024 00000003020 12621127646 017501 0ustar00trocstaff000000 000000 { "abstract" : "non-blocking, parallel DNS client", "author" : [ "Rocco Caputo " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.041, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "POE-Component-Client-DNS", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Net::DNS" : "0.65", "POE" : "1.294", "Test::More" : "0.96", "Test::NoWarnings" : "1.02" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-poe-component-client-dns@rt.cpan.org", "web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=POE-Component-Client-DNS" }, "homepage" : "http://search.cpan.org/dist/POE-Component-Client-DNS", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/rcaputo/poe-component-client-dns.git", "web" : "https://github.com/rcaputo/poe-component-client-dns" } }, "version" : "1.054" } POE-Component-Client-DNS-1.054/META.yml000644 000765 000024 00000001414 12621127646 017336 0ustar00trocstaff000000 000000 --- abstract: 'non-blocking, parallel DNS client' author: - 'Rocco Caputo ' build_requires: {} configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.041, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: POE-Component-Client-DNS requires: Net::DNS: '0.65' POE: '1.294' Test::More: '0.96' Test::NoWarnings: '1.02' resources: bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=POE-Component-Client-DNS homepage: http://search.cpan.org/dist/POE-Component-Client-DNS license: http://dev.perl.org/licenses/ repository: git://github.com/rcaputo/poe-component-client-dns.git version: '1.054' POE-Component-Client-DNS-1.054/README000644 000765 000024 00000021327 12621127646 016752 0ustar00trocstaff000000 000000 NAME POE::Component::Client::DNS - non-blocking, parallel DNS client SYNOPSIS use POE qw(Component::Client::DNS); my $named = POE::Component::Client::DNS->spawn( Alias => "named" ); POE::Session->create( inline_states => { _start => \&start_tests, response => \&got_response, } ); POE::Kernel->run(); exit; sub start_tests { my $response = $named->resolve( event => "response", host => "localhost", context => { }, ); if ($response) { $_[KERNEL]->yield(response => $response); } } sub got_response { my $response = $_[ARG0]; my @answers = $response->{response}->answer(); foreach my $answer (@answers) { print( "$response->{host} = ", $answer->type(), " ", $answer->rdatastr(), "\n" ); } } DESCRIPTION POE::Component::Client::DNS provides non-blocking, parallel DNS requests via Net::DNS. Using POE, it allows other tasks to run while waiting for name servers to respond. For simple name resolution, including smart handling of IPv6 names, please see POE::Component::Resolver instead. PUBLIC METHODS spawn A program must spawn at least one POE::Component::Client::DNS instance before it can perform background DNS requests. Each instance represents a connection to one or more name servers. If a program only needs to request DNS requests from one server, then you only need one POE::Component::Client::DNS instance. As of version 0.98 you can override the default timeout per request. From this point forward there is no need to spawn multiple instances to affect different timeouts for each request. PoCo::Client::DNS's spawn method takes a few named parameters: Alias sets the component's alias. Requests will be posted to this alias. The component's alias defaults to "resolver" if one is not provided. Programs spawning more than one DNS client component must specify aliases for N-1 of them, otherwise alias collisions will occur. Alias => $session_alias, # defaults to "resolver" Timeout sets the component's default timeout. The timeout may be overridden per request. See the "request" event, later on. If no Timeout is set, the component will wait 90 seconds per request by default. Timeouts may be set to real numbers. Timeouts are more accurate if you have Time::HiRes installed. POE (and thus this component) will use Time::HiRes automatically if it's available. Timeout => $seconds_to_wait, # defaults to 90 Nameservers holds a reference to a list of name servers to try. The list is passed directly to Net::DNS::Resolver's nameservers() method. By default, POE::Component::Client::DNS will query the name servers that appear in /etc/resolv.conf or its equivalent. Nameservers => \@name_servers, # defaults to /etc/resolv.conf's HostsFile (optional) holds the name of a specific hosts file to use for resolving hardcoded addresses. By default, it looks for a file named /etc/hosts. On Windows systems, it may look in the following other places: $ENV{SystemRoot}\System32\Drivers\Etc\hosts $ENV{SystemRoot}\System\Drivers\Etc\hosts $ENV{SystemRoot}\hosts resolve resolve() requests the component to resolve a host name. It will return a hash reference (described in RESPONSE MESSAGES, below) if it can honor the request immediately (perhaps from a cache). Otherwise it returns undef if a resolver must be consulted asynchronously. Requests are passed as a list of named fields. $resolver->resolve( class => $dns_record_class, # defaults to "IN" type => $dns_record_type, # defaults to "A" host => $request_host, # required context => $request_context, # required event => $response_event, # required timeout => $request_timeout, # defaults to spawn()'s Timeout nameservers => $nameservers, # defaults to $resolver's Nameservers ); The "class" and "type" fields specify what kind of information to return about a host. Most of the time internet addresses are requested for host names, so the class and type default to "IN" (internet) and "A" (address), respectively. The "host" field designates the host to look up. It is required. The "event" field tells the component which event to send back when a response is available. It is required, but it will not be used if resolve() can immediately return a cached response. "timeout" tells the component how long to wait for a response to this request. It defaults to the "Timeout" given at spawn() time. "context" includes some external data that links responses back to their requests. The context data is provided by the program that uses POE::Component::Client::DNS. The component will pass the context back to the program without modification. The "context" parameter is required, and may contain anything that fits in a scalar. shutdown shutdown() causes the component to terminate gracefully. It will finish serving pending requests then close down. get_resolver POE::Component::Client::DNS uses a Net::DNS::Resolver object internally. get_resolver() returns that object so it may be interrogated or modified. See Net::DNS::Resolver for options. Set the resolver to check on nonstandard port 1153: $poco_client_dns->get_resolver()->port(1153); RESPONSE MESSAGES POE::Component::Client::DNS responds in one of two ways. Its resolve() method will return a response immediately if it can be found in the component's cache. Otherwise the component posts the response back in $_[ARG0]. In either case, the response is a hash reference containing the same fields: host => $request_host, type => $request_type, class => $request_class, context => $request_context, response => $net_dns_packet, error => $net_dns_error, The "host", "type", "class", and "context" response fields are identical to those given in the request message. "response" contains a Net::DNS::Packet object on success or undef if the lookup failed. The Net::DNS::Packet object describes the response to the program's request. It may contain several DNS records. Please consult Net::DNS and Net::DNS::Packet for more information. "error" contains a description of any error that has occurred. It is only valid if "response" is undefined. SEE ALSO POE - POE::Component::Client::DNS builds heavily on POE. POE::Component::Resolver - A system name resolver, including IPv6 support and whatever else your system supports. Net::DNS - This module uses Net::DNS internally. Net::DNS::Packet - Responses are returned as Net::DNS::Packet objects. DEPRECATIONS The older, list-based interfaces are no longer documented as of version 0.98. They are being phased out. The method-based interface, first implementedin version 0.98, will replace the deprecated interfaces after a six-month phase-out period. Version 0.98 was released in October of 2004. The deprecated interfaces will continue to work without warnings until January 2005. As of January 2005, programs that use the deprecated interfaces will continue to work, but they will generate mandatory warnings. Those warnings will persist until April 2005. As of April 2005 the mandatory warnings will be upgraded to mandatory errors. Support for the deprecated interfaces will be removed entirely. As of late January 2011, POE::Component::Resolver provides basic system resolver support, including IPv6 and mDNS if your resolver's configured ot use it. The use of POE::Component::Client::DNS for basic resolution is deprecated, however it's still the best option for actual DNS server requests. BUG TRACKER https://rt.cpan.org/Dist/Display.html?Queue=POE-Component-Client-DNS REPOSITORY http://github.com/rcaputo/poe-component-client-dns OTHER RESOURCES http://search.cpan.org/dist/POE-Component-Client-DNS/ AUTHOR & COPYRIGHTS POE::Component::Client::DNS is Copyright 1999-2009 by Rocco Caputo. All rights are reserved. POE::Component::Client::DNS is free software; you may redistribute it and/or modify it under the same terms as Perl itself. Postback arguments were contributed by tag. POE-Component-Client-DNS-1.054/README.mkdn000644 000765 000024 00000021364 12621127646 017703 0ustar00trocstaff000000 000000 # NAME POE::Component::Client::DNS - non-blocking, parallel DNS client # VERSION version 1.054 # SYNOPSIS use POE qw(Component::Client::DNS); my $named = POE::Component::Client::DNS->spawn( Alias => "named" ); POE::Session->create( inline_states => { _start => \&start_tests, response => \&got_response, } ); POE::Kernel->run(); exit; sub start_tests { my $response = $named->resolve( event => "response", host => "localhost", context => { }, ); if ($response) { $_[KERNEL]->yield(response => $response); } } sub got_response { my $response = $_[ARG0]; my @answers = $response->{response}->answer(); foreach my $answer (@answers) { print( "$response->{host} = ", $answer->type(), " ", $answer->rdatastr(), "\n" ); } } # DESCRIPTION POE::Component::Client::DNS provides non-blocking, parallel DNS requests via Net::DNS. Using POE, it allows other tasks to run while waiting for name servers to respond. For simple name resolution, including smart handling of IPv6 names, please see [POE::Component::Resolver](https://metacpan.org/pod/POE::Component::Resolver) instead. # PUBLIC METHODS - spawn A program must spawn at least one POE::Component::Client::DNS instance before it can perform background DNS requests. Each instance represents a connection to one or more name servers. If a program only needs to request DNS requests from one server, then you only need one POE::Component::Client::DNS instance. As of version 0.98 you can override the default timeout per request. From this point forward there is no need to spawn multiple instances to affect different timeouts for each request. PoCo::Client::DNS's `spawn` method takes a few named parameters: Alias sets the component's alias. Requests will be posted to this alias. The component's alias defaults to "resolver" if one is not provided. Programs spawning more than one DNS client component must specify aliases for N-1 of them, otherwise alias collisions will occur. Alias => $session_alias, # defaults to "resolver" Timeout sets the component's default timeout. The timeout may be overridden per request. See the "request" event, later on. If no Timeout is set, the component will wait 90 seconds per request by default. Timeouts may be set to real numbers. Timeouts are more accurate if you have Time::HiRes installed. POE (and thus this component) will use Time::HiRes automatically if it's available. Timeout => $seconds_to_wait, # defaults to 90 Nameservers holds a reference to a list of name servers to try. The list is passed directly to Net::DNS::Resolver's nameservers() method. By default, POE::Component::Client::DNS will query the name servers that appear in /etc/resolv.conf or its equivalent. Nameservers => \@name_servers, # defaults to /etc/resolv.conf's HostsFile (optional) holds the name of a specific hosts file to use for resolving hardcoded addresses. By default, it looks for a file named /etc/hosts. On Windows systems, it may look in the following other places: $ENV{SystemRoot}\System32\Drivers\Etc\hosts $ENV{SystemRoot}\System\Drivers\Etc\hosts $ENV{SystemRoot}\hosts - resolve resolve() requests the component to resolve a host name. It will return a hash reference (described in RESPONSE MESSAGES, below) if it can honor the request immediately (perhaps from a cache). Otherwise it returns undef if a resolver must be consulted asynchronously. Requests are passed as a list of named fields. $resolver->resolve( class => $dns_record_class, # defaults to "IN" type => $dns_record_type, # defaults to "A" host => $request_host, # required context => $request_context, # required event => $response_event, # required timeout => $request_timeout, # defaults to spawn()'s Timeout nameservers => $nameservers, # defaults to $resolver's Nameservers ); The "class" and "type" fields specify what kind of information to return about a host. Most of the time internet addresses are requested for host names, so the class and type default to "IN" (internet) and "A" (address), respectively. The "host" field designates the host to look up. It is required. The "event" field tells the component which event to send back when a response is available. It is required, but it will not be used if resolve() can immediately return a cached response. "timeout" tells the component how long to wait for a response to this request. It defaults to the "Timeout" given at spawn() time. "context" includes some external data that links responses back to their requests. The context data is provided by the program that uses POE::Component::Client::DNS. The component will pass the context back to the program without modification. The "context" parameter is required, and may contain anything that fits in a scalar. - shutdown shutdown() causes the component to terminate gracefully. It will finish serving pending requests then close down. - get\_resolver POE::Component::Client::DNS uses a Net::DNS::Resolver object internally. get\_resolver() returns that object so it may be interrogated or modified. See [Net::DNS::Resolver](https://metacpan.org/pod/Net::DNS::Resolver) for options. Set the resolver to check on nonstandard port 1153: $poco_client_dns->get_resolver()->port(1153); # RESPONSE MESSAGES POE::Component::Client::DNS responds in one of two ways. Its resolve() method will return a response immediately if it can be found in the component's cache. Otherwise the component posts the response back in $\_\[ARG0\]. In either case, the response is a hash reference containing the same fields: host => $request_host, type => $request_type, class => $request_class, context => $request_context, response => $net_dns_packet, error => $net_dns_error, The "host", "type", "class", and "context" response fields are identical to those given in the request message. "response" contains a Net::DNS::Packet object on success or undef if the lookup failed. The Net::DNS::Packet object describes the response to the program's request. It may contain several DNS records. Please consult [Net::DNS](https://metacpan.org/pod/Net::DNS) and [Net::DNS::Packet](https://metacpan.org/pod/Net::DNS::Packet) for more information. "error" contains a description of any error that has occurred. It is only valid if "response" is undefined. # SEE ALSO [POE](https://metacpan.org/pod/POE) - POE::Component::Client::DNS builds heavily on POE. [POE::Component::Resolver](https://metacpan.org/pod/POE::Component::Resolver) - A system name resolver, including IPv6 support and whatever else your system supports. [Net::DNS](https://metacpan.org/pod/Net::DNS) - This module uses Net::DNS internally. [Net::DNS::Packet](https://metacpan.org/pod/Net::DNS::Packet) - Responses are returned as Net::DNS::Packet objects. # DEPRECATIONS The older, list-based interfaces are no longer documented as of version 0.98. They are being phased out. The method-based interface, first implementedin version 0.98, will replace the deprecated interfaces after a six-month phase-out period. Version 0.98 was released in October of 2004. The deprecated interfaces will continue to work without warnings until January 2005. As of January 2005, programs that use the deprecated interfaces will continue to work, but they will generate mandatory warnings. Those warnings will persist until April 2005. As of April 2005 the mandatory warnings will be upgraded to mandatory errors. Support for the deprecated interfaces will be removed entirely. As of late January 2011, POE::Component::Resolver provides basic system resolver support, including IPv6 and mDNS if your resolver's configured ot use it. The use of POE::Component::Client::DNS for basic resolution is deprecated, however it's still the best option for actual DNS server requests. # BUG TRACKER https://rt.cpan.org/Dist/Display.html?Queue=POE-Component-Client-DNS # REPOSITORY http://github.com/rcaputo/poe-component-client-dns # OTHER RESOURCES http://search.cpan.org/dist/POE-Component-Client-DNS/ # AUTHOR & COPYRIGHTS POE::Component::Client::DNS is Copyright 1999-2009 by Rocco Caputo. All rights are reserved. POE::Component::Client::DNS is free software; you may redistribute it and/or modify it under the same terms as Perl itself. Postback arguments were contributed by tag. POE-Component-Client-DNS-1.054/t/000755 000765 000024 00000000000 12621127646 016330 5ustar00trocstaff000000 000000 POE-Component-Client-DNS-1.054/t/000-report-versions.t000644 000765 000024 00000031270 12621127646 022176 0ustar00trocstaff000000 000000 #!perl use warnings; use strict; use Test::More 0.94; # Include a cut-down version of YAML::Tiny so we don't introduce unnecessary # dependencies ourselves. package Local::YAML::Tiny; use strict; use Carp 'croak'; # UTF Support? sub HAVE_UTF8 () { $] >= 5.007003 } BEGIN { if ( HAVE_UTF8 ) { # The string eval helps hide this from Test::MinimumVersion eval "require utf8;"; die "Failed to load UTF-8 support" if $@; } # Class structure require 5.004; $YAML::Tiny::VERSION = '1.40'; # Error storage $YAML::Tiny::errstr = ''; } # Printable characters for escapes my %UNESCAPES = ( z => "\x00", a => "\x07", t => "\x09", n => "\x0a", v => "\x0b", f => "\x0c", r => "\x0d", e => "\x1b", '\\' => '\\', ); ##################################################################### # Implementation # Create an empty YAML::Tiny object sub new { my $class = shift; bless [ @_ ], $class; } # Create an object from a file sub read { my $class = ref $_[0] ? ref shift : shift; # Check the file my $file = shift or return $class->_error( 'You did not specify a file name' ); return $class->_error( "File '$file' does not exist" ) unless -e $file; return $class->_error( "'$file' is a directory, not a file" ) unless -f _; return $class->_error( "Insufficient permissions to read '$file'" ) unless -r _; # Slurp in the file local $/ = undef; local *CFG; unless ( open(CFG, $file) ) { return $class->_error("Failed to open file '$file': $!"); } my $contents = ; unless ( close(CFG) ) { return $class->_error("Failed to close file '$file': $!"); } $class->read_string( $contents ); } # Create an object from a string sub read_string { my $class = ref $_[0] ? ref shift : shift; my $self = bless [], $class; my $string = $_[0]; unless ( defined $string ) { return $self->_error("Did not provide a string to load"); } # Byte order marks # NOTE: Keeping this here to educate maintainers # my %BOM = ( # "\357\273\277" => 'UTF-8', # "\376\377" => 'UTF-16BE', # "\377\376" => 'UTF-16LE', # "\377\376\0\0" => 'UTF-32LE' # "\0\0\376\377" => 'UTF-32BE', # ); if ( $string =~ /^(?:\376\377|\377\376|\377\376\0\0|\0\0\376\377)/ ) { return $self->_error("Stream has a non UTF-8 BOM"); } else { # Strip UTF-8 bom if found, we'll just ignore it $string =~ s/^\357\273\277//; } # Try to decode as utf8 utf8::decode($string) if HAVE_UTF8; # Check for some special cases return $self unless length $string; unless ( $string =~ /[\012\015]+\z/ ) { return $self->_error("Stream does not end with newline character"); } # Split the file into lines my @lines = grep { ! /^\s*(?:\#.*)?\z/ } split /(?:\015{1,2}\012|\015|\012)/, $string; # Strip the initial YAML header @lines and $lines[0] =~ /^\%YAML[: ][\d\.]+.*\z/ and shift @lines; # A nibbling parser while ( @lines ) { # Do we have a document header? if ( $lines[0] =~ /^---\s*(?:(.+)\s*)?\z/ ) { # Handle scalar documents shift @lines; if ( defined $1 and $1 !~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/ ) { push @$self, $self->_read_scalar( "$1", [ undef ], \@lines ); next; } } if ( ! @lines or $lines[0] =~ /^(?:---|\.\.\.)/ ) { # A naked document push @$self, undef; while ( @lines and $lines[0] !~ /^---/ ) { shift @lines; } } elsif ( $lines[0] =~ /^\s*\-/ ) { # An array at the root my $document = [ ]; push @$self, $document; $self->_read_array( $document, [ 0 ], \@lines ); } elsif ( $lines[0] =~ /^(\s*)\S/ ) { # A hash at the root my $document = { }; push @$self, $document; $self->_read_hash( $document, [ length($1) ], \@lines ); } else { croak("YAML::Tiny failed to classify the line '$lines[0]'"); } } $self; } # Deparse a scalar string to the actual scalar sub _read_scalar { my ($self, $string, $indent, $lines) = @_; # Trim trailing whitespace $string =~ s/\s*\z//; # Explitic null/undef return undef if $string eq '~'; # Quotes if ( $string =~ /^\'(.*?)\'\z/ ) { return '' unless defined $1; $string = $1; $string =~ s/\'\'/\'/g; return $string; } if ( $string =~ /^\"((?:\\.|[^\"])*)\"\z/ ) { # Reusing the variable is a little ugly, # but avoids a new variable and a string copy. $string = $1; $string =~ s/\\"/"/g; $string =~ s/\\([never\\fartz]|x([0-9a-fA-F]{2}))/(length($1)>1)?pack("H2",$2):$UNESCAPES{$1}/gex; return $string; } # Special cases if ( $string =~ /^[\'\"!&]/ ) { croak("YAML::Tiny does not support a feature in line '$lines->[0]'"); } return {} if $string eq '{}'; return [] if $string eq '[]'; # Regular unquoted string return $string unless $string =~ /^[>|]/; # Error croak("YAML::Tiny failed to find multi-line scalar content") unless @$lines; # Check the indent depth $lines->[0] =~ /^(\s*)/; $indent->[-1] = length("$1"); if ( defined $indent->[-2] and $indent->[-1] <= $indent->[-2] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } # Pull the lines my @multiline = (); while ( @$lines ) { $lines->[0] =~ /^(\s*)/; last unless length($1) >= $indent->[-1]; push @multiline, substr(shift(@$lines), length($1)); } my $j = (substr($string, 0, 1) eq '>') ? ' ' : "\n"; my $t = (substr($string, 1, 1) eq '-') ? '' : "\n"; return join( $j, @multiline ) . $t; } # Parse an array sub _read_array { my ($self, $array, $indent, $lines) = @_; while ( @$lines ) { # Check for a new document if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) { while ( @$lines and $lines->[0] !~ /^---/ ) { shift @$lines; } return 1; } # Check the indent level $lines->[0] =~ /^(\s*)/; if ( length($1) < $indent->[-1] ) { return 1; } elsif ( length($1) > $indent->[-1] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } if ( $lines->[0] =~ /^(\s*\-\s+)[^\'\"]\S*\s*:(?:\s+|$)/ ) { # Inline nested hash my $indent2 = length("$1"); $lines->[0] =~ s/-/ /; push @$array, { }; $self->_read_hash( $array->[-1], [ @$indent, $indent2 ], $lines ); } elsif ( $lines->[0] =~ /^\s*\-(\s*)(.+?)\s*\z/ ) { # Array entry with a value shift @$lines; push @$array, $self->_read_scalar( "$2", [ @$indent, undef ], $lines ); } elsif ( $lines->[0] =~ /^\s*\-\s*\z/ ) { shift @$lines; unless ( @$lines ) { push @$array, undef; return 1; } if ( $lines->[0] =~ /^(\s*)\-/ ) { my $indent2 = length("$1"); if ( $indent->[-1] == $indent2 ) { # Null array entry push @$array, undef; } else { # Naked indenter push @$array, [ ]; $self->_read_array( $array->[-1], [ @$indent, $indent2 ], $lines ); } } elsif ( $lines->[0] =~ /^(\s*)\S/ ) { push @$array, { }; $self->_read_hash( $array->[-1], [ @$indent, length("$1") ], $lines ); } else { croak("YAML::Tiny failed to classify line '$lines->[0]'"); } } elsif ( defined $indent->[-2] and $indent->[-1] == $indent->[-2] ) { # This is probably a structure like the following... # --- # foo: # - list # bar: value # # ... so lets return and let the hash parser handle it return 1; } else { croak("YAML::Tiny failed to classify line '$lines->[0]'"); } } return 1; } # Parse an array sub _read_hash { my ($self, $hash, $indent, $lines) = @_; while ( @$lines ) { # Check for a new document if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) { while ( @$lines and $lines->[0] !~ /^---/ ) { shift @$lines; } return 1; } # Check the indent level $lines->[0] =~ /^(\s*)/; if ( length($1) < $indent->[-1] ) { return 1; } elsif ( length($1) > $indent->[-1] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } # Get the key unless ( $lines->[0] =~ s/^\s*([^\'\" ][^\n]*?)\s*:(\s+|$)// ) { if ( $lines->[0] =~ /^\s*[?\'\"]/ ) { croak("YAML::Tiny does not support a feature in line '$lines->[0]'"); } croak("YAML::Tiny failed to classify line '$lines->[0]'"); } my $key = $1; # Do we have a value? if ( length $lines->[0] ) { # Yes $hash->{$key} = $self->_read_scalar( shift(@$lines), [ @$indent, undef ], $lines ); } else { # An indent shift @$lines; unless ( @$lines ) { $hash->{$key} = undef; return 1; } if ( $lines->[0] =~ /^(\s*)-/ ) { $hash->{$key} = []; $self->_read_array( $hash->{$key}, [ @$indent, length($1) ], $lines ); } elsif ( $lines->[0] =~ /^(\s*)./ ) { my $indent2 = length("$1"); if ( $indent->[-1] >= $indent2 ) { # Null hash entry $hash->{$key} = undef; } else { $hash->{$key} = {}; $self->_read_hash( $hash->{$key}, [ @$indent, length($1) ], $lines ); } } } } return 1; } # Set error sub _error { $YAML::Tiny::errstr = $_[1]; undef; } # Retrieve error sub errstr { $YAML::Tiny::errstr; } ##################################################################### # Use Scalar::Util if possible, otherwise emulate it BEGIN { eval { require Scalar::Util; }; if ( $@ ) { # Failed to load Scalar::Util eval <<'END_PERL'; sub refaddr { my $pkg = ref($_[0]) or return undef; if (!!UNIVERSAL::can($_[0], 'can')) { bless $_[0], 'Scalar::Util::Fake'; } else { $pkg = undef; } "$_[0]" =~ /0x(\w+)/; my $i = do { local $^W; hex $1 }; bless $_[0], $pkg if defined $pkg; $i; } END_PERL } else { Scalar::Util->import('refaddr'); } } ##################################################################### # main test ##################################################################### package main; BEGIN { # Skip modules that either don't want to be loaded directly, such as # Module::Install, or that mess with the test count, such as the Test::* # modules listed here. # # Moose::Role conflicts if Moose is loaded as well, but Moose::Role is in # the Moose distribution and it's certain that someone who uses # Moose::Role also uses Moose somewhere, so if we disallow Moose::Role, # we'll still get the relevant version number. my %skip = map { $_ => 1 } qw( App::FatPacker Class::Accessor::Classy Devel::Cover Module::Install Moose::Role POE::Loop::Tk Template::Test Test::Kwalitee Test::Pod::Coverage Test::Portability::Files Test::YAML::Meta open ); my $Test = Test::Builder->new; $Test->plan(skip_all => "META.yml could not be found") unless -f 'META.yml' and -r _; my $meta = (Local::YAML::Tiny->read('META.yml'))->[0]; my %requires; for my $require_key (grep { /requires/ } keys %$meta) { my %h = %{ $meta->{$require_key} }; $requires{$_}++ for keys %h; } delete $requires{perl}; diag("Testing with Perl $], $^X"); for my $module (sort keys %requires) { if ($skip{$module}) { note "$module doesn't want to be loaded directly, skipping"; next; } local $SIG{__WARN__} = sub { note "$module: $_[0]" }; require_ok $module or BAIL_OUT("can't load $module"); my $version = $module->VERSION; $version = 'undefined' unless defined $version; diag(" $module version is $version"); } done_testing; } POE-Component-Client-DNS-1.054/t/01_resolve.t000644 000765 000024 00000011722 12621127646 020477 0ustar00trocstaff000000 000000 #!/usr/bin/perl -w use strict; use lib '/home/troc/perl/poe'; sub POE::Kernel::ASSERT_DEFAULT () { 1 } use POE qw(Component::Client::DNS); use Test::More tests => 4; use Test::NoWarnings; sub DNS_TIMEOUT () { 3 }; sub DEBUG () { 0 }; #------------------------------------------------------------------------------ # A bunch of hostnames to resolve. my @hostnames = qw( altavista.com google.com yahoo.com 127.0.0.1 10.0.0.25 localhost poe.dynodns.net poe.perl.org poe.whee efnet.demon.co.uk efnet.telstra.net.au irc.Prison.NET irc.best.net irc.ced.chalmers.se irc.colorado.edu irc.concentric.net irc.core.com irc.du.se irc.east.gblx.net irc.ef.net irc.emory.edu irc.enitel.no irc.etsmtl.ca irc.exodus.net irc.fasti.net irc.freei.net irc.gigabell.de irc.homelien.no irc.ins.net.uk irc.inter.net.il irc.lagged.org irc.lightning.net irc.magic.ca irc.mcs.net irc.mindspring.com irc.mpl.net irc.plur.net irc.powersurfr.com irc.rt.ru irc.skynetweb.com irc.stanford.edu irc.total.net irc.umich.edu irc.umn.edu irc.west.gblx.net irc2.home.com poe.dynodns.net poe.perl.org ); #------------------------------------------------------------------------------ # This session uses the resolver component to resolve things. sub client_start { my ($kernel, $heap) = @_[KERNEL, HEAP]; # We should not hang even if we have an alias. $kernel->alias_set("oh, something"); # Response types. $heap->{answers} = 0; $heap->{timeouts} = 0; $heap->{no_answers} = 0; $heap->{errors} = 0; # Response record types. $heap->{a_records} = 0; $heap->{mx_records} = 0; $heap->{cname_records} = 0; $heap->{other_records} = 0; # Post a bunch of requests all at once. I have seen this fail with # more than 16 requests. foreach my $hostname (@hostnames) { $kernel->post( 'resolver', # Post the request to the 'resolver'. 'resolve', # Ask it to 'resolve' an address. 'response', # Have it post a reply to my 'response' state. $hostname, # This is the host we are asking about. 'ANY', # This is the list of records we want. ); } DEBUG and warn "client started...\n"; # Start time to make sure the resolver's working in parallel. $heap->{start_time} = time(); } sub client_got_response { my $heap = $_[HEAP]; my $request_address = $_[ARG0]->[0]; my ($net_dns_packet, $net_dns_resolver_errorstring) = @{$_[ARG1]}; unless (defined $net_dns_packet) { DEBUG and warn sprintf( "%25s (%-10.10s) %s\n", $request_address, 'error', $net_dns_resolver_errorstring ); if ($net_dns_resolver_errorstring eq 'timeout') { $heap->{timeouts}++; } else { $heap->{errors}++; } return; } my @answers = $net_dns_packet->answer; unless (@answers) { DEBUG and warn sprintf( "%25s (%-10.10s) %s\n", $request_address, '...none...', 'no resolver response' ); $heap->{no_answers}++; return; } $heap->{answers}++; foreach (@answers) { my $response_data_string = $_->rdatastr; my $response_data_type = $_->type; DEBUG and warn sprintf( "%25s (%-10.10s) %-s\n", $request_address, $_->type, $response_data_string ); if ($response_data_type eq 'A') { $heap->{a_records}++; } elsif ($response_data_type eq 'MX') { $heap->{mx_records}++; } elsif ($response_data_type eq 'CNAME') { $heap->{cname_records}++; } else { $heap->{other_records}++; } } } sub client_stop { my $heap = $_[HEAP]; if (DEBUG) { warn "answers : $heap->{answers}\n"; warn "timeouts : $heap->{timeouts}\n"; warn "no answers : $heap->{no_answers}\n"; warn "errors : $heap->{errors}\n"; warn "a records : $heap->{a_records}\n"; warn "mx records : $heap->{mx_records}\n"; warn "cname records: $heap->{cname_records}\n"; warn "other records: $heap->{other_records}\n"; } is( $heap->{answers} + $heap->{no_answers} + $heap->{timeouts} + $heap->{errors}, scalar(@hostnames), "expected number of outcomes" ); ok( $heap->{a_records} + $heap->{mx_records} + $heap->{cname_records} + $heap->{other_records} >= $heap->{answers}, "got enough records" ); # Cut some slack for people running on really really slow systems. ok( time() - $heap->{start_time} < (DNS_TIMEOUT * @hostnames) / 2, "tests ran sufficiently quickly" ); DEBUG and warn "client stopped...\n"; } #------------------------------------------------------------------------------ # Create a resolver component. POE::Component::Client::DNS->spawn( Alias => 'resolver', # This is the name it'll be know by. Timeout => DNS_TIMEOUT, # This is the query timeout. ); # Create a session that will use the resolver. POE::Session->create( inline_states => { _start => \&client_start, _stop => \&client_stop, response => \&client_got_response, } ); # Run it all until done. $poe_kernel->run(); exit; POE-Component-Client-DNS-1.054/t/02_tag_args.t000644 000765 000024 00000001204 12621127646 020602 0ustar00trocstaff000000 000000 #!/usr/bin/perl -w # tag@cpan.org use strict; use POE qw(Component::Client::DNS); use Data::Dumper; use Test::More tests => 5; use Test::NoWarnings; my $reverse = "127.0.0.1"; POE::Component::Client::DNS->spawn( Alias => 'named', Timeout => 5, ); POE::Session->create( inline_states => { _start => sub { for (1..4) { $_[KERNEL]->post( named => resolve => [ reverse => "TEST WORKED" ] => $reverse, 'PTR' ); } }, _stop => sub { }, # for asserts reverse => sub { is( $_[ARG0][3], "TEST WORKED", "test worked" ); }, } ); POE::Kernel->run; exit 0; POE-Component-Client-DNS-1.054/t/03_api_3.t000644 000765 000024 00000002663 12621127646 020021 0ustar00trocstaff000000 000000 #!/usr/bin/perl -w # vim: filetype=perl # Test the version 3 API. use strict; sub POE::Kernel::ASSERT_DEFAULT () { 1 } use POE qw(Component::Client::DNS); use Test::More tests => 5; use Test::NoWarnings; POE::Component::Client::DNS->spawn( Alias => 'named', Timeout => 5, ); POE::Session->create( inline_states => { _start => \&start_tests, response => \&got_response, _stop => sub { }, # avoid assert problems } ); POE::Kernel->run(); exit; sub start_tests { my $request = 1; # Default IN A. Override timeout. $_[KERNEL]->post( named => resolve => { event => "response", host => "localhost", context => $request++, timeout => 30, }, ); # Default IN A. Not found in /etc/hosts. $_[KERNEL]->post( named => resolve => { event => "response", host => "google.com", context => $request++, timeout => 30, }, ); # IN PTR $_[KERNEL]->post( named => resolve => { event => "response", host => "127.0.0.1", class => "IN", type => "PTR", context => $request++, }, ); # Small timeout. $_[KERNEL]->post( named => resolve => { event => "response", host => "google.com", context => $request++, timeout => 0.001, }, ); } sub got_response { my ($request, $response) = @_[ARG0, ARG1]; ok($request->{context}, "got response $request->{context}"); } POE-Component-Client-DNS-1.054/t/04_errors.t000644 000765 000024 00000003643 12621127646 020342 0ustar00trocstaff000000 000000 #!/usr/bin/perl -w # vim: filetype=perl # Deliberately trigger errors. use strict; sub POE::Kernel::CATCH_EXCEPTIONS () { 0 } use POE qw(Component::Client::DNS); use Test::More tests => 10; use Test::NoWarnings; # Avoid a warning. POE::Kernel->run(); { eval { POE::Component::Client::DNS->spawn(1); }; my $err = $@; $err =~ s/ at \S+ line \d+.*//s; is( $err, "POE::Component::Client::DNS requires an even number of parameters" ); } { eval { POE::Component::Client::DNS->spawn(moo => "nope"); }; my $err = $@; $err =~ s/ at \S+ line \d+.*//s; is( $err, "POE::Component::Client::DNS doesn't know these parameters: moo" ); } my $resolver = POE::Component::Client::DNS->spawn(); { eval { $poe_kernel->call( "resolver", "resolve", { } ); }; my $err = $@; $err =~ s/ at \S+ line \d+.*//s; is($err, "Must include an 'event' in Client::DNS request"); } { eval { $poe_kernel->call( "resolver", "resolve", { event => "moo", } ); }; my $err = $@; $err =~ s/ at \S+ line \d+.*//s; is($err, "Must include a 'context' in Client::DNS request"); } { eval { $poe_kernel->call( "resolver", "resolve", { event => "moo", context => "bar", } ); }; my $err = $@; $err =~ s/ at \S+ line \d+.*//s; is($err, "Must include a 'host' in Client::DNS request"); } { eval { $resolver->resolve(1); }; my $err = $@; $err =~ s/ at \S+ line \d+.*//s; is($err, "resolve() needs an even number of parameters"); } { eval { $resolver->resolve(); }; my $err = $@; $err =~ s/ at \S+ line \d+.*//s; is($err, "resolve() must include an 'event'"); } { eval { $resolver->resolve( event => "moo", ); }; my $err = $@; $err =~ s/ at \S+ line \d+.*//s; is($err, "resolve() must include a 'context'"); } { eval { $resolver->resolve( event => "moo", context => "bar", ); }; my $err = $@; $err =~ s/ at \S+ line \d+.*//s; is($err, "resolve() must include a 'host'"); } exit; POE-Component-Client-DNS-1.054/t/05_api_4.t000644 000765 000024 00000002676 12621127646 020030 0ustar00trocstaff000000 000000 #!/usr/bin/perl -w # vim: filetype=perl # Test the version 3 API. use strict; sub POE::Kernel::ASSERT_DEFAULT () { 1 } use POE qw(Component::Client::DNS); use Test::More tests => 6; use Test::NoWarnings; my $resolver = POE::Component::Client::DNS->spawn( Alias => 'named', Timeout => 5, ); POE::Session->create( inline_states => { _start => \&start_tests, _stop => sub { }, # avoid assert problems response => \&got_response, } ); POE::Kernel->run(); exit; sub start_tests { my $request = 1; # Default IN A. Override timeout. $resolver->resolve( event => "response", host => "localhost", context => $request++, timeout => 30, ); # Default IN A. Not found in /etc/hosts. $resolver->resolve( event => "response", host => "google.com", context => $request++, timeout => 30, ); # IN PTR $resolver->resolve( event => "response", host => "127.0.0.1", class => "IN", type => "PTR", context => $request++, ); # Small timeout. $resolver->resolve( event => "response", host => "google.com", context => $request++, timeout => 0.001, ); $resolver->resolve( event => "response", host => "google.com", context => $request++, nameservers => ['8.8.8.8', '8.8.4.4'], ); } sub got_response { my ($request, $response) = @_[ARG0, ARG1]; ok($request->{context}, "got response $request->{context}"); } POE-Component-Client-DNS-1.054/t/06_hosts.t000644 000765 000024 00000007000 12621127646 020157 0ustar00trocstaff000000 000000 #!/usr/bin/perl # vim: filetype=perl # Test the hosts file stuff. use warnings; use strict; sub POE::Kernel::ASSERT_DEFAULT () { 1 } use POE qw(Component::Client::DNS); use Test::More tests => 5; use Test::NoWarnings; require Net::DNS; my $can_resolve = Net::DNS::Resolver->new->search("poe.perl.org"); my %target_address; if ($can_resolve) { foreach ($can_resolve->answer()) { $target_address{$_->address} = 1 if $_->type eq "A"; } } use constant HOSTS_FILE => "./test-hosts"; my $resolver = POE::Component::Client::DNS->spawn( Alias => 'named', Timeout => 15, HostsFile => HOSTS_FILE, ); POE::Session->create( inline_states => { _start => \&start_tests, _stop => sub { }, # avoid assert problems response_no_hosts => \&response_no_hosts, response_hosts_match_v4 => \&response_hosts_match_v4, response_hosts_match_v6 => \&response_hosts_match_v6, response_hosts_nomatch => \&response_hosts_nomatch, } ); POE::Kernel->run(); exit; sub start_tests { # 1. Test without a hosts file. unlink HOSTS_FILE; $resolver->resolve( event => "response_no_hosts", host => "poe.perl.org", context => "whatever", ); } sub response_no_hosts { my $response = $_[ARG0]; my $address = a_data($response); SKIP: { skip "Can't resolve with Net::DNS, network probably not available", 1 unless($can_resolve); ok( exists $target_address{$address}, "lookup with no hosts file ($address)" ); } # 2. Test with a hosts file that contains a host match. unlink HOSTS_FILE; # Changes inode! open(HF, ">" . HOSTS_FILE) or die "couldn't write hosts file: $!"; print HF "123.45.67.89 poe.perl.org\n"; print HF "::1 hocallost\n"; close HF; $resolver->resolve( event => "response_hosts_match_v4", host => "poe.perl.org", context => "whatever", ); } sub response_hosts_match_v4 { my $response = $_[ARG0]; my $address = a_data($response); ok( $address eq "123.45.67.89", "lookup when hosts file matches ($address)" ); $resolver->resolve( event => "response_hosts_match_v6", host => "hocallost", context => "whatever", type => "AAAA", ); } sub response_hosts_match_v6 { my $response = $_[ARG0]; my $address = aaaa_data($response); ok( ($address eq "0:0:0:0:0:0:0:1" or $address eq "::1"), "ipv6 lookup when hosts file matches ($address)" ); # 3. Test against a hosts file without a host match. unlink HOSTS_FILE; # Changes inode! open(HF, ">" . HOSTS_FILE) or die "couldn't write hosts file: $!"; print HF "123.456.789.012 narf.barf.warf\n"; close HF; $resolver->resolve( event => "response_hosts_nomatch", host => "poe.perl.org", context => "whatever", ); } sub response_hosts_nomatch { my $response = $_[ARG0]; my $address = a_data($response); SKIP: { skip "Can't resolve with Net::DNS, network probably not available", 1 unless($can_resolve); ok( exists $target_address{$address}, "lookup with hosts file but no match ($address)" ); } unlink HOSTS_FILE; } ### Not POE event handlers. sub a_data { my $response = shift; return "" unless defined $response->{response}; return ( grep { ref() eq "Net::DNS::RR::A" } $response->{response}->answer() )[0]->rdatastr(); } sub aaaa_data { my $response = shift; return "" unless defined $response->{response}; return ( grep { ref() eq "Net::DNS::RR::AAAA" } $response->{response}->answer() )[0]->rdatastr(); } POE-Component-Client-DNS-1.054/t/author-pod-coverage.t000644 000765 000024 00000000565 12621127646 022376 0ustar00trocstaff000000 000000 #!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for testing by the author'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); POE-Component-Client-DNS-1.054/t/author-pod-syntax.t000644 000765 000024 00000000503 12621127646 022121 0ustar00trocstaff000000 000000 #!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for testing by the author'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); POE-Component-Client-DNS-1.054/lib/POE/000755 000765 000024 00000000000 12621127646 017256 5ustar00trocstaff000000 000000 POE-Component-Client-DNS-1.054/lib/POE/Component/000755 000765 000024 00000000000 12621127646 021220 5ustar00trocstaff000000 000000 POE-Component-Client-DNS-1.054/lib/POE/Component/Client/000755 000765 000024 00000000000 12621127646 022436 5ustar00trocstaff000000 000000 POE-Component-Client-DNS-1.054/lib/POE/Component/Client/DNS.pm000644 000765 000024 00000056472 12621127646 023436 0ustar00trocstaff000000 000000 # License and documentation are after __END__. # vim: ts=2 sw=2 expandtab package POE::Component::Client::DNS; $POE::Component::Client::DNS::VERSION = '1.054'; use strict; use Carp qw(croak); use Socket qw(unpack_sockaddr_in inet_ntoa); use Net::DNS; use POE; use constant DEBUG => 0; # A hosts file we found somewhere. my $global_hosts_file; # Object fields. "SF" stands for "self". use constant SF_ALIAS => 0; use constant SF_TIMEOUT => 1; use constant SF_NAMESERVERS => 2; use constant SF_RESOLVER => 3; use constant SF_HOSTS_FILE => 4; use constant SF_HOSTS_MTIME => 5; use constant SF_HOSTS_CTIME => 6; use constant SF_HOSTS_INODE => 7; use constant SF_HOSTS_CACHE => 8; use constant SF_HOSTS_BYTES => 9; use constant SF_SHUTDOWN => 10; use constant SF_REQ_BY_SOCK => 11; # Spawn a new PoCo::Client::DNS session. This basically is a # constructor, but it isn't named "new" because it doesn't create a # usable object. Instead, it spawns the object off as a session. sub spawn { my $type = shift; croak "$type requires an even number of parameters" if @_ % 2; my %params = @_; my $alias = delete $params{Alias}; $alias = "resolver" unless $alias; my $timeout = delete $params{Timeout}; $timeout = 90 unless $timeout; my $nameservers = delete $params{Nameservers}; my $resolver = Net::DNS::Resolver->new(); $nameservers ||= [ $resolver->nameservers() ]; my $hosts = delete $params{HostsFile}; croak( "$type doesn't know these parameters: ", join(', ', sort keys %params) ) if scalar keys %params; # TODO - SF_NAMESERVERS isn't used right now. It exists for future # expansion. my $self = bless [ $alias, # SF_ALIAS $timeout, # SF_TIMEOUT $nameservers, # SF_NAMESERVERS $resolver, # SF_RESOLVER $hosts, # SF_HOSTS_FILE 0, # SF_HOSTS_MTIME 0, # SF_HOSTS_CTIME 0, # SF_HOSTS_INODE { }, # SF_HOSTS_CACHE 0, # SF_HOSTS_BYTES 0, # SF_SHUTDOWN ], $type; # Set the list of nameservers, if one was supplied. # May redundantly reset itself. $self->[SF_RESOLVER]->nameservers(@$nameservers); POE::Session->create( object_states => [ $self => { _default => "_dns_default", _start => "_dns_start", _stop => "_dns_stop", got_dns_response => "_dns_response", resolve => "_dns_resolve", send_request => "_dns_do_request", shutdown => "_dns_shutdown", }, ], ); return $self; } # Public method interface. sub resolve { my $self = shift; croak "resolve() needs an even number of parameters" if @_ % 2; my %args = @_; croak "resolve() must include an 'event'" unless exists $args{event}; croak "resolve() must include a 'context'" unless exists $args{context}; croak "resolve() must include a 'host'" unless exists $args{host}; $poe_kernel->call( $self->[SF_ALIAS], "resolve", \%args ); return undef; } sub shutdown { my $self = shift; $poe_kernel->call( $self->[SF_ALIAS], "shutdown" ); } # Start the resolver session. Record the parameters which were # validated in spawn(), create the internal resolver object, and set # an alias which we'll be known by. sub _dns_start { my ($object, $kernel) = @_[OBJECT, KERNEL]; $kernel->alias_set($object->[SF_ALIAS]); } # Dummy handler to avoid ASSERT_DEFAULT problems. sub _dns_stop { # do nothing } # Receive a request. Version 4 API. This uses extra reference counts # to keep the client sessions alive until responses are ready. sub _dns_resolve { my ($self, $kernel, $sender, $event, $host, $type, $class) = @_[OBJECT, KERNEL, SENDER, ARG0, ARG1, ARG2, ARG3]; my $debug_info = "in Client::DNS request at $_[CALLER_FILE] line $_[CALLER_LINE]\n"; my ($api_version, $context, $timeout); my @nameservers; # Version 3 API. Pass the entire request as a hash. if (ref($event) eq 'HASH') { my %args = %$event; $type = delete $args{type}; $type = "A" unless $type; $class = delete $args{class}; $class = "IN" unless $class; $event = delete $args{event}; die "Must include an 'event' $debug_info" unless $event; $context = delete $args{context}; die "Must include a 'context' $debug_info" unless $context; $timeout = delete $args{timeout}; @nameservers = @{delete $args{nameservers}} if $args{nameservers}; $host = delete $args{host}; die "Must include a 'host' $debug_info" unless $host; $api_version = 3; } # Parse user args from the magical $response format. Version 2 API. elsif (ref($event) eq "ARRAY") { $context = $event; $event = shift @$context; $api_version = 2; } # Whee. Version 1 API. else { $context = [ ]; $api_version = 1; } @nameservers = @{ $self->[SF_NAMESERVERS] } unless @nameservers; # Default the request's timeout. $timeout = $self->[SF_TIMEOUT] unless $timeout; # Set an extra reference on the sender so it doesn't go away. $kernel->refcount_increment($sender->ID, __PACKAGE__); # If it's an IN type A request, check /etc/hosts or the equivalent. # -><- This is not always the right thing to do, but it's more right # more often than never checking at all. if (($type eq "A" or $type eq "AAAA") and $class eq "IN") { my $address = $self->_check_hosts_file($host, $type); if (defined $address) { # Pretend the request went through a name server. my $packet = Net::DNS::Packet->new($address, $type, "IN"); $packet->push( "answer", Net::DNS::RR->new( Name => $host, TTL => 1, Class => $class, Type => $type, Address => $address, ) ); # Send the response immediately, and return. _send_response( api_ver => $api_version, sender => $sender, event => $event, host => $host, type => $type, class => $class, context => $context, response => $packet, error => "", ); return; } } # We are here. Yield off to the state where the request will be # sent. This is done so that the do-it state can yield or delay # back to itself for retrying. my $now = time(); $kernel->call( $self->[SF_ALIAS], send_request => { sender => $sender, event => $event, host => $host, type => $type, class => $class, context => $context, started => $now, ends => $now + $timeout, api_ver => $api_version, nameservers => \@nameservers, } ); } # Perform the real request. May recurse to perform retries. sub _dns_do_request { my ($self, $kernel, $req) = @_[OBJECT, KERNEL, ARG0]; # Did the request time out? my $remaining = $req->{ends} - time(); if ($remaining <= 0) { _send_response( %$req, response => undef, error => "timeout", ); return; } # Send the request. $self->[SF_RESOLVER]->nameservers( @{ $req->{nameservers} || $self->[SF_NAMESERVERS] } ); my $resolver_ref = $self->[SF_RESOLVER]->bgsend( $req->{host}, $req->{type}, $req->{class} ); # The request failed? Attempt to retry. unless ($resolver_ref) { $remaining = 1 if $remaining > 1; $kernel->delay_add(send_request => $remaining, $req); return; } my $resolver_socket; if ( ref( $resolver_ref ) eq 'IO::Select' ) { ($resolver_socket) = [ $resolver_ref->handles ]->[0][0]; } else { $resolver_socket = $resolver_ref; } $req->{RES_REF} = $resolver_ref; # Set a timeout for the request, and watch the response socket for # activity. $self->[SF_REQ_BY_SOCK]->{$resolver_socket} = $req; $kernel->delay($resolver_socket, $remaining / 2, $resolver_socket); $kernel->select_read($resolver_socket, 'got_dns_response'); # Save the socket for pre-emptive shutdown. $req->{resolver_socket} = $resolver_socket; } # A resolver query timed out. Keep trying until we run out of time. # Also, if the top nameserver is the one we tried, then cycle the # nameservers. sub _dns_default { my ($self, $kernel, $event, $args) = @_[OBJECT, KERNEL, ARG0, ARG1]; my $socket = $args->[0]; return unless defined($socket) and $event eq $socket; my $req = delete $self->[SF_REQ_BY_SOCK]->{$socket}; return unless $req; # Stop watching the socket. $kernel->select_read($socket); # No more time remaining? We must time out. my $remaining = $req->{ends} - time(); if ($remaining <= 0) { _send_response( %$req, response => undef, error => "timeout", ); return; } # There remains time. Let's try again. # The nameserver we tried has failed us. If it's the top # nameserver in Net::DNS's list, then send it to the back and retry. # TODO - What happens if they all fail forever? my @nameservers = @{ $req->{nameservers} }; push @nameservers, shift(@nameservers); $self->[SF_RESOLVER]->nameservers(@nameservers); $req->{nameservers} = \@nameservers; # Retry. $kernel->yield(send_request => $req); # Don't accidentally handle signals. # Only meaningful for old POEs. return; } # A resolver query generated a response. Post the reply back. sub _dns_response { my ($self, $kernel, $socket) = @_[OBJECT, KERNEL, ARG0]; my $req = delete $self->[SF_REQ_BY_SOCK]->{$socket}; return unless $req; # Turn off the timeout for this request, and stop watching the # resolver connection. $kernel->delay($socket); $kernel->select_read($socket); my $handle = delete $req->{RES_REF}; # Read the DNS response. my $packet = $self->[SF_RESOLVER]->bgread($handle); # Set the packet's answerfrom field, if the packet was received ok # and an answerfrom isn't already included. This uses the # documented peerhost() method if (defined $packet and !defined $packet->answerfrom) { my $answerfrom = getpeername($socket); if (defined $answerfrom) { $answerfrom = (unpack_sockaddr_in($answerfrom))[1]; $answerfrom = inet_ntoa($answerfrom); $packet->answerfrom($answerfrom); } } # Send the response. _send_response( %$req, response => $packet, error => $self->[SF_RESOLVER]->errorstring(), ); } sub _dns_shutdown { my ($self, $kernel) = @_[OBJECT, KERNEL]; # Clean up all pending socket timeouts and selects. foreach my $socket (keys %{$self->[SF_REQ_BY_SOCK]}) { DEBUG and warn "SHT: Shutting down resolver socket $socket"; my $req = delete $self->[SF_REQ_BY_SOCK]->{$socket}; $kernel->delay($socket); $kernel->select($req->{resolver_socket}); # Let the client session go. DEBUG and warn "SHT: Releasing sender ", $req->{sender}->ID; $poe_kernel->refcount_decrement($req->{sender}->ID, __PACKAGE__); } # Clean out our global timeout. $kernel->delay(send_request => undef); # Clean up our global alias. DEBUG and warn "SHT: Resolver removing alias $self->[SF_ALIAS]"; $kernel->alias_remove($self->[SF_ALIAS]); $self->[SF_SHUTDOWN] = 1; } # Send a response. Fake a postback for older API versions. Send a # nice, tidy hash for new ones. Also decrement the reference count # that's keeping the requester session alive. sub _send_response { my %args = @_; # Simulate a postback for older API versions. my $api_version = delete $args{api_ver}; if ($api_version < 3) { $poe_kernel->post( $args{sender}, $args{event}, [ $args{host}, $args{type}, $args{class}, @{$args{context}} ], [ $args{response}, $args{error} ], ); } # New, fancy, shiny hash-based response. else { $poe_kernel->post( $args{sender}, $args{event}, { host => $args{host}, type => $args{type}, class => $args{class}, context => $args{context}, response => $args{response}, error => $args{error}, } ); } # Let the client session go. $poe_kernel->refcount_decrement($args{sender}->ID, __PACKAGE__); } ### NOT A POE EVENT HANDLER sub _check_hosts_file { my ($self, $host, $type) = @_; # Use the hosts file that was specified, or find one. my $use_hosts_file; if (defined $self->[SF_HOSTS_FILE]) { $use_hosts_file = $self->[SF_HOSTS_FILE]; } else { # Discard the hosts file name if it has disappeared. $global_hosts_file = undef if ( $global_hosts_file and !-f $global_hosts_file ); # Try to find a hosts file if one doesn't exist. unless ($global_hosts_file) { my @candidates = ( "/etc/hosts", ); if ( $^O eq 'android' ) { push @candidates, "/system/etc/hosts"; } if ($^O eq "MSWin32" or $^O eq "Cygwin") { my $sys_dir; $sys_dir = $ENV{SystemRoot} || "c:\\Windows"; push( @candidates, "$sys_dir\\System32\\Drivers\\Etc\\hosts", "$sys_dir\\System\\Drivers\\Etc\\hosts", "$sys_dir\\hosts", ); } foreach my $candidate (@candidates) { next unless -f $candidate; $global_hosts_file = $candidate; $global_hosts_file =~ s/\\+/\//g; $self->[SF_HOSTS_MTIME] = 0; $self->[SF_HOSTS_CTIME] = 0; $self->[SF_HOSTS_INODE] = 0; last; } } # We use the global hosts file. $use_hosts_file = $global_hosts_file; } # Still no hosts file? Don't bother reading it, then. return unless $use_hosts_file; # Blow away our cache if the file doesn't exist. $self->[SF_HOSTS_CACHE] = { } unless -f $use_hosts_file; # Reload the hosts file if times have changed. my ($inode, $bytes, $mtime, $ctime) = (stat $use_hosts_file)[1, 7, 9,10]; unless ( $self->[SF_HOSTS_MTIME] == ($mtime || -1) and $self->[SF_HOSTS_CTIME] == ($ctime || -1) and $self->[SF_HOSTS_INODE] == ($inode || -1) and $self->[SF_HOSTS_BYTES] == ($bytes || -1) ) { return unless open(HOST, "<", $use_hosts_file); my %cached_hosts; while () { next if /^\s*\#/; # skip all-comment lines next if /^\s*$/; # skip empty lines chomp; # Bare split discards leading and trailing whitespace. my ($address, @aliases) = split; next unless defined $address; my $type = ($address =~ /:/) ? "AAAA" : "A"; foreach my $alias (@aliases) { $cached_hosts{$alias}{$type}{$address} = 1; } } close HOST; # Normalize our cached hosts. while (my ($alias, $type_rec) = each %cached_hosts) { while (my ($type, $address_rec) = each %$type_rec) { $cached_hosts{$alias}{$type} = (keys %$address_rec)[0]; } } $self->[SF_HOSTS_CACHE] = \%cached_hosts; $self->[SF_HOSTS_MTIME] = $mtime; $self->[SF_HOSTS_CTIME] = $ctime; $self->[SF_HOSTS_INODE] = $inode; $self->[SF_HOSTS_BYTES] = $bytes; } # Return whatever match we have. return unless ( (exists $self->[SF_HOSTS_CACHE]{$host}) and (exists $self->[SF_HOSTS_CACHE]{$host}{$type}) ); return $self->[SF_HOSTS_CACHE]{$host}{$type}; } ### NOT A POE EVENT HANDLER sub get_resolver { my $self = shift; return $self->[SF_RESOLVER]; } 1; __END__ =head1 NAME POE::Component::Client::DNS - non-blocking, parallel DNS client =head1 VERSION version 1.054 =head1 SYNOPSIS use POE qw(Component::Client::DNS); my $named = POE::Component::Client::DNS->spawn( Alias => "named" ); POE::Session->create( inline_states => { _start => \&start_tests, response => \&got_response, } ); POE::Kernel->run(); exit; sub start_tests { my $response = $named->resolve( event => "response", host => "localhost", context => { }, ); if ($response) { $_[KERNEL]->yield(response => $response); } } sub got_response { my $response = $_[ARG0]; my @answers = $response->{response}->answer(); foreach my $answer (@answers) { print( "$response->{host} = ", $answer->type(), " ", $answer->rdatastr(), "\n" ); } } =head1 DESCRIPTION POE::Component::Client::DNS provides non-blocking, parallel DNS requests via Net::DNS. Using POE, it allows other tasks to run while waiting for name servers to respond. For simple name resolution, including smart handling of IPv6 names, please see L instead. =head1 PUBLIC METHODS =over 2 =item spawn A program must spawn at least one POE::Component::Client::DNS instance before it can perform background DNS requests. Each instance represents a connection to one or more name servers. If a program only needs to request DNS requests from one server, then you only need one POE::Component::Client::DNS instance. As of version 0.98 you can override the default timeout per request. From this point forward there is no need to spawn multiple instances to affect different timeouts for each request. PoCo::Client::DNS's C method takes a few named parameters: Alias sets the component's alias. Requests will be posted to this alias. The component's alias defaults to "resolver" if one is not provided. Programs spawning more than one DNS client component must specify aliases for N-1 of them, otherwise alias collisions will occur. Alias => $session_alias, # defaults to "resolver" Timeout sets the component's default timeout. The timeout may be overridden per request. See the "request" event, later on. If no Timeout is set, the component will wait 90 seconds per request by default. Timeouts may be set to real numbers. Timeouts are more accurate if you have Time::HiRes installed. POE (and thus this component) will use Time::HiRes automatically if it's available. Timeout => $seconds_to_wait, # defaults to 90 Nameservers holds a reference to a list of name servers to try. The list is passed directly to Net::DNS::Resolver's nameservers() method. By default, POE::Component::Client::DNS will query the name servers that appear in /etc/resolv.conf or its equivalent. Nameservers => \@name_servers, # defaults to /etc/resolv.conf's HostsFile (optional) holds the name of a specific hosts file to use for resolving hardcoded addresses. By default, it looks for a file named /etc/hosts. On Windows systems, it may look in the following other places: $ENV{SystemRoot}\System32\Drivers\Etc\hosts $ENV{SystemRoot}\System\Drivers\Etc\hosts $ENV{SystemRoot}\hosts =item resolve resolve() requests the component to resolve a host name. It will return a hash reference (described in RESPONSE MESSAGES, below) if it can honor the request immediately (perhaps from a cache). Otherwise it returns undef if a resolver must be consulted asynchronously. Requests are passed as a list of named fields. $resolver->resolve( class => $dns_record_class, # defaults to "IN" type => $dns_record_type, # defaults to "A" host => $request_host, # required context => $request_context, # required event => $response_event, # required timeout => $request_timeout, # defaults to spawn()'s Timeout nameservers => $nameservers, # defaults to $resolver's Nameservers ); The "class" and "type" fields specify what kind of information to return about a host. Most of the time internet addresses are requested for host names, so the class and type default to "IN" (internet) and "A" (address), respectively. The "host" field designates the host to look up. It is required. The "event" field tells the component which event to send back when a response is available. It is required, but it will not be used if resolve() can immediately return a cached response. "timeout" tells the component how long to wait for a response to this request. It defaults to the "Timeout" given at spawn() time. "context" includes some external data that links responses back to their requests. The context data is provided by the program that uses POE::Component::Client::DNS. The component will pass the context back to the program without modification. The "context" parameter is required, and may contain anything that fits in a scalar. =item shutdown shutdown() causes the component to terminate gracefully. It will finish serving pending requests then close down. =item get_resolver POE::Component::Client::DNS uses a Net::DNS::Resolver object internally. get_resolver() returns that object so it may be interrogated or modified. See L for options. Set the resolver to check on nonstandard port 1153: $poco_client_dns->get_resolver()->port(1153); =back =head1 RESPONSE MESSAGES POE::Component::Client::DNS responds in one of two ways. Its resolve() method will return a response immediately if it can be found in the component's cache. Otherwise the component posts the response back in $_[ARG0]. In either case, the response is a hash reference containing the same fields: host => $request_host, type => $request_type, class => $request_class, context => $request_context, response => $net_dns_packet, error => $net_dns_error, The "host", "type", "class", and "context" response fields are identical to those given in the request message. "response" contains a Net::DNS::Packet object on success or undef if the lookup failed. The Net::DNS::Packet object describes the response to the program's request. It may contain several DNS records. Please consult L and L for more information. "error" contains a description of any error that has occurred. It is only valid if "response" is undefined. =head1 SEE ALSO L - POE::Component::Client::DNS builds heavily on POE. L - A system name resolver, including IPv6 support and whatever else your system supports. L - This module uses Net::DNS internally. L - Responses are returned as Net::DNS::Packet objects. =head1 DEPRECATIONS The older, list-based interfaces are no longer documented as of version 0.98. They are being phased out. The method-based interface, first implementedin version 0.98, will replace the deprecated interfaces after a six-month phase-out period. Version 0.98 was released in October of 2004. The deprecated interfaces will continue to work without warnings until January 2005. As of January 2005, programs that use the deprecated interfaces will continue to work, but they will generate mandatory warnings. Those warnings will persist until April 2005. As of April 2005 the mandatory warnings will be upgraded to mandatory errors. Support for the deprecated interfaces will be removed entirely. As of late January 2011, POE::Component::Resolver provides basic system resolver support, including IPv6 and mDNS if your resolver's configured ot use it. The use of POE::Component::Client::DNS for basic resolution is deprecated, however it's still the best option for actual DNS server requests. =head1 BUG TRACKER https://rt.cpan.org/Dist/Display.html?Queue=POE-Component-Client-DNS =head1 REPOSITORY http://github.com/rcaputo/poe-component-client-dns =head1 OTHER RESOURCES http://search.cpan.org/dist/POE-Component-Client-DNS/ =head1 AUTHOR & COPYRIGHTS POE::Component::Client::DNS is Copyright 1999-2009 by Rocco Caputo. All rights are reserved. POE::Component::Client::DNS is free software; you may redistribute it and/or modify it under the same terms as Perl itself. Postback arguments were contributed by tag. =cut