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

filter: Statementstmt 89.8% 88 / 98 Branchbran 56.2% 9 / 16 Conditioncond 9.0% 1 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 92.8% 13 / 14 Podpod 80.0% 4 / 5 totaltotal 76.6% 115 / 150 CC 15 SCAR 20.4
CC
15
Cov
78%
activity_facts
30.0
as_xml
5.6
analysis
3.8
CRAP 7.7
« blib/lib/WWW/Ohloh/API.pm ↑ Summary blib/lib/WWW/Ohloh/API/Stack.pm »
1 package WWW::Ohloh::API::Project;
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;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use WWW::Ohloh::API::Analysis;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use WWW::Ohloh::API::ContributorFact;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 15 our $VERSION = '0.3.2';
13  
14 15 my @request_url_of : Field : Arg(request_url) : Get( request_url );
15 15 my @ohloh_of : Field : Arg(ohloh) : Get( _ohloh );
16 15 my @xml_of : Field : Arg(xml);
17  
18 15 my @id_of : Field : Get(id) : Set(_set_id);
19 15 my @name_of : Field : Get(name) : Set(_set_name);
20 15 my @created_at_of : Field : Get(created_at) : Set(_set_created_at);
21 15 my @updated_at_of : Field : Get(updated_at) : Set(_set_updated_at);
22 15 my @description_of : Field : Get(description) : Set(_set_description);
23 15 my @homepage_url_of : Field : Get(homepage_url) : Set(_set_homepage_url);
24 15 my @download_url_of : Field : Get(download_url) : Set(_set_download_url);
25 15 my @irc_url_of : Field : Get(irc_url) : Set(_set_irc_url);
26 15 my @stack_count_of : Field : Get(stack_count) : Set(_set_stack_count);
27 15 my @average_rating_of : Field : Get(average_rating) :
28 Set(_set_average_rating);
29 15 my @rating_count_of : Field : Get(rating_count) : Set(_set_rating_count);
30 15 my @analysis_id_of : Field : Get(analysis_id) : Set(_set_analysis_id);
31 15 my @analysis_of : Field;
32 15 my @facts_of : Field;
33 15 my @factoids_of : Field;
34  
35 15 my @contributors_of : Field;
36  
37 sub _init : Init {
38 37 ▶ my $self = shift;
Subroutine _init: called CC=3 SCAR=11.0
39  
40 37 ▶ my $dom = $xml_of[$$self] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $dom = $xml_of[$$self] or return 0 37 37
41  
42 37 $self->_set_id( $dom->findvalue('id/text()') );
43 37 $self->_set_name( $dom->findvalue('name/text()') );
44 37 $self->_set_created_at( $dom->findvalue('created_at/text()') );
45 37 $self->_set_updated_at( $dom->findvalue('updated_at/text()') );
46 37 $self->_set_description( $dom->findvalue('description/text()') );
47 37 $self->_set_homepage_url( $dom->findvalue('homepage_url/text()') );
48 37 $self->_set_download_url( $dom->findvalue('download_url/text()') );
49 37 $self->_set_irc_url( $dom->findvalue('irc_url/text()') );
50 37 $self->_set_stack_count( $dom->findvalue('stack_count/text()') );
51 37 $self->_set_average_rating( $dom->findvalue('average_rating/text()') );
52 37 $self->_set_rating_count( $dom->findvalue('rating_count/text()') );
53 37 $self->_set_analysis_id( $dom->findvalue('analysis_id/text()') );
54  
55 37 ▶ if ( my ($n) = $dom->findnodes('analysis[1]') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($n) = $dom->findnodes("analysis[1]")) 2 35 37
56 2 $analysis_of[$$self] = WWW::Ohloh::API::Analysis->new( xml => $n );
57 }
58  
59 37 return;
60 15 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63  
64 sub analysis {
65 2 ▶ my $self = shift;
Subroutine analysis: called CC=3 SCAR=13.5
Pod documented
66 2 my $id = shift;
67  
68 2 ▶ if ( $id or not $analysis_of[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id or not $analysis_of[$$self]) 0 2 2
Condition33%1/3
$id or not $analysis_of[$$self]
l!l&&r!l&&!r
002
MC/DC0%0/2
$id or not $analysis_of[$$self]
$id not $analysis_of[$$self]
Truth table33%1/3
A or not(B)
A= $idB= not $analysis_of[$$self]
ABresult
1X1
011
000
69 0 $analysis_of[$$self] =
70 $ohloh_of[$$self]->get_analysis( $self->id, $id );
71 0 $analysis_id_of[$$self] = $analysis_of[$$self]->id;
72 }
73  
74 2 return $analysis_of[$$self];
75 }
76  
77 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78  
79 sub activity_facts {
80 0 ▶ my $self = shift;
Subroutine activity_facts: not called CC=5 SCAR=34.0
Pod documented
81 0 my $id = shift;
82  
83 0 ▶ if ( $id or not $facts_of[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id or not $facts_of[$$self]) 0 0 0
Condition0%0/3
$id or not $facts_of[$$self]
l!l&&r!l&&!r
000
MC/DC0%0/2
$id or not $facts_of[$$self]
$id not $facts_of[$$self]
Truth table0%0/3
A or not(B)
A= $idB= not $facts_of[$$self]
ABresult
1X1
011
000
84 0 ▶ $facts_of[$$self] =
Condition0%0/5
$id || $self->analysis_id || 'latest'
l!l
00
$id or $self->analysis_id
l!l&&r!l&&!r
000
MC/DC0%0/2
$id || $self->analysis_id || 'latest'
$id $self->analysis_id
Truth table0%0/3
A or B
A= $idB= $self->analysis_id
ABresult
1X1
011
000
85 $ohloh_of[$$self]->get_activity_facts( $self->id,
86 $id || $self->analysis_id || 'latest' );
87 }
88  
89 0 return $facts_of[$$self];
90 }
91  
92 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93  
94 sub as_xml {
95 1 ▶ my $self = shift;
Subroutine as_xml: called CC=5 SCAR=17.3
Pod documented
96 1 my $xml;
97 1 my $w = XML::Writer->new( OUTPUT => \$xml );
98  
99 1 $w->startTag('project');
100 1 for my $attr (
101 qw/ id name created_at updated_at
102 description homepage_url
103 download_url irc_url stack_count
104 average_rating rating_count
105 analysis_id /
106 ) {
107 12 $w->dataElement( $attr, $self->$attr );
108 }
109 1 ▶ $xml .= $self->analysis->as_xml if $analysis_of[$$self];
Branch: 1 branch
BranchTrueFalseTotal
if $analysis_of[$$self] 1 0 1
110  
111 1 ▶ if ( my $factoids = $factoids_of[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $factoids = $factoids_of[$$self]) 0 1 1
112 0 $xml .= '<factoids>';
113 0 $xml .= $_->as_xml for @$factoids;
114 0 $xml .= '</factoids>';
115 }
116  
117 1 $w->endTag;
118  
119 1 return $xml;
120 }
121  
122 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123  
124 sub contributors {
125 1 ▶ my $self = shift;
Subroutine contributors: called CC=2 SCAR=7.0
Pod undocumented
126  
127 1 ▶ unless ( $contributors_of[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($contributors_of[$$self]) 1 0 1
128 1 my ( $url, $xml ) = $self->_ohloh->_query_server(
129 'projects/' . $self->id . '/contributors.xml' );
130  
131 $contributors_of[$$self] = [
132 map {
133 1 WWW::Ohloh::API::ContributorFact->new(
134 request_url => $url,
135 xml => $_,
136 ohloh => $self->_ohloh
137 )
138 } $xml->findnodes('//contributor_fact') ];
139 }
140  
141 1 return @{ $contributors_of[$$self] };
142 }
143  
144 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145  
146 sub factoids {
147 2 ▶ my $self = shift;
Subroutine factoids: called CC=2 SCAR=6.9
Pod documented
148  
149 2 ▶ unless ( defined $factoids_of[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $factoids_of[$$self]) 1 1 2
150 1 $factoids_of[$$self] =
151 [ $ohloh_of[$$self]->get_factoids( $self->id ) ];
152 }
153  
154 2 return @{ $factoids_of[$$self] };
155 }
156  
157 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
158  
159 15 'end of WWW::Ohloh::API::Project';
160 __END__
161  
162 =head1 NAME
163  
164 WWW::Ohloh::API::Project - an Ohloh project
165  
166 =head1 SYNOPSIS
167  
168 use WWW::Ohloh::API;
169  
170 my $ohloh = WWW::Ohloh::API->new( api_key => $my_api_key );
171 my $project = $ohloh->get_project( id => 1001 );
172  
173 print $project->homepage_url;
174  
175 =head1 DESCRIPTION
176  
177 W::O::A::Project contains the information associated with an Ohloh
178 project as defined at http://www.ohloh.net/api/reference/project.
179 To be properly populated, it must be created via
180 the C<get_project> method of a L<WWW::Ohloh::API> object.
181  
182 =head1 METHODS
183  
184 =head2 API Data Accessors
185  
186 =head3 id
187  
188 Return the project's id.
189  
190 =head3 name
191  
192 Return the name of the project.
193  
194 =head3 created_at
195  
196 Return the time at which the project was initially
197 added to Ohloh.
198  
199 =head3 updated_at
200  
201 Return the time of the most recent modification of the project's
202 record.
203  
204 =head3 description
205  
206 Return a description of the project.
207  
208 =head3 homepage_url
209  
210 Return the URL of the project's homepage.
211  
212 =head3 download_url
213  
214 Return an url to a project download.
215  
216 =head3 irc_url
217  
218 Return a URL to an IRC channel associated to the project.
219  
220 =head3 stack_count
221  
222 Return the number of stacks currently using the project.
223  
224 =head3 average_rating
225  
226 Return a number ranging from 1.0 to 5.0, representing the average
227 value of all user ratings for this project, where 1 is the worst possible rating,
228 and 5 the best.
229  
230 =head3 rating_count
231  
232 Return the number of users having rated this project.
233  
234 =head3 analysis_id
235  
236 Return the id of the current analysis associated with the project.
237 It'll be the latest
238 analysis if the project has been retrieved via C<get_project>, and
239 will be null if retrieved via C<get_projects>.
240  
241 =head3 analysis( $id )
242  
243 Return the Ohloh analysis I<$id> (which can also be the
244 keyword 'latest') as an L<WWW::Ohloh::API::Analysis>
245 object. If I<$id> is omitted, return the previously requested
246 analysis for this project or, if none has been requested yet,
247 the latest analysis available for the project.
248  
249 =head3 activity_facts( $analysis_id )
250  
251 Return activity facts related to the project as a
252 L<WWW::Ohloh::API::ActivityFacts> object. The activity facts
253 are taken from the analysis specified by I<$analysis_id>.
254 If C<$analysis_id> is not given, the previously called
255 analysis will be used and, if no analysis has been explicitly
256 called, the latest one will be used.
257  
258 $project = $ohloh->get_project( 12345); # retrieve the project
259  
260 $latest = $project->activity_facts; # get the latest facts
261  
262 $specific = $project->activity_facts( 789 ); # get facts from analysis 789
263  
264 $project->analysis( 789 );
265 $specific = $project->activity_facts; # equivalent to previous example
266  
267  
268 =head3 factoids
269  
270 @factoids = $project->factoids;
271  
272 Return the factoids associated with the project
273 as L<WWW::Ohloh::API::Factoid> objects.
274  
275 =head2 Other Methods
276  
277 =head3 as_xml
278  
279 Return the account information (including the kudo score if it applies)
280 as an XML string. Note that this is not the exact xml document as returned
281 by the Ohloh server.
282  
283 Factoids will be included in the xml output if
284 they have been queried prior to the call to I<as_xml>.
285  
286  
287 =head1 SEE ALSO
288  
289 =over
290  
291 =item *
292  
293 L<WWW::Ohloh::API>,
294 L<WWW::Ohloh::API::KudoScore>,
295 L<WWW::Ohloh::API::Factoid>,
296 L<WWW::Ohloh::API::Analysis>,
297 L<WWW::Ohloh::API::Account>.
298  
299  
300 =item *
301  
302 Ohloh API reference: http://www.ohloh.net/api/getting_started
303  
304 =item *
305  
306 Ohloh Account API reference: http://www.ohloh.net/api/reference/project
307  
308 =back
309  
310 =head1 VERSION
311  
312 This document describes WWW::Ohloh::API version 0.3.2
313  
314 =head1 BUGS AND LIMITATIONS
315  
316 WWW::Ohloh::API is very extremely alpha quality. It'll improve,
317 but till then: I<Caveat emptor>.
318  
319 The C<as_xml()> method returns a re-encoding of the account data, which
320 can differ of the original xml document sent by the Ohloh server.
321  
322 Please report any bugs or feature requests to
323 C<bug-www-ohloh-api@rt.cpan.org>, or through the web interface at
324 L<http://rt.cpan.org>.
325  
326  
327 =head1 AUTHOR
328  
329 Yanick Champoux C<< <yanick@cpan.org> >>
330  
331 =head1 LICENCE AND COPYRIGHT
332  
333 Copyright (c) 2008, Yanick Champoux C<< <yanick@cpan.org> >>. All rights reserved.
334  
335 This module is free software; you can redistribute it and/or
336 modify it under the same terms as Perl itself. See L<perlartistic>.
337  
338  
339  
« blib/lib/WWW/Ohloh/API.pm ↑ Summary blib/lib/WWW/Ohloh/API/Stack.pm »