line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Purple::Client; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
756
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
7
|
1
|
|
|
1
|
|
4
|
use HTTP::Request; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
8
|
1
|
|
|
1
|
|
4
|
use URI::Escape; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
9
|
1
|
|
|
1
|
|
620
|
use Purple; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
892
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
2
|
|
|
2
|
1
|
3773
|
my $class = shift; |
13
|
2
|
|
|
|
|
58
|
my %p = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Use library directly if server_url is not set |
16
|
2
|
100
|
|
|
|
60
|
unless ($p{server_url}) { |
17
|
1
|
|
|
|
|
48
|
return Purple->new(store => $p{store}); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
4
|
my $self = {}; |
21
|
1
|
|
|
|
|
25
|
$self->{server_url} = $p{server_url}; |
22
|
1
|
|
|
|
|
33
|
bless ($self, $class); |
23
|
1
|
|
|
|
|
34
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub getNext { |
27
|
1
|
|
|
1
|
1
|
23
|
my $self = shift; |
28
|
1
|
|
|
|
|
13
|
my $uri = shift; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
70
|
return _post( $self->{server_url}, $uri ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub getNIDs { |
34
|
1
|
|
|
1
|
1
|
1114
|
my $self = shift; |
35
|
1
|
|
|
|
|
3
|
my $url = shift; |
36
|
1
|
|
|
|
|
5
|
return _get( $self->{server_url}, $url ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub getURL { |
40
|
1
|
|
|
1
|
1
|
3013
|
my $self = shift; |
41
|
1
|
|
|
|
|
3
|
my $nid = shift; |
42
|
1
|
|
|
|
|
6
|
return _get( $self->{server_url}, $nid ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# XXX just one for now, API can do multi |
46
|
|
|
|
|
|
|
sub deleteNIDs { |
47
|
1
|
|
|
1
|
1
|
799
|
my $self = shift; |
48
|
1
|
|
|
|
|
4
|
my $nid = shift; |
49
|
1
|
|
|
|
|
7
|
return _delete( $self->{server_url}, $nid ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub updateURL { |
53
|
1
|
|
|
1
|
1
|
699
|
my $self = shift; |
54
|
1
|
|
|
|
|
3
|
my $new_uri = shift; |
55
|
1
|
|
|
|
|
4
|
my $nid = shift; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
6
|
return _put($self->{server_url}, $new_uri, $nid); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _post { |
61
|
1
|
|
|
1
|
|
22
|
my $server = shift; |
62
|
1
|
|
|
|
|
29
|
my $uri = shift; |
63
|
1
|
|
|
|
|
11
|
my $nid = shift; |
64
|
1
|
|
|
|
|
103
|
my $request = HTTP::Request->new( POST => $server ); |
65
|
1
|
50
|
|
|
|
45546
|
$uri = $uri . '#' . $nid if $nid; |
66
|
1
|
|
|
|
|
32
|
$request->content($uri); |
67
|
1
|
|
|
|
|
51
|
_respond_or_die($request); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _get { |
71
|
2
|
|
|
2
|
|
8
|
my $server = shift; |
72
|
2
|
|
|
|
|
4
|
my $arg = shift; |
73
|
2
|
|
|
|
|
12
|
$arg = uri_escape($arg); |
74
|
2
|
|
|
|
|
83
|
my $request = HTTP::Request->new( GET => $server . '/' . $arg ); |
75
|
2
|
|
|
|
|
312
|
_respond_or_die($request); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _delete { |
79
|
1
|
|
|
1
|
|
3
|
my $server = shift; |
80
|
1
|
|
|
|
|
2
|
my $nid = shift; |
81
|
1
|
|
|
|
|
11
|
my $request = HTTP::Request->new( DELETE => $server . '/' . $nid ); |
82
|
1
|
|
|
|
|
148
|
_respond_or_die($request); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _put { |
86
|
1
|
|
|
1
|
|
4
|
my $server = shift; |
87
|
1
|
|
|
|
|
3
|
my $uri = shift; |
88
|
1
|
|
|
|
|
4
|
my $nid = shift; |
89
|
1
|
|
|
|
|
8
|
my $request |
90
|
|
|
|
|
|
|
= HTTP::Request->new( PUT => $server ); |
91
|
1
|
|
|
|
|
158
|
$request->content( $uri . '#' . $nid ); |
92
|
1
|
|
|
|
|
24
|
_respond_or_die($request); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _respond_or_die { |
96
|
5
|
|
|
5
|
|
12
|
my $request = shift; |
97
|
5
|
|
|
|
|
15
|
my $ua = _userAgent(); |
98
|
|
|
|
|
|
|
|
99
|
5
|
|
|
|
|
29
|
my $response = $ua->request($request); |
100
|
5
|
50
|
|
|
|
1159357
|
if ( $response->is_success ) { |
101
|
5
|
|
|
|
|
174
|
return $response->content; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# in real client eval, set errstr, whatever |
105
|
0
|
|
|
|
|
0
|
die $response->status_line; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# XXX more flesh here |
109
|
|
|
|
|
|
|
sub _userAgent { |
110
|
5
|
|
|
5
|
|
75
|
my $ua = LWP::UserAgent->new; |
111
|
5
|
|
|
|
|
6957
|
$ua->timeout(10); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# blah blah |
114
|
5
|
|
|
|
|
86
|
return $ua; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 NAME |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Purple::Client - Client to L and L |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SYNOPSIS |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# use a remote Purple::Server |
126
|
|
|
|
|
|
|
my $client_net = Purple::Client->new(server_url => $SERVER_URL); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# access a local store through the library |
129
|
|
|
|
|
|
|
my $client_lib = Purple::Client->new(store => 't/sql.lite'); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 METHODS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 new(%options) |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Valid %options include: |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
server_url => 'SERVER_URL' # for distributed Purple |
138
|
|
|
|
|
|
|
store => 'STORE' # for local Purple |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
If no options specified, defaults to local SQLite store. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 getNext($uri) |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Gets the next available NID, assigning it $uri in the database. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 getNIDs($uri) |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Gets all NIDs associated with $uri. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 getURL($nid) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Gets the URL associated with NID $nid. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 deleteNIDs($nid) |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Deletes the NID $nid. Note that while the local API supports deleting |
157
|
|
|
|
|
|
|
multiple NIDs at once, this does not (yet). |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 updateURL($url, $nid) |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Updates the NID $nid with the URL $url. Note that while the local API |
162
|
|
|
|
|
|
|
supports updating multiple NIDs at once, this does not (yet). |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 AUTHOR |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Chris Dent, Ecdent@burningchrome.comE |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Eugene Eric Kim, Eeekim@blueoxen.comE |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 BUGS |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
173
|
|
|
|
|
|
|
C, or through the web interface at |
174
|
|
|
|
|
|
|
L. |
175
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
176
|
|
|
|
|
|
|
your bug as I make changes. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
(C) Copyright 2006 Blue Oxen Associates. All rights reserved. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
183
|
|
|
|
|
|
|
under the same terms as Perl itself. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |