-
-
18 Oct 2012 04:10:25 UTC
- Distribution: DBIx-DSN-Resolver
- Module version: 0.09
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues
- Testers (603 / 0 / 0)
- Kwalitee
Bus factor: 1- 93.24% Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (21.48KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors- Masahiro Nagano <kazeburo {at} gmail.com>
- Dependencies
- DBI
- Socket
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
DBIx::DSN::Resolver - Resolve hostname within dsn string
SYNOPSIS
use DBIx::DSN::Resolver; my $dsn = 'dbi:mysql:database=mytbl;host=myserver.example' my $resolver = DBIx::DSN::Resolver->new(); $dsn = $resolver->resolv($dsn); is $dsn, 'dbi:mysql:database=mytbl;host=10.0.9.41';
DESCRIPTION
DBIx::DSN::Resolver parses dsn string and resolves hostname within dsn. This module allows customize the resolver function.
CUSTOMIZE RESOLVER
use the resolver argument. This sample code makes resolver cache with Cache::Memory::Simple.
use Cache::Memory::Simple; use Socket; my $DNS_CACHE = Cache::Memory::Simple->new(); my $r = DBIx::DSN::Resolver->new( resolver => sub { my $host = shift; my $ipr = $DNS_CACHE->get($host); my $ip = $ipr ? $$ipr : undef; if ( !$ipr ) { $ip = Socket::inet_aton($host); $DNS_CACHE->set($host,\$ip,5); } return unless $ip; Socket::inet_ntoa($ip); } ); $dsn = $resolver->resolv($dsn);
Default:
resolver => sub { Socket::inet_ntoa(Socket::inet_aton(@_)) }
Also DBIx::DSN::Resolver::Cached is useful for cache resolver response.
AUTHOR
Masahiro Nagano <kazeburo {at} gmail.com>
NOTES
DBIx::DSN::Resolver uses Socket::inet_aton for hostname resolution. If you use Solaris and fail hostname resolution, please recompile Socket with "LIBS=-lresolve"
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install DBIx::DSN::Resolver, copy and paste the appropriate command in to your terminal.
cpanm DBIx::DSN::Resolver
perl -MCPAN -e shell install DBIx::DSN::Resolver
For more information on module installation, please visit the detailed CPAN module installation guide.