blib/lib/WWW/Wookie/Server/Connection.pm

filter: Statementstmt 91.8% 68 / 74 Branchbran 50.0% 4 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 94.4% 17 / 18 Podpod 100% 2 / 2 totaltotal 87.8% 94 / 107 SCAR 18.0
CC
6
Cov
87%
test
5.7
__ANON__
3.0
as_string
2.0
CRAP 6.1
« blib/lib/WWW/Wookie/Widget/Property.pm ↑ Summary blib/lib/WWW/Wookie/User.pm »
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use 5.020000;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use Moose qw/around has/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Moose::Util::TypeConstraints qw/as coerce from where subtype via/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use namespace::autoclean '-except' => 'meta', '-also' => qr/^_/smx;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 5 ▶use overload '""' => 'as_string';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 ## no critic qw(ProhibitCallsToUnexportedSubs)
21 5 Readonly::Scalar my $EMPTY => q{};
22 5 Readonly::Scalar my $MORE_ARGS => 3;
23 5 Readonly::Scalar my $ADVERTISE => q{advertise?all=true};
24 5 Readonly::Scalar my $TIMEOUT => 15;
25 5 Readonly::Scalar my $AGENT => q{WWW::Wookie/}
26 . $WWW::Wookie::Server::Connection::VERSION;
27 5 Readonly::Scalar my $SERVER_CONNECTION =>
28 q{Wookie Server Connection - URL: %sAPI Key: %sShared Data Key: %s};
29 ## use critic
30  
31 24 ▶subtype 'Trailing' => as 'Str' => where { m{(^$|(/$))}gsmx };
Subroutine __ANON__: called CC=1 SCAR=0.0
32  
33 1 ▶coerce 'Trailing' => from 'Str' => via { s{([^/])$}{$1/}gsmx; $_ };
Subroutine __ANON__: called CC=1 SCAR=0.0
34  
35 5 has '_url' => (
36 'is' => 'ro',
37 'isa' => 'Trailing',
38 'coerce' => 1,
39 'reader' => 'getURL',
40 );
41  
42 5 has '_api_key' => (
43 'is' => 'ro',
44 'isa' => 'Str',
45 'default' => q{TEST},
46 'reader' => 'getApiKey',
47 );
48  
49 5 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 ▶ my $self = shift;
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
58 0 return sprintf $SERVER_CONNECTION, $self->getURL, $self->getApiKey,
59 $self->getSharedDataKey;
60 }
61  
62 sub test {
63 3 ▶ my $self = shift;
Subroutine test: called CC=4 SCAR=17.3
Pod documented
64 3 my $url = $self->getURL;
65 3 ▶ if ( $url ne $EMPTY ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url ne $EMPTY) 3 0 3
66 3 my $ua = LWP::UserAgent->new(
67 'timeout' => $TIMEOUT,
68 'agent' => $AGENT,
69 );
70 3 my $response = $ua->get( $url . $ADVERTISE );
71 3 ▶ if ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 3 3
72 0 my $xml_obj =
73 XML::Simple->new( 'ForceArray' => 1, 'KeyAttr' => 'id' )
74 ->XMLin( $response->content );
75 0 ▶ if ( exists ${$xml_obj}{'widget'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists do { $xml_obj }->{"widget"}) 0 0 0
76 0 return 1;
77 }
78 }
79 }
80 3 return 0;
81 }
82  
83 around 'BUILDARGS' => sub {
84 14 ▶ my $orig = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
85 14 my $class = shift;
86  
87 14 ▶ if ( @_ == $MORE_ARGS && !ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == $MORE_ARGS and not ref $_[0]) 12 2 14
Condition66%2/3
@_ == $MORE_ARGS and not ref $_[0]
!ll&&!rl&&r
2012
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]
ABresult
0X0
100
111
88 12 my ( $url, $api_key, $shareddata_key ) = @_;
89 12 return $class->$orig(
90 '_url' => $url,
91 '_api_key' => $api_key,
92 '_shared_data_key' => $shareddata_key,
93 );
94 }
95 2 return $class->$orig(@_);
96 5 };
97  
98 5 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
99  
100 5 __PACKAGE__->meta->make_immutable;
101  
102 5 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
« blib/lib/WWW/Wookie/Widget/Property.pm ↑ Summary blib/lib/WWW/Wookie/User.pm »