The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::Yadis::Discovery - Perl extension for discovering Yadis document from Yadis URL

SYNOPSIS

  use Net::Yadis::Discovery;
  
  my $disc = Net::Yadis::Discovery->new(
                                         ua => $ua,       # LWP::UserAgent object
                                         cache => $cache  # Cache object
                                     );

  my $xrd = $disc->discover("http://id.example.com/") or Carp::croak($disc->err);

  print $disc->identity_url;       # Yadis URL (Final URL if redirected )
  print $disc->xrd_url;            # Yadis Resourse Descriptor URL

  foreach my $srv (@$xrd) {        # Loop for Each Service in Yadis Resourse Descriptor
    print $srv->priority;          # Service priority (sorted)
    print $srv->Type;              # Identifier of some version of some service (scalar, array or array ref)
    print $srv->URI;               # URI that resolves to a resource providing the service (scalar, array or array ref)
    print $srv->extra_field("Delegate","http://openid.net/xmlns/1.0");
                                   # Extra field of some service
  }

  my $xrd = $self->servers('openid'=>['1.0','1.1'],'typekey');
  # If you want to take only OpenID 1.0/1.1 and TypeKey servers.

  my $xrd = $self->servers(sub{($_[int(rand(@_))])});
  # If you want to choose random server by code-ref.

DESCRIPTION

This is the Perl API for Yadis, to find Yadis Resourse Descriptor from Yadis URL, and make Service objects from Resourse Descriptor.

Yadis is a protocol to enable a Relying Party to obtain a Yadis Resource Descriptor that describes the services available using a Yadis ID.

More information is available at:

  http://yadis.org/

This module version 0.01 is based on Yadis Specification 0.92.

CONSTRUCTOR

new

my $disc = Net::Yadis::Discovery->new([ %opts ]);

You can set the ua and cache in the constructor. See the corresponding method descriptions below.

EXPORT

This module exports three constant values to use with discover method.

YR_HEAD

If you set this value to option argument of discover method, module check Yadis URL start from HTTP HEAD request.

YR_GET

If you set this, module check Yadis URL start from HTTP GET request.

YR_XRDS

If you set this, this module consider Yadis URL as Yadis Resource Descriptor URL. If not so, error returns.

METHODS

$disc->ua($user_agent)
$disc->ua

Getter/setter for the LWP::UserAgent (or subclass) instance which will be used when web donwloads are needed. It's highly recommended that you use LWPx::ParanoidAgent, or at least read its documentation so you're aware of why you should care.

$disc->cache($cache)
$disc->cache

Getter/setter for the optional (but recommended!) cache instance you want to use for storing fetched parts of pages.

The $cache object can be anything that has a ->get($key) and ->set($key,$value) methods. See URI::Fetch for more information. This cache object is just passed to URI::Fetch directly.

$disc->discover($url,[$request_method])

Given a user-entered $url (which could be missing http://, or have extra whitespace, etc), returns either array/array ref of Net::Yadis::Object objects, or undef on failure.

$request_method is optional, and if set this, you can change the HTTP request method of fetching Yadis URL. See EXPORT to know the value you can set, and default is YR_HEAD.

If this method returns undef, you can rely on the following errors codes (from $csr->errcode) to decide what to present to the user:

xrd_parse_error
xrd_format_error
too_many_hops
no_yadis_document
url_fetch_err
empty_url
url_gone
$disc->xrd_objects

Returns array/array ref of Net::Yadis::Object objects. It is same what could be got by discover method.

$disc->identity_url

Returns Yadis URL. If not redirected, it is same with the argument of discover method.

$disc->xrd_url

Returns Yadis Resource Descriptor URL.

$disc->servers($protocol,$protocol,...)
$disc->servers($protocol=>[$version1,$version2],...)
$disc->servers($protocol,....,$code_ref);

Filter method of xrd_objects.

If no opton is defined, returns same result with xrd_objects method.

protocol names or Type URLs are given, filter only given protocol. Two or more protocols are given, return and results of filtering.

Sample: $disc->servers("openid","http://lid.netmesh.org/sso/1.0");

If reference of version numbers array is given after protocol names, filter only given version of protocol.

Sample: $disc->servers("openid"=>['1.0','1.1'],"lid"=>['1.0']);

If you want to use version numbers limitation with type URL, you can use \ver as place holder of version number.

Sample: $disc->servers("http://lid.netmesh.org/sso/\ver"=>['1.0','2.0']);

If code reference is given as argument , you can make your own filter rule. code reference is executed at the last of filtering logic, like this:

  @results = $code_ref->(@temporary_results)

Sample: If you want to filter OpenID server and get only first one: ($openid_server) = $disc->servers("openid",sub{$_[0]});

$disc->err

Returns the last error, in form "errcode: errtext"

$disc->errcode

Returns the last error code.

$disc->errtext

Returns the last error text.

COPYRIGHT

This module is Copyright (c) 2006 OHTSUKA Ko-hei. All rights reserved.

You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. If you need more liberal licensing terms, please contact the maintainer.

WARRANTY

This is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.

SEE ALSO

Yadis website: http://yadis.org/

Net::Yadis::Object -- part of this module

AUTHORS

OHTSUKA Ko-hei <nene@kokogiko.net>