line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- cperl; cperl-indent-level: 4 -*- |
2
|
|
|
|
|
|
|
# Copyright (C) 2010-2021, Roland van Ipenburg |
3
|
|
|
|
|
|
|
package WWW::Wookie::Server::Connection v1.1.3; |
4
|
5
|
|
|
5
|
|
121202
|
use strict; |
|
5
|
|
|
|
|
19
|
|
|
5
|
|
|
|
|
168
|
|
5
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
20
|
|
|
5
|
|
|
|
|
137
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
652
|
use utf8; |
|
5
|
|
|
|
|
26
|
|
|
5
|
|
|
|
|
30
|
|
8
|
5
|
|
|
5
|
|
175
|
use 5.020000; |
|
5
|
|
|
|
|
25
|
|
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
665
|
use Moose qw/around has/; |
|
5
|
|
|
|
|
481782
|
|
|
5
|
|
|
|
|
76
|
|
11
|
5
|
|
|
5
|
|
31519
|
use Moose::Util::TypeConstraints qw/as coerce from where subtype via/; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
64
|
|
12
|
5
|
|
|
5
|
|
5707
|
use URI; |
|
5
|
|
|
|
|
6419
|
|
|
5
|
|
|
|
|
209
|
|
13
|
5
|
|
|
5
|
|
779
|
use LWP::UserAgent; |
|
5
|
|
|
|
|
40925
|
|
|
5
|
|
|
|
|
176
|
|
14
|
5
|
|
|
5
|
|
939
|
use XML::Simple; |
|
5
|
|
|
|
|
9536
|
|
|
5
|
|
|
|
|
43
|
|
15
|
5
|
|
|
5
|
|
997
|
use namespace::autoclean '-except' => 'meta', '-also' => qr/^_/smx; |
|
5
|
|
|
|
|
8828
|
|
|
5
|
|
|
|
|
43
|
|
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
5
|
|
520
|
use overload '""' => 'as_string'; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
62
|
|
18
|
|
|
|
|
|
|
|
19
|
5
|
|
|
5
|
|
1683
|
use Readonly; |
|
5
|
|
|
|
|
8823
|
|
|
5
|
|
|
|
|
3035
|
|
20
|
|
|
|
|
|
|
## no critic qw(ProhibitCallsToUnexportedSubs) |
21
|
|
|
|
|
|
|
Readonly::Scalar my $EMPTY => q{}; |
22
|
|
|
|
|
|
|
Readonly::Scalar my $MORE_ARGS => 3; |
23
|
|
|
|
|
|
|
Readonly::Scalar my $ADVERTISE => q{advertise?all=true}; |
24
|
|
|
|
|
|
|
Readonly::Scalar my $TIMEOUT => 15; |
25
|
|
|
|
|
|
|
Readonly::Scalar my $AGENT => q{WWW::Wookie/} |
26
|
|
|
|
|
|
|
. $WWW::Wookie::Server::Connection::VERSION; |
27
|
|
|
|
|
|
|
Readonly::Scalar my $SERVER_CONNECTION => |
28
|
|
|
|
|
|
|
q{Wookie Server Connection - URL: %sAPI Key: %sShared Data Key: %s}; |
29
|
|
|
|
|
|
|
## use critic |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
subtype 'Trailing' => as 'Str' => where { m{(^$|(/$))}gsmx }; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
coerce 'Trailing' => from 'Str' => via { s{([^/])$}{$1/}gsmx; $_ }; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has '_url' => ( |
36
|
|
|
|
|
|
|
'is' => 'ro', |
37
|
|
|
|
|
|
|
'isa' => 'Trailing', |
38
|
|
|
|
|
|
|
'coerce' => 1, |
39
|
|
|
|
|
|
|
'reader' => 'getURL', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has '_api_key' => ( |
43
|
|
|
|
|
|
|
'is' => 'ro', |
44
|
|
|
|
|
|
|
'isa' => 'Str', |
45
|
|
|
|
|
|
|
'default' => q{TEST}, |
46
|
|
|
|
|
|
|
'reader' => 'getApiKey', |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has '_shared_data_key' => ( |
50
|
|
|
|
|
|
|
'is' => 'ro', |
51
|
|
|
|
|
|
|
'isa' => 'Str', |
52
|
|
|
|
|
|
|
'default' => q{mysharedkey}, |
53
|
|
|
|
|
|
|
'reader' => 'getSharedDataKey', |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub as_string { |
57
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
58
|
0
|
|
|
|
|
0
|
return sprintf $SERVER_CONNECTION, $self->getURL, $self->getApiKey, |
59
|
|
|
|
|
|
|
$self->getSharedDataKey; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub test { |
63
|
3
|
|
|
3
|
1
|
16
|
my $self = shift; |
64
|
3
|
|
|
|
|
102
|
my $url = $self->getURL; |
65
|
3
|
50
|
|
|
|
16
|
if ( $url ne $EMPTY ) { |
66
|
3
|
|
|
|
|
38
|
my $ua = LWP::UserAgent->new( |
67
|
|
|
|
|
|
|
'timeout' => $TIMEOUT, |
68
|
|
|
|
|
|
|
'agent' => $AGENT, |
69
|
|
|
|
|
|
|
); |
70
|
3
|
|
|
|
|
6442
|
my $response = $ua->get( $url . $ADVERTISE ); |
71
|
3
|
50
|
|
|
|
105441
|
if ( $response->is_success ) { |
72
|
0
|
|
|
|
|
0
|
my $xml_obj = |
73
|
|
|
|
|
|
|
XML::Simple->new( 'ForceArray' => 1, 'KeyAttr' => 'id' ) |
74
|
|
|
|
|
|
|
->XMLin( $response->content ); |
75
|
0
|
0
|
|
|
|
0
|
if ( exists ${$xml_obj}{'widget'} ) { |
|
0
|
|
|
|
|
0
|
|
76
|
0
|
|
|
|
|
0
|
return 1; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
3
|
|
|
|
|
139
|
return 0; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
around 'BUILDARGS' => sub { |
84
|
|
|
|
|
|
|
my $orig = shift; |
85
|
|
|
|
|
|
|
my $class = shift; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
if ( @_ == $MORE_ARGS && !ref $_[0] ) { |
88
|
|
|
|
|
|
|
my ( $url, $api_key, $shareddata_key ) = @_; |
89
|
|
|
|
|
|
|
return $class->$orig( |
90
|
|
|
|
|
|
|
'_url' => $url, |
91
|
|
|
|
|
|
|
'_api_key' => $api_key, |
92
|
|
|
|
|
|
|
'_shared_data_key' => $shareddata_key, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
return $class->$orig(@_); |
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
|
98
|
5
|
|
|
5
|
|
46
|
no Moose; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
37
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=encoding utf8 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=for stopwords Bitbucket Wookie API Readonly URI Ipenburg MERCHANTABILITY |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
WWW::Wookie::Server::Connection - A connection to a Wookie server |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 VERSION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This document describes WWW::Wookie::Server::Connection version C<v1.1.3> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SYNOPSIS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
use WWW::Wookie::Server::Connection; |
121
|
|
|
|
|
|
|
$c = WWW::Wookie::Server::Connection->new($url, $api_key, $data_key); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 DESCRIPTION |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
A connection to a Wookie server. This maintains the necessary data for |
126
|
|
|
|
|
|
|
connecting to the server and provides utility methods for making common calls |
127
|
|
|
|
|
|
|
via the Wookie REST API. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 C<new> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Create a connection to a Wookie server at a given URL. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 4 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item 1. The URL of the Wookie server as string |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item 2. The API key for the server as string |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item 3. The shared data key for the server connection as string |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=back |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 C<getURL> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Get the URL of the Wookie server. Returns the current Wookie connection's URL |
148
|
|
|
|
|
|
|
as string. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 C<setURL> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Set the URL of the Wookie server. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 C<getApiKey> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Get the API key for this server. Returns the current Wookie connection's API |
157
|
|
|
|
|
|
|
key as string. Throws a C<WookieConnectorException>. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 C<setApiKey> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Set the API key for this server. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 C<getSharedDataKey> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Get the shared data key for this server. Returns the current Wookie |
166
|
|
|
|
|
|
|
connection's shared data key. Throws a C<WookieConnectorException>. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 C<setSharedDataKey> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Set the shared data key for this server. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 C<as_string> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Output connection information as string. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 C<test> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Test the Wookie server connection. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=over 4 |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * L<LWP::UserAgent|LWP::UserAgent> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * L<Moose|Moose> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item * L<Moose::Util::TypeConstraints|Moose::Util::TypeConstraints> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item * L<Readonly|Readonly> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * L<URI|URI> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item * L<XML::Simple|XML::Simple> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * L<namespace::autoclean|namespace::autoclean> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * L<overload|overload> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=back |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Please report any bugs or feature requests at |
211
|
|
|
|
|
|
|
L<Bitbucket|https://bitbucket.org/rolandvanipenburg/www-wookie/issues>. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head1 AUTHOR |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Roland van Ipenburg, E<lt>roland@rolandvanipenburg.comE<gt> |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Copyright 2010-2021 by Roland van Ipenburg |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
222
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.14.0 or, |
223
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTY |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
228
|
|
|
|
|
|
|
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
229
|
|
|
|
|
|
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
230
|
|
|
|
|
|
|
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER |
231
|
|
|
|
|
|
|
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
232
|
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE |
233
|
|
|
|
|
|
|
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH |
234
|
|
|
|
|
|
|
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL |
235
|
|
|
|
|
|
|
NECESSARY SERVICING, REPAIR, OR CORRECTION. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
238
|
|
|
|
|
|
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
239
|
|
|
|
|
|
|
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE |
240
|
|
|
|
|
|
|
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, |
241
|
|
|
|
|
|
|
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE |
242
|
|
|
|
|
|
|
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
243
|
|
|
|
|
|
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
244
|
|
|
|
|
|
|
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
245
|
|
|
|
|
|
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
246
|
|
|
|
|
|
|
SUCH DAMAGES. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |