AnyEvent-CacheDNS-0.08000755001750001750 012166567241 16273 5ustar00erodriguezerodriguez000000000000AnyEvent-CacheDNS-0.08/README000444001750001750 242212166567241 17310 0ustar00erodriguezerodriguez000000000000AnyEvent::CacheDNS ================== ******************************************************************************* This CPAN package provides a simple DNS resolver that caches the results for a faster retrieval for subsequent calls. This is module is very basic and has no policies for clearing our invalidating the DNS cache. Patches and suggestions are welcome. INSTALLATION To install this module type the following: perl Build.PL ./Build ./Build test ./Build install PROJECT The project is now hosted on github (http://github.com/potyl/perl-AnyEvent-CacheDNS/) which provides the latest source code and a simple bug tracking. Even tough github provides a download facility, the project's source code bundles will always be published through CPAN. It's easier this way for the project and after all this is a Perl project! BUGS Please when possible try to submit the bugs through the github issue tracker (http://github.com/potyl/perl-AnyEvent-CacheDNS/issues) otherwise simply create a ticket through RT. COPYRIGHT AND LICENCE Copyright (C) 2011 by Emmanuel Rodriguez This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. AnyEvent-CacheDNS-0.08/Build.PL000444001750001750 154212166567241 17726 0ustar00erodriguezerodriguez000000000000#!/usr/bin/perl use strict; use warnings; use Module::Build; use File::Spec::Functions; my %requires = ( perl => '5.6.1', 'AnyEvent' => 0, ); my %configure_requires = ( 'File::Spec::Functions' => 0, ); my $url_resources = 'http://github.com/potyl/perl-AnyEvent-CacheDNS'; my $build = Module::Build->new( module_name => 'AnyEvent::CacheDNS', license => 'perl', dist_author => 'Emmanuel Rodriguez ', dist_version_from => catfile('lib', 'AnyEvent', 'CacheDNS.pm'), # Dependencies requires => \%requires, configure_requires => \%configure_requires, build_requires => { %configure_requires, 'Test::More' => 0 }, meta_merge => { resources => { homepage => $url_resources, bugtracker => "$url_resources/issues", repository => $url_resources, }, }, ); $build->create_build_script(); AnyEvent-CacheDNS-0.08/META.yml000444001750001750 150312166567241 17700 0ustar00erodriguezerodriguez000000000000--- abstract: 'Simple DNS resolver with caching' author: - 'Emmanuel Rodriguez ' build_requires: File::Spec::Functions: 0 Test::More: 0 configure_requires: File::Spec::Functions: 0 Module::Build: 0.40 dynamic_config: 1 generated_by: 'Module::Build version 0.4001, CPAN::Meta::Converter version 2.110440' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: AnyEvent-CacheDNS provides: AnyEvent::CacheDNS: file: lib/AnyEvent/CacheDNS.pm version: 0.08 requires: AnyEvent: 0 perl: v5.6.1 resources: bugtracker: http://github.com/potyl/perl-AnyEvent-CacheDNS/issues homepage: http://github.com/potyl/perl-AnyEvent-CacheDNS license: http://dev.perl.org/licenses/ repository: http://github.com/potyl/perl-AnyEvent-CacheDNS version: 0.08 AnyEvent-CacheDNS-0.08/Changes000444001750001750 143112166567241 17722 0ustar00erodriguezerodriguez0000000000000.08 Mon Jul 8 18:46:51 CEST 2013 - Fixed autovivification of @_ (patch by Sergey Zhuravlev) 0.07 Wed Feb 22 21:31:53 CET 2012 - Works now with perl 5.10.0 0.06 Sat Feb 18 09:05:07 CET 2012 - Backport to perl 5.8 0.05 Sun Dec 4 17:08:02 CET 2011 - Add DNS record TTL support (patch by Brane F. Gračnar) 0.04 Wed Feb 2 04:54:20 CET 2011 - Unit test bug fix (pass even if host can't do DNS lookups) - Bug fixes: register() creates the resolver as AnyEvent::DNS::resolver() does. Version 0.02 was missing the commit that enabled this 0.03 Sun Jan 30 23:17:32 CET 2011 - Documentation and unit tests updates 0.02 Sat Jan 29 18:44:03 CET 2011 - Bug fixes: register() creates the resolver as AnyEvent::DNS::resolver() does 0.01 Wed Jan 26 21:31:29 CET 2011 - First version AnyEvent-CacheDNS-0.08/MANIFEST.SKIP000444001750001750 14712166567241 20310 0ustar00erodriguezerodriguez000000000000Build _build ^MYMETA\.yml$ ^\.git/ ^\.gitignore$ blib AnyEvent-CacheDNS-.* ^\.DS_Store$ ^MYMETA\.json$ AnyEvent-CacheDNS-0.08/META.json000444001750001750 256712166567241 20063 0ustar00erodriguezerodriguez000000000000{ "abstract" : "Simple DNS resolver with caching", "author" : [ "Emmanuel Rodriguez " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4001, CPAN::Meta::Converter version 2.110440", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "AnyEvent-CacheDNS", "prereqs" : { "build" : { "requires" : { "File::Spec::Functions" : 0, "Test::More" : 0 } }, "configure" : { "requires" : { "File::Spec::Functions" : 0, "Module::Build" : "0.40" } }, "runtime" : { "requires" : { "AnyEvent" : 0, "perl" : "v5.6.1" } } }, "provides" : { "AnyEvent::CacheDNS" : { "file" : "lib/AnyEvent/CacheDNS.pm", "version" : "0.08" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "http://github.com/potyl/perl-AnyEvent-CacheDNS/issues" }, "homepage" : "http://github.com/potyl/perl-AnyEvent-CacheDNS", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "http://github.com/potyl/perl-AnyEvent-CacheDNS" } }, "version" : "0.08" } AnyEvent-CacheDNS-0.08/MANIFEST000444001750001750 14312166567241 17537 0ustar00erodriguezerodriguez000000000000Build.PL lib/AnyEvent/CacheDNS.pm Changes MANIFEST MANIFEST.SKIP META.yml t/dns.t README META.json AnyEvent-CacheDNS-0.08/t000755001750001750 012166567241 16536 5ustar00erodriguezerodriguez000000000000AnyEvent-CacheDNS-0.08/t/dns.t000444001750001750 325212166567241 17646 0ustar00erodriguezerodriguez000000000000#!/usr/bin/perl use strict; use warnings; use Test::More tests => 11; use AnyEvent; use AnyEvent::CacheDNS ':register'; use AnyEvent::DNS; use Data::Dumper; sub main { # Make sure we timeout fast my $dns = AnyEvent::DNS::resolver; isa_ok($dns, 'AnyEvent::CacheDNS'); $dns->{timeout} = [0.5]; $dns->_compile(); my $cv; my $host = 'bee.meon.eu'; $cv = AnyEvent->condvar; $dns->resolve($host, 'a', $cv); my ($first) = $cv->recv(); if (defined $first) { ok($first, "First DNS lookup"); } else { # DNS request failed, ok as long as the second one fails too we're ok SKIP: { skip "DNS lookup for $host failed", 1; }; } $cv = AnyEvent->condvar; $dns->resolve($host, 'a', $cv); my ($second) = $cv->recv(); # Inspect the cache ok(keys %{ $dns->{_cache} } == 1, "DNS cache was used"); ok(keys %{ $dns->{_cache}{a} } == 1, "DNS cache has a sinle host"); my $cached = $dns->{_cache}{a}{$host}; if (! defined $first) { # DNS request failed, ok as long as the second one fails too we're ok ok(! defined $second, "Second DNS lookup failed, just as the first one"); # Inspect the cache ok(! defined $cached, "Cache has no record for host"); SKIP: { skip "DNS lookup for $host failed", 3; }; return 0; } ok($second, "Second DNS lookup"); is_deeply($first, $second, "DNS records identical"); ok($first == $second, "DNS records same ref"); # Check that the cache as a DNS record ok(pop @{ $cached }, "IP address is true"); is($cached->[0], $host, "Response packet host matches"); is($cached->[1], 'a', "Response packet record type matches"); is($cached->[2], 'in', "Response packet record class matches"); return 0; } exit main() unless caller; AnyEvent-CacheDNS-0.08/lib000755001750001750 012166567241 17041 5ustar00erodriguezerodriguez000000000000AnyEvent-CacheDNS-0.08/lib/AnyEvent000755001750001750 012166567241 20572 5ustar00erodriguezerodriguez000000000000AnyEvent-CacheDNS-0.08/lib/AnyEvent/CacheDNS.pm000444001750001750 755412166567241 22650 0ustar00erodriguezerodriguez000000000000package AnyEvent::CacheDNS; use strict; use warnings; use base 'AnyEvent::DNS'; use Data::Dumper; our $VERSION = '0.08'; # Detect AnyEvent >= 6.0.1 my $IS_AE_6X = version->can("parse") ? version->parse(AnyEvent->VERSION()) >= version->parse('v6.0.1') : AnyEvent->VERSION !~ /^ (?: [0-5]\. | 6\.0(?:\.0)? $ )/x; # Default TTL for AnyEvent < 6.0.1 my $DEFAULT_TTL = undef; sub import { my $package = shift; my @options = @_; while (@options) { my $key = shift @options; if ($key eq ':register') { $package->register(); } } } sub resolve { my $cb = pop @_; my ($self, $qname, $qtype, %opt) = @_; # If we have the value cached then we serve it from there my $cache = $self->{_cache}{$qtype} ||= {}; if (exists $cache->{$qname}) { my $response = $cache->{$qname}; $cb->($response ? ($response) : ()); return; } # Perform a request and cache the value $self->SUPER::resolve( $qname, $qtype, %opt, sub{ # Note that it could be possible that multiple DNS request are done # for a new qname. For instance if an application is doing multiple # concurrent HTTP request to the same host then there will be at # least one DNS request per HTTP request. That's why we only cache # the results of the first DNS request that's successful. $cache->{$qname} ||= @_ ? $_[0] : undef; # Respect TTL and be backwards compatible with AnyEvent < 6.x my $ttl = defined $DEFAULT_TTL ? $DEFAULT_TTL : ($IS_AE_6X && @_ ? int($_[0]->[3] || 0) : 0) ; if ($ttl > 0) { # Create expire timer my $wt; $wt = AE::timer($ttl, 0, sub { $wt = undef; delete($cache->{$qname}); }); } $cb->(@_); } ); } sub register { my $class = shift; my @args = ( untaint => 1, ); my $key = 'PERL_ANYEVENT_MAX_OUTSTANDING_DNS'; push @args, max_outstanding => $ENV{$key} * 1 || 1 if exists $ENV{$key}; my $resolver = $class->new(@args); if (exists $ENV{PERL_ANYEVENT_RESOLV_CONF}) { my $conf = $ENV{PERL_ANYEVENT_RESOLV_CONF}; $resolver->_parse_resolv_conf_file($conf) if length $conf; } else { $resolver->os_config(); } $DEFAULT_TTL = abs(int($ENV{PERL_ANYEVENT_DNS_TTL} || 0)) if exists $ENV{PERL_ANYEVENT_DNS_TTL}; $AnyEvent::DNS::RESOLVER = $resolver; } 1; =head1 NAME AnyEvent::CacheDNS - Simple DNS resolver with caching =head1 SYNOPSIS use AnyEvent; use AnyEvent::HTTP; # Register our DNS resolver as the default resolver use AnyEvent::CacheDNS ':register'; # Use AnyEvent as ususal my $cond = AnyEvent->condvar; http_get "http://search.cpan.org/", sub { $cond->send(); }; $cond->recv(); =head1 DESCRIPTION This module provides a very simple DNS resolver that caches its results and can improve the connection times to remote hosts. =head1 Import It's possible to register the this class as AnyEvent's main DNS resolver by passing the tag C<:register> in the C statement. =head1 METHODS =head2 register Registers a new DNS cache instance as AnyEvent's global DNS resolver. =head2 ENVIRONMENT =over =item C The effect of setting this variable differs depending on L version. =over =item AnyEvent 5.x Default DNS response record cache TTL for older AnyEvent versions. L <= 6.x doesn't report record TTL and records get cached for infinite amount of time, therefore running programs won't detect if cached DNS records have changed. B: Setting this variable to C<0> disables purging records from cache. =item AnyEvent 6.x Newer versions of AnyEvent report DNS record TTL so records will be purged from the cache after B TTL expires. Setting this variable to any positive integer B the TTL for all records to the specified value, setting variable to C<0> disables purging records from the cache. =back =back =head1 AUTHOR Emmanuel Rodriguez =head1 COPYRIGHT (C) 2011 Emmanuel Rodriguez - All Rights Reserved. =cut