Вячеслав Тихановский

NAME

Protocol::Yadis - Asynchronous Yadis implementation

SYNOPSIS

    my $y = Protocol::Yadis->new(
        http_req_cb => sub {
            my ($url, $method, $headers, $body, $cb) = @_;

            ...

            $cb->($url, $status, $headers, $body, $error);
        }
    );

    $y->discover(
        $url => sub {
            my ($self, $document, $error) = @_;

            if ($document) {
                my $services = $document->services;

                ...
            }
            elsif ($error) {
                die "Error: $error";
            }
            else {
                die "Nothing found";
            }
        }
    );

DESCRIPTION

This is an asynchronous lightweight but full Yadis implementation.

ATTRIBUTES

http_req_cb

    my $y = Protocol::Yadis->new(
        http_req_cb => sub {
            my ($url, $method, $headers, $body, $cb) = @_;

            ...

            $cb->($url, $status, $headers, $body, $error);
        }
    );

This is a required callback that is used to download documents from the network. Don't forget, that redirects can occur. This callback must handle them properly. That is why after finishing downloading, callback must be called with the final $url.

Arguments that are passed to the request callback

  • url url where to start Yadis discovery

  • method request method

  • headers request headers

  • body request body

  • cb callback that must be called after download was completed

Arguments that must be passed to the response callback

  • url url from where the document was downloaded

  • status response status

  • headers response headers

  • body response body

  • error internal error

head_first

Do HEAD request first. Disabled by default.

METHODS

new

Creates a new Protocol::Yadis instance.

discover

    $y->discover(
        $url => sub {
            my ($self, $document, $error) = @_;

            if ($document) {
                my $services = $document->services;

                ...
            }
            else {
                die 'error';
            }
        }
    );

Discover Yadis document at the url provided. Callback is called when discovery was finished. If no document was passed there was an error during discovery. Error is passed as the third parameter.

If a Yadis document was discovered you get Protocol::Yadis::Document instance containing all the services.

AUTHOR

Viacheslav Tykhanovskyi, vti@cpan.org.

COPYRIGHT

Copyright (C) 2009, Viacheslav Tykhanovskyi.

This program is free software, you can redistribute it and/or modify it under the same terms as Perl 5.10.