source: tags/5.1.7/Link-Accounts-Remote/lib/Link/Accounts/Remote.pm @ 2626

Last change on this file since 2626 was 871, checked in by nanardon, 13 years ago
  • fix error detection
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1package Link::Accounts::Remote;
2
3use 5.014002;
4use strict;
5use warnings;
6use RPC::XML;
7use Net::Domain;
8use Net::DNS;
9use base qw(RPC::XML::Client);
10$RPC::XML::ENCODING = 'utf-8';
11
12our $VERSION = '0.01';
13
14our $ERROR;
15
16sub new {
17    my ($class, $url) = @_;
18
19    $url ||= find_la_url() or do {
20        # ...
21        return;
22    };
23
24    my $self = RPC::XML::Client->new($url);
25
26    # Don't check certificate:
27    #$self->useragent->ssl_opts(verify_hostname => 0);
28
29    bless $self, $class;
30}
31
32sub find_la_url {
33    my $domain = Net::Domain::hostdomain() or return;
34
35    my $res = Net::DNS::Resolver->new;
36    if (my $query = $res->query("_link_accounts.$domain", 'TXT')) {
37        foreach my $rr ($query->answer) {
38            $rr->type eq 'TXT' or next;
39            return $rr->txtdata if $rr->txtdata;
40        }
41    }
42    return;
43}
44
45sub query {
46    my ($self, @args) = @_;
47
48    my $res = $self->send_request(@args);
49    if (!$res) {
50        $ERROR = $RPC::XML::ERROR;
51        return undef;
52    } elsif (ref $res && !$res->is_fault) {
53        return @{$res->value};
54    } else {
55        $ERROR = $res->string;
56        return;
57   }
58}
59
601;
61
62__END__
63# Below is stub documentation for your module. You'd better edit it!
64
65=head1 NAME
66
67Link::Accounts::Remote - Perl extension for blah blah blah
68
69=head1 SYNOPSIS
70
71  use Link::Accounts::Remote;
72  blah blah blah
73
74=head1 DESCRIPTION
75
76Stub documentation for Link::Accounts::Remote, created by h2xs. It looks like the
77author of the extension was negligent enough to leave the stub
78unedited.
79
80Blah blah blah.
81
82
83=head1 SEE ALSO
84
85Mention other useful documentation such as the documentation of
86related modules or operating system documentation (such as man pages
87in UNIX), or any relevant external documentation such as RFCs or
88standards.
89
90If you have a mailing list set up for your module, mention it here.
91
92If you have a web site set up for your module, mention it here.
93
94=head1 AUTHOR
95
96olivier, E<lt>olivier@(none)E<gt>
97
98=head1 COPYRIGHT AND LICENSE
99
100Copyright (C) 2011 by olivier
101
102This library is free software; you can redistribute it and/or modify
103it under the same terms as Perl itself, either Perl version 5.14.2 or,
104at your option, any later version of Perl 5 you may have available.
105
106
107=cut
Note: See TracBrowser for help on using the repository browser.