| 1 | package WWW::Ohloh::API::ContributorFact; | ||||||||||
| 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 | |||||||||||
| 10 | 15 | our $VERSION = '0.3.2'; | |||||||||
| 11 | |||||||||||
| 12 | 15 | my @ohloh_of : Field : Arg(ohloh) : Get(_ohloh); | |||||||||
| 13 | 15 | my @request_url_of : Field : Arg(request_url) : Get( request_url ); | |||||||||
| 14 | 15 | my @xml_of : Field : Arg(xml); | |||||||||
| 15 | |||||||||||
| 16 | 15 | my @api_fields = qw/ | |||||||||
| 17 | analysis_id | ||||||||||
| 18 | contributor_id | ||||||||||
| 19 | contributor_name | ||||||||||
| 20 | account_id | ||||||||||
| 21 | account_name | ||||||||||
| 22 | primary_language_id | ||||||||||
| 23 | primary_language_nice_name | ||||||||||
| 24 | comment_ratio | ||||||||||
| 25 | first_commit_time | ||||||||||
| 26 | last_commit_time | ||||||||||
| 27 | man_months | ||||||||||
| 28 | commits | ||||||||||
| 29 | median_commits | ||||||||||
| 30 | contributor_language_facts | ||||||||||
| 31 | /; | ||||||||||
| 32 | |||||||||||
| 33 | 15 | my @analysis_id_of : Field : Set(_set_analysis_id) : Get(analysis_id); | |||||||||
| 34 | 15 | my @contributor_id_of : Field : Set(_set_contributor_id) : | |||||||||
| 35 | Get(contributor_id); | ||||||||||
| 36 | 15 | my @contributor_name_of : Field : Set(_set_contributor_name) : | |||||||||
| 37 | Get(contributor_name); | ||||||||||
| 38 | 15 | my @account_id_of : Field : Set(_set_account_id) : Get(account_id); | |||||||||
| 39 | 15 | my @account_name_of : Field : Set(_set_account_name) : Get(account_name); | |||||||||
| 40 | 15 | my @primary_language_id_of : Field : Set(_set_primary_language_id) : | |||||||||
| 41 | Get(primary_language_id); | ||||||||||
| 42 | 15 | my @primary_language_nice_name_of : Field : | |||||||||
| 43 | Set(_set_primary_language_nice_name) : Get(primary_language_nice_name); | ||||||||||
| 44 | 15 | my @comment_ratio_of : Field : Set(_set_comment_ratio) : Get(comment_ratio); | |||||||||
| 45 | 15 | my @first_commit_time_of : Field : Set(_set_first_commit_time) : | |||||||||
| 46 | Get(first_commit_time); | ||||||||||
| 47 | 15 | my @last_commit_time_of : Field : Set(_set_last_commit_time) : | |||||||||
| 48 | Get(last_commit_time); | ||||||||||
| 49 | 15 | my @man_months_of : Field : Set(_set_man_months) : Get(man_months); | |||||||||
| 50 | 15 | my @commits_of : Field : Set(_set_commits) : Get(commits); | |||||||||
| 51 | 15 | my @median_commits_of : Field : Set(_set_median_commits) : | |||||||||
| 52 | Get(median_commits); | ||||||||||
| 53 | 15 | my @contributor_language_facts_of : Field : | |||||||||
| 54 | Set(_set_contributor_language_facts) : Get(contributor_language_facts); | ||||||||||
| 55 | |||||||||||
| 56 | 15 | my @account_of : Field; | |||||||||
| 57 | |||||||||||
| 58 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 59 | |||||||||||
| 60 | sub _init : Init { | ||||||||||
| 61 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_init: called CC=2 SCAR=6.9
| |||||||||||
| 62 | |||||||||||
| 63 | 1 | ▶ | my $dom = $xml_of[$$self] or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | |||||||||||
| 65 | 1 | $self->_set_analysis_id( $dom->findvalue("analysis_id/text()") ); | |||||||||
| 66 | 1 | $self->_set_contributor_id( $dom->findvalue("contributor_id/text()") ); | |||||||||
| 67 | 1 | $self->_set_contributor_name( | |||||||||
| 68 | $dom->findvalue("contributor_name/text()") ); | ||||||||||
| 69 | 1 | $self->_set_account_id( $dom->findvalue("account_id/text()") ); | |||||||||
| 70 | 1 | $self->_set_account_name( $dom->findvalue("account_name/text()") ); | |||||||||
| 71 | 1 | $self->_set_primary_language_id( | |||||||||
| 72 | $dom->findvalue("primary_language_id/text()") ); | ||||||||||
| 73 | 1 | $self->_set_primary_language_nice_name( | |||||||||
| 74 | $dom->findvalue("primary_language_nice_name/text()") ); | ||||||||||
| 75 | 1 | $self->_set_comment_ratio( $dom->findvalue("comment_ratio/text()") ); | |||||||||
| 76 | 1 | $self->_set_first_commit_time( | |||||||||
| 77 | $dom->findvalue("first_commit_time/text()") ); | ||||||||||
| 78 | 1 | $self->_set_last_commit_time( | |||||||||
| 79 | $dom->findvalue("last_commit_time/text()") ); | ||||||||||
| 80 | 1 | $self->_set_man_months( $dom->findvalue("man_months/text()") ); | |||||||||
| 81 | 1 | $self->_set_commits( $dom->findvalue("commits/text()") ); | |||||||||
| 82 | 1 | $self->_set_median_commits( $dom->findvalue("median_commits/text()") ); | |||||||||
| 83 | 1 | $self->_set_contributor_language_facts( | |||||||||
| 84 | $dom->findvalue("contributor_language_facts/text()") ); | ||||||||||
| 85 | |||||||||||
| 86 | 15 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 87 | |||||||||||
| 88 | sub as_xml { | ||||||||||
| 89 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
as_xml: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 90 | 1 | my $xml; | |||||||||
| 91 | 1 | my $w = XML::Writer->new( OUTPUT => \$xml ); | |||||||||
| 92 | |||||||||||
| 93 | 1 | $w->startTag('contributor_fact'); | |||||||||
| 94 | |||||||||||
| 95 | 1 | for my $attr (@api_fields) { | |||||||||
| 96 | 14 | $w->dataElement( $attr => $self->$attr ); | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 1 | ▶ | if ( my $a = $account_of[$$self] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 1 | $xml .= $a->as_xml; | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | 1 | $w->endTag; | |||||||||
| 104 | |||||||||||
| 105 | 1 | return $xml; | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | sub account { | ||||||||||
| 109 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
account: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||
| 110 | |||||||||||
| 111 | 1 | ▶ | return $account_of[$$self] if $account_of[$$self]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | |||||||||||
| 113 | 1 | ▶ | my $id = $self->account_id or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | |||||||||||
| 115 | 1 | return $account_of[$$self] = $self->_ohloh->get_account( id => $id ); | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | 15 | 'end of WWW::Ohloh::API::ContributorFact'; | |||||||||
| 119 | |||||||||||
| 120 | __END__ | ||||||||||
| 121 | |||||||||||
| 122 | =head1 NAME | ||||||||||
| 123 | |||||||||||
| 124 | WWW::Ohloh::API::ContributorFact - Ohloh stats about a project's contributor | ||||||||||
| 125 | |||||||||||
| 126 | =head1 SYNOPSIS | ||||||||||
| 127 | |||||||||||
| 128 | use WWW::Ohloh::API; | ||||||||||
| 129 | |||||||||||
| 130 | my $ohloh = WWW::Ohloh::API->new( api_key => $my_api_key ); | ||||||||||
| 131 | my $project = $ohloh->get_project( id => 12933 ); | ||||||||||
| 132 | |||||||||||
| 133 | my @contributors = $project->contributors; | ||||||||||
| 134 | |||||||||||
| 135 | =head1 DESCRIPTION | ||||||||||
| 136 | |||||||||||
| 137 | W::O::A::ContributorFact contains the information associated with | ||||||||||
| 138 | a contributor to a project | ||||||||||
| 139 | as defined at http://www.ohloh.net/api/reference/contributori_fact. | ||||||||||
| 140 | To be properly populated, it must be created via | ||||||||||
| 141 | the C<get_project> method of a L<WWW::Ohloh::API> object. | ||||||||||
| 142 | |||||||||||
| 143 | =head1 METHODS | ||||||||||
| 144 | |||||||||||
| 145 | =head2 API Data Accessors | ||||||||||
| 146 | |||||||||||
| 147 | =head3 analysis_id | ||||||||||
| 148 | |||||||||||
| 149 | Return the id of the analysis which provided the data for | ||||||||||
| 150 | the contributor_fact. | ||||||||||
| 151 | |||||||||||
| 152 | =head3 contributor_id | ||||||||||
| 153 | |||||||||||
| 154 | Return the id of the contributor, which is unique | ||||||||||
| 155 | within the scope of the project, but not globally. | ||||||||||
| 156 | |||||||||||
| 157 | =head3 contributor_name | ||||||||||
| 158 | |||||||||||
| 159 | Return the name used by the contrinutor when committing to | ||||||||||
| 160 | the source control server. | ||||||||||
| 161 | |||||||||||
| 162 | =head3 account_id | ||||||||||
| 163 | |||||||||||
| 164 | Return the Ohloh account id of the contributor, if the | ||||||||||
| 165 | contribution has been claimed. If not, return I<undef>. | ||||||||||
| 166 | |||||||||||
| 167 | |||||||||||
| 168 | =head3 account_name | ||||||||||
| 169 | |||||||||||
| 170 | Return the account name of the contributor, if the contribution | ||||||||||
| 171 | has been claimed, or I<undef> otherwise. | ||||||||||
| 172 | configured. | ||||||||||
| 173 | |||||||||||
| 174 | =head3 primary_language_id | ||||||||||
| 175 | |||||||||||
| 176 | Return the id of the language most used by the contributor. | ||||||||||
| 177 | |||||||||||
| 178 | =head3 primary_language_nice_name | ||||||||||
| 179 | |||||||||||
| 180 | Return the name of the language most used by the contributor. | ||||||||||
| 181 | |||||||||||
| 182 | =head3 comment_ratio | ||||||||||
| 183 | |||||||||||
| 184 | Return the ratio of lines committed by this contributor | ||||||||||
| 185 | that are comments. | ||||||||||
| 186 | |||||||||||
| 187 | =head3 first_commit_time, last_commit_time | ||||||||||
| 188 | |||||||||||
| 189 | Return the time of the first/last commit by this | ||||||||||
| 190 | contributor. | ||||||||||
| 191 | |||||||||||
| 192 | =head3 man_months | ||||||||||
| 193 | |||||||||||
| 194 | The total number of months for which this contributor made at least | ||||||||||
| 195 | one commit. | ||||||||||
| 196 | |||||||||||
| 197 | =head3 commits | ||||||||||
| 198 | |||||||||||
| 199 | Return the total number of commits made by this contributor. | ||||||||||
| 200 | |||||||||||
| 201 | =head3 median_commits | ||||||||||
| 202 | |||||||||||
| 203 | Return the median number of commits by this contributor | ||||||||||
| 204 | by active month. | ||||||||||
| 205 | |||||||||||
| 206 | =head3 contributor_language_facts | ||||||||||
| 207 | |||||||||||
| 208 | Return a list of L<WWW::Ohloh::API::ContributorLanguageFact> objects | ||||||||||
| 209 | containing the information pertaining to this contributor. | ||||||||||
| 210 | |||||||||||
| 211 | =head2 Other Methods | ||||||||||
| 212 | |||||||||||
| 213 | =head3 as_xml | ||||||||||
| 214 | |||||||||||
| 215 | Return the account information (including the account information | ||||||||||
| 216 | and contributor language facts, if they have been retrieved) | ||||||||||
| 217 | as an XML string. Note that this is not the exact xml document as returned | ||||||||||
| 218 | by the Ohloh server. | ||||||||||
| 219 | |||||||||||
| 220 | =head1 SEE ALSO | ||||||||||
| 221 | |||||||||||
| 222 | =over | ||||||||||
| 223 | |||||||||||
| 224 | =item * | ||||||||||
| 225 | |||||||||||
| 226 | L<WWW::Ohloh::API>, L<WWW::Ohloh::API::KudoScore>. | ||||||||||
| 227 | |||||||||||
| 228 | =item * | ||||||||||
| 229 | |||||||||||
| 230 | Ohloh API reference: http://www.ohloh.net/api/getting_started | ||||||||||
| 231 | |||||||||||
| 232 | =item * | ||||||||||
| 233 | |||||||||||
| 234 | Ohloh Account API reference: | ||||||||||
| 235 | http://www.ohloh.net/api/reference/contributor_fact | ||||||||||
| 236 | |||||||||||
| 237 | =back | ||||||||||
| 238 | |||||||||||
| 239 | =head1 VERSION | ||||||||||
| 240 | |||||||||||
| 241 | This document describes WWW::Ohloh::API::ContributorFact version 0.3.2 | ||||||||||
| 242 | |||||||||||
| 243 | =head1 BUGS AND LIMITATIONS | ||||||||||
| 244 | |||||||||||
| 245 | WWW::Ohloh::API is very extremely alpha quality. It'll improve, | ||||||||||
| 246 | but till then: I<Caveat emptor>. | ||||||||||
| 247 | |||||||||||
| 248 | The C<as_xml()> method returns a re-encoding of the account data, which | ||||||||||
| 249 | can differ of the original xml document sent by the Ohloh server. | ||||||||||
| 250 | |||||||||||
| 251 | Please report any bugs or feature requests to | ||||||||||
| 252 | C<bug-www-ohloh-api@rt.cpan.org>, or through the web interface at | ||||||||||
| 253 | L<http://rt.cpan.org>. | ||||||||||
| 254 | |||||||||||
| 255 | |||||||||||
| 256 | =head1 AUTHOR | ||||||||||
| 257 | |||||||||||
| 258 | Yanick Champoux C<< <yanick@cpan.org> >> | ||||||||||
| 259 | |||||||||||
| 260 | =head1 LICENCE AND COPYRIGHT | ||||||||||
| 261 | |||||||||||
| 262 | Copyright (c) 2008, Yanick Champoux C<< <yanick@cpan.org> >>. All rights reserved. | ||||||||||
| 263 | |||||||||||
| 264 | This module is free software; you can redistribute it and/or | ||||||||||
| 265 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||
| 266 | |||||||||||
| 267 | |||||||||||
| 268 | |||||||||||