The manakai project

Web::Transport::HashrefResolver

Resolve domain names using a hash reference

SYNOPSIS

  use Web::Transport::HashrefResolver;
  $resolver = Web::Transport::HashrefResolver->new_from_hashref ({
    'example.com' => Web::Host->parse_string ('127.0.0.1'),
  });
  $resolver->resolve (Web::Host->parse_string ("example.com"))->then (sub {
    warn defined $_[0] && $_[0]->stringify;
  });

DESCRIPTION

The Web::Transport::HashrefResolver module acts as a simple wrapper for a hash reference to implement the name resolution API.

This module is a resolver (see "RESOLVERS" in Web::Transport).

METHOD

Following methods are available:

$resolver = Web::Transport::HashrefResolver->new_from_hashref ($hashref)

Create a resolver.

$promise = $resolver->resolve ($host, $name => $value, ...)

Resolve a domain.

The first argument must be a host (Web::Host) to resolve.

Additionally, following named arguments can be specified:

no_cache => $boolean

Ignored by this resolver.

signal => $signal

Ignored by this resolver (for now, at least).

debug => $debug

Ignored by this resolver.

The method returns a promise (Promise), which is to be resolved with the result. If the host is a domain and is successfully resolved into an IP address, or the host is an IP address, the promise is resolved with a host (Web::Host) representing that IP address. Otherwise, it is resolved with undef.

That is, if the hash reference with which the resolver is created has a key/value pair whose key is the argument's to_ascii method's return value and value is a Web::Host object whose is_ip method returns true, the argument is resolved into that value. If the hash reference has no such pair and the argument's is_ip method returns true, the argument is resolved into the argument itself. In other words, IP addresses are resolved into theirselves by default but can be overridden by adding pairs into the hash reference. If the hash reference has no such pair and the argument's is_ip method returns false, the argument is resolved into undef.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2016-2019 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.