1 | package Link::Accounts::Remote; |
---|
2 | |
---|
3 | use 5.014002; |
---|
4 | use strict; |
---|
5 | use warnings; |
---|
6 | use RPC::XML; |
---|
7 | use Net::Domain; |
---|
8 | use Net::DNS; |
---|
9 | use base qw(RPC::XML::Client); |
---|
10 | $RPC::XML::ENCODING = 'utf-8'; |
---|
11 | |
---|
12 | our $VERSION = '0.01'; |
---|
13 | |
---|
14 | our $ERROR; |
---|
15 | |
---|
16 | sub 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 | |
---|
32 | sub 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 | |
---|
45 | sub 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 | |
---|
60 | 1; |
---|
61 | |
---|
62 | __END__ |
---|
63 | # Below is stub documentation for your module. You'd better edit it! |
---|
64 | |
---|
65 | =head1 NAME |
---|
66 | |
---|
67 | Link::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 | |
---|
76 | Stub documentation for Link::Accounts::Remote, created by h2xs. It looks like the |
---|
77 | author of the extension was negligent enough to leave the stub |
---|
78 | unedited. |
---|
79 | |
---|
80 | Blah blah blah. |
---|
81 | |
---|
82 | |
---|
83 | =head1 SEE ALSO |
---|
84 | |
---|
85 | Mention other useful documentation such as the documentation of |
---|
86 | related modules or operating system documentation (such as man pages |
---|
87 | in UNIX), or any relevant external documentation such as RFCs or |
---|
88 | standards. |
---|
89 | |
---|
90 | If you have a mailing list set up for your module, mention it here. |
---|
91 | |
---|
92 | If you have a web site set up for your module, mention it here. |
---|
93 | |
---|
94 | =head1 AUTHOR |
---|
95 | |
---|
96 | olivier, E<lt>olivier@(none)E<gt> |
---|
97 | |
---|
98 | =head1 COPYRIGHT AND LICENSE |
---|
99 | |
---|
100 | Copyright (C) 2011 by olivier |
---|
101 | |
---|
102 | This library is free software; you can redistribute it and/or modify |
---|
103 | it under the same terms as Perl itself, either Perl version 5.14.2 or, |
---|
104 | at your option, any later version of Perl 5 you may have available. |
---|
105 | |
---|
106 | |
---|
107 | =cut |
---|