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

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