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