blib/lib/WWW/Ohloh/API/Account.pm

filter: Statementstmt 91.8% 90 / 98 Branchbran 40.0% 4 / 10 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 90.4% 19 / 21 Podpod 37.5% 3 / 8 totaltotal 76.4% 120 / 157 CC 11 SCAR 8.2
CC
11
Cov
82%
generate_query_url
6.0
stack
4.4
as_xml
3.0
CRAP 2.3
« blib/lib/WWW/Ohloh/API/Kudos.pm ↑ Summary blib/lib/WWW/Ohloh/API/ContributorFact.pm »
1 package WWW::Ohloh::API::Account;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 use Object::InsideOut qw/
8 WWW::Ohloh::API::Role::Fetchable
9 15 ▶ WWW::Ohloh::API::Role::LoadXML /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use WWW::Ohloh::API::KudoScore;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use Date::Parse;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 15 ▶use Params::Validate qw/ validate validate_with /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 15 our $VERSION = '0.3.2';
18  
19 15 ▶use overload '""' => sub { $_[0]->name };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
20  
21 #<<<
22 15 my @id_of : Field
23 : Set(_set_id)
24 : Get(id)
25 ;
26 15 my @name_of : Field
27 : Set(_set_name)
28 : Get(name)
29 ;
30 15 my @creation_date_of : Field
31 : Set(_set_created_at)
32 : Get(created_at)
33 : Type(Time::Piece)
34 ;
35 15 my @update_date_of : Field
36 : Set(_set_updated_at)
37 : Get(updated_at)
38 ;
39 15 my @homepage_url_of : Field
40 : Set(_set_homepage_url)
41 : Get(homepage_url)
42 ;
43 15 my @avatar_url_of : Field
44 : Set(_set_avatar_url)
45 : Get(avatar_url)
46 ;
47 15 my @posts_count_of : Field
48 : Set(_set_posts_count)
49 : Get(posts_count)
50 ;
51 15 my @location_of : Field
52 : Set(_set_location)
53 : Get(location)
54 ;
55 15 my @latitude_of : Field
56 : Set(_set_latitude)
57 : Get(latitude)
58 ;
59 15 my @longitude_of : Field
60 : Set(_set_longitude)
61 : Get(longitude)
62 ;
63 15 my @country_code_of : Field
64 : Set(_set_country_code)
65 : Get(country_code)
66 ;
67 15 my @kudo_of : Field
68 : Set(_set_kudo)
69 : Get(kudo_score)
70 ;
71 #>>>
72 15 my @kudos_of : Field : Arg(kudos);
73  
74 15 my @stack : Field;
75  
76 0 ▶sub element_name { return 'account' }
Subroutine element_name: not called CC=1 SCAR=6.9
Pod undocumented
77  
78 sub generate_query_url : Chained(bottom up) {
79 0 ▶ my ( $self, @args ) = @_;
Subroutine generate_query_url: not called CC=2 SCAR=17.9
80  
81 0 my %param = validate_with(
82 params => \@args,
83 spec => { id => 1 },
84 allow_extra => 1
85 );
86 0 my $id = $param{id};
87 0 delete $param{id};
88  
89 0 ▶ if ( index( $id, '@' ) > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($id, "\@") != -1) 0 0 0
90 0 $id = md5_hex($id);
91 }
92  
93 0 return ( "accounts/$id.xml", %param );
94 15 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
95  
96 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97  
98 sub load_xml {
99 9 ▶ my ( $self, $dom ) = @_;
Subroutine load_xml: called CC=2 SCAR=6.9
Pod undocumented
100  
101 9 $self->_set_id( $dom->findvalue('id/text()') );
102 9 $self->_set_name( $dom->findvalue('name/text()') );
103 9 $self->_set_created_at(
104 Time::Piece->new( str2time( $dom->findvalue('created_at/text()') ) )
105 );
106 9 $self->_set_updated_at( $dom->findvalue('updated_at/text()') );
107 9 $self->_set_homepage_url( $dom->findvalue('homepage_url/text()') );
108 9 $self->_set_avatar_url( $dom->findvalue('avatar_url/text()') );
109 9 $self->_set_posts_count( $dom->findvalue('posts_count/text()') );
110 9 $self->_set_location( $dom->findvalue('location/text()') );
111 9 $self->_set_country_code( $dom->findvalue('country_code/text()') );
112 9 $self->_set_latitude( $dom->findvalue('latitude/text()') );
113 9 $self->_set_longitude( $dom->findvalue('longitude/text()') );
114  
115 9 ▶ if ( my ($node) = $dom->findnodes('kudo_score[1]') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($node) = $dom->findnodes("kudo_score[1]")) 9 0 9
116 9 $kudo_of[$$self] = WWW::Ohloh::API::KudoScore->new( xml => $node );
117 }
118 }
119  
120 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121  
122 sub as_xml {
123 2 ▶ my $self = shift;
Subroutine as_xml: called CC=3 SCAR=11.0
Pod documented
124 2 my $xml;
125 2 my $w = XML::Writer->new( OUTPUT => \$xml );
126  
127 2 $w->startTag('account');
128  
129 2 $w->dataElement( $_ => $self->$_ ) for qw/
130 id name created_at updated_at homepage_url
131 avatar_url posts_count
132 location
133 country_code
134 latitude
135 longitude
136 /;
137  
138 2 ▶ $xml .= $self->kudo->as_xml if $self->kudo;
Branch: 1 branch
BranchTrueFalseTotal
if $self->kudo 2 0 2
139  
140 2 $w->endTag;
141  
142 2 return $xml;
143 }
144  
145 sub kudoScore {
146 4 ▶ my $self = shift;
Subroutine kudoScore: called CC=1 SCAR=0.0
Pod documented
147 4 return $kudo_of[$$self];
148 }
149  
150 # aliases
151 15 *kudo = *kudoScore;
152  
153 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154  
155 sub stack {
156 1 ▶ my $self = shift;
Subroutine stack: called CC=4 SCAR=14.8
Pod documented
157  
158 1 my $retrieve = shift;
159 1 ▶ $retrieve = 1 unless defined $retrieve;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $retrieve 1 0 1
160  
161 1 ▶ if ( $retrieve and not $stack[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retrieve and not $stack[$$self]) 1 0 1
Condition33%1/3
$retrieve and not $stack[$$self]
!ll&&!rl&&r
001
MC/DC0%0/2
$retrieve and not $stack[$$self]
$retrieve not $stack[$$self]
Truth table33%1/3
A and not(B)
A= $retrieveB= not $stack[$$self]
ABresult
0X0
100
111
162 1 $stack[$$self] = $self->ohloh->get_account_stack( $self->id );
163 1 $stack[$$self]->set_account($self);
164 }
165  
166 1 return $stack[$$self];
167 }
168  
169 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
170  
171 sub sent_kudos {
172 1 ▶ my $self = shift;
Subroutine sent_kudos: called CC=2 SCAR=7.6
Pod undocumented
173  
174 1 ▶ $kudos_of[$$self] ||= $self->ohloh->get_kudos( id => $self->id );
Condition33%1/3
$kudos_of[$$self] ||= $self->ohloh->get_kudos("id", $self->id)
l!l&&r!l&&!r
100
MC/DC0%0/2
$kudos_of[$$self] ||= $self->ohloh->get_kudos("id", $self->id)
$kudos_of[$$self] $self->ohloh->get_kudos("id", $self->id)
Truth table33%1/3
A ||= B
A= $kudos_of[$$self]B= $self->ohloh->get_kudos("id", $self->id)
ABresult
1X1
011
000
175  
176 1 return $kudos_of[$$self]->sent;
177 }
178  
179 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180  
181 sub received_kudos {
182 1 ▶ my $self = shift;
Subroutine received_kudos: called CC=2 SCAR=7.6
Pod undocumented
183  
184 1 ▶ $kudos_of[$$self] ||= $self->ohloh->get_kudos( id => $self->id );
Condition33%1/3
$kudos_of[$$self] ||= $self->ohloh->get_kudos("id", $self->id)
l!l&&r!l&&!r
100
MC/DC0%0/2
$kudos_of[$$self] ||= $self->ohloh->get_kudos("id", $self->id)
$kudos_of[$$self] $self->ohloh->get_kudos("id", $self->id)
Truth table33%1/3
A ||= B
A= $kudos_of[$$self]B= $self->ohloh->get_kudos("id", $self->id)
ABresult
1X1
011
000
185  
186 1 return $kudos_of[$$self]->received;
187 }
188  
189 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190  
191 sub kudos {
192 1 ▶ my $self = shift;
Subroutine kudos: called CC=2 SCAR=8.1
Pod undocumented
193  
194 1 ▶ return $kudos_of[$$self] ||= $self->ohloh->get_kudos( id => $self->id );
Condition33%1/3
$kudos_of[$$self] ||= $self->ohloh->get_kudos("id", $self->id)
l!l&&r!l&&!r
010
MC/DC0%0/2
$kudos_of[$$self] ||= $self->ohloh->get_kudos("id", $self->id)
$kudos_of[$$self] $self->ohloh->get_kudos("id", $self->id)
Truth table33%1/3
A ||= B
A= $kudos_of[$$self]B= $self->ohloh->get_kudos("id", $self->id)
ABresult
1X1
011
000
195 }
196  
197 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
198  
199 15 'end of WWW::Ohloh::API::Account';
200 __END__
201  
202 =head1 NAME
203  
204 WWW::Ohloh::API::Account - an Ohloh account
205  
206 =head1 SYNOPSIS
207  
208 use WWW::Ohloh::API;
209  
210 my $ohloh = WWW::Ohloh::API->new( api_key => $my_api_key );
211 my $account $ohloh->get_account( id => 12933 );
212  
213 print $account->name;
214  
215 =head1 DESCRIPTION
216  
217 W::O::A::Account contains the information associated with an Ohloh
218 account as defined at http://www.ohloh.net/api/reference/account.
219 To be properly populated, it must be created via
220 the C<get_account> method of a L<WWW::Ohloh::API> object.
221  
222 =head1 METHODS
223  
224 =head2 API Data Accessors
225  
226 =head3 id
227  
228 Return the account's id.
229  
230 =head3 name
231  
232 Return the public name of the account.
233  
234 =head3 created_at
235  
236 Return the time at which the account was created.
237  
238 =head3 updated_at
239  
240 Return the last time at which the account was modified.
241  
242 =head3 homepage_url
243  
244 Return the URL to a member's home page, such as a blog, or I<undef> if not
245 configured.
246  
247 =head3 avatar_url
248  
249 Return the URL to the profile image displayed on Ohloh pages, or I<undef> if
250 not configured.
251  
252 =head3 posts_count
253  
254 Return the number of posts made to the Ohloh forums by this account.
255  
256 =head3 location
257  
258 Return a text description of this account holder's claimed location, or
259 I<undef> if not
260 available.
261  
262 =head3 country_code
263  
264 Return a string representing the account holder's country, or I<undef> is
265 unavailable.
266  
267 =head3 latitude, longitude
268  
269 Return floating-point values representing the account's latitude and longitude,
270 suitable for use with the Google Maps API, or I<undef> is they are not
271 available.
272  
273 =head3 kudoScore, kudo_score, kudo
274  
275 Return a L<WWW::Ohloh::API::KudoScore> object holding the account's
276 kudo information, or I<undef> if the account doesn't have a kudo score
277 yet. All three methods are equivalent.
278  
279 =head3 stack( $retrieve )
280  
281 Return the stack associated with the account as a
282 L<WWW::Ohloh::API::Stack> object.
283  
284 If the optional I<$retrieve> argument is given and false,
285 the stack will not be queried from the Ohloh server and,
286 if the information has not been retrieved previously, the method
287 will return nothing.
288  
289 =head2 Other Methods
290  
291 =head3 as_xml
292  
293 Return the account information (including the kudo score if it applies)
294 as an XML string. Note that this is not the exact xml document as returned
295 by the Ohloh server.
296  
297 =head1 OVERLOADING
298  
299 When the object is called in a string context, it'll be replaced by
300 the name associated with the account. E.g.,
301  
302 print $account; # equivalent to 'print $account->name'
303  
304 =head1 SEE ALSO
305  
306 =over
307  
308 =item *
309  
310 L<WWW::Ohloh::API>, L<WWW::Ohloh::API::KudoScore>.
311  
312 =item *
313  
314 Ohloh API reference: http://www.ohloh.net/api/getting_started
315  
316 =item *
317  
318 Ohloh Account API reference: http://www.ohloh.net/api/reference/account
319  
320 =back
321  
322 =head1 VERSION
323  
324 This document describes WWW::Ohloh::API version 0.3.2
325  
326 =head1 BUGS AND LIMITATIONS
327  
328 WWW::Ohloh::API is very extremely alpha quality. It'll improve,
329 but till then: I<Caveat emptor>.
330  
331 The C<as_xml()> method returns a re-encoding of the account data, which
332 can differ of the original xml document sent by the Ohloh server.
333  
334 Please report any bugs or feature requests to
335 C<bug-www-ohloh-api@rt.cpan.org>, or through the web interface at
336 L<http://rt.cpan.org>.
337  
338  
339 =head1 AUTHOR
340  
341 Yanick Champoux C<< <yanick@cpan.org> >>
342  
343 =head1 LICENCE AND COPYRIGHT
344  
345 Copyright (c) 2008, Yanick Champoux C<< <yanick@cpan.org> >>. All rights reserved.
346  
347 This module is free software; you can redistribute it and/or
348 modify it under the same terms as Perl itself. See L<perlartistic>.
349  
« blib/lib/WWW/Ohloh/API/Kudos.pm ↑ Summary blib/lib/WWW/Ohloh/API/ContributorFact.pm »