File Coverage

blib/lib/WWW/Ohloh/API/ContributorFact.pm
Criterion Covered Total %
statement 32 48 66.6
branch 3 8 37.5
condition n/a
subroutine 8 9 88.8
pod 1 2 50.0
total 44 67 65.6


line stmt bran cond sub pod time code
1             package WWW::Ohloh::API::ContributorFact;
2             our $AUTHORITY = 'cpan:YANICK';
3              
4 30     30   238686 use strict;
  30         81  
  30         1155  
5 30     30   152 use warnings;
  30         54  
  30         1506  
6              
7 30     30   181 use Carp;
  30         55  
  30         2149  
8 30     30   1103 use Object::InsideOut;
  30         45455  
  30         230  
9 30     30   3751 use XML::LibXML;
  30         36267  
  30         222  
10              
11             our $VERSION = '1.0_1';
12              
13             my @ohloh_of : Field : Arg(ohloh) : Get(_ohloh);
14             my @request_url_of : Field : Arg(request_url) : Get( request_url );
15             my @xml_of : Field : Arg(xml);
16              
17             my @api_fields = qw/
18             analysis_id
19             contributor_id
20             contributor_name
21             account_id
22             account_name
23             primary_language_id
24             primary_language_nice_name
25             comment_ratio
26             first_commit_time
27             last_commit_time
28             man_months
29             commits
30             median_commits
31             contributor_language_facts
32             /;
33              
34             my @analysis_id_of : Field : Set(_set_analysis_id) : Get(analysis_id);
35             my @contributor_id_of : Field : Set(_set_contributor_id) :
36             Get(contributor_id);
37             my @contributor_name_of : Field : Set(_set_contributor_name) :
38             Get(contributor_name);
39             my @account_id_of : Field : Set(_set_account_id) : Get(account_id);
40             my @account_name_of : Field : Set(_set_account_name) : Get(account_name);
41             my @primary_language_id_of : Field : Set(_set_primary_language_id) :
42             Get(primary_language_id);
43             my @primary_language_nice_name_of : Field :
44             Set(_set_primary_language_nice_name) : Get(primary_language_nice_name);
45             my @comment_ratio_of : Field : Set(_set_comment_ratio) : Get(comment_ratio);
46             my @first_commit_time_of : Field : Set(_set_first_commit_time) :
47             Get(first_commit_time);
48             my @last_commit_time_of : Field : Set(_set_last_commit_time) :
49             Get(last_commit_time);
50             my @man_months_of : Field : Set(_set_man_months) : Get(man_months);
51             my @commits_of : Field : Set(_set_commits) : Get(commits);
52             my @median_commits_of : Field : Set(_set_median_commits) :
53             Get(median_commits);
54             my @contributor_language_facts_of : Field :
55             Set(_set_contributor_language_facts) : Get(contributor_language_facts);
56              
57             my @account_of : Field;
58              
59             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60              
61             sub _init : Init {
62 0     0   0 my $self = shift;
63              
64 0 0       0 my $dom = $xml_of[$$self] or return;
65              
66 0         0 $self->_set_analysis_id( $dom->findvalue("analysis_id/text()") );
67 0         0 $self->_set_contributor_id( $dom->findvalue("contributor_id/text()") );
68 0         0 $self->_set_contributor_name(
69             $dom->findvalue("contributor_name/text()") );
70 0         0 $self->_set_account_id( $dom->findvalue("account_id/text()") );
71 0         0 $self->_set_account_name( $dom->findvalue("account_name/text()") );
72 0         0 $self->_set_primary_language_id(
73             $dom->findvalue("primary_language_id/text()") );
74 0         0 $self->_set_primary_language_nice_name(
75             $dom->findvalue("primary_language_nice_name/text()") );
76 0         0 $self->_set_comment_ratio( $dom->findvalue("comment_ratio/text()") );
77 0         0 $self->_set_first_commit_time(
78             $dom->findvalue("first_commit_time/text()") );
79 0         0 $self->_set_last_commit_time(
80             $dom->findvalue("last_commit_time/text()") );
81 0         0 $self->_set_man_months( $dom->findvalue("man_months/text()") );
82 0         0 $self->_set_commits( $dom->findvalue("commits/text()") );
83 0         0 $self->_set_median_commits( $dom->findvalue("median_commits/text()") );
84 0         0 $self->_set_contributor_language_facts(
85             $dom->findvalue("contributor_language_facts/text()") );
86              
87 30     30   20946 }
  30         68  
  30         286  
88              
89             sub as_xml {
90 1     1 1 2903 my $self = shift;
91 1         4 my $xml;
92 1         14 my $w = XML::Writer->new( OUTPUT => \$xml );
93              
94 1         309 $w->startTag('contributor_fact');
95              
96 1         147 for my $attr (@api_fields) {
97 14         1642 $w->dataElement( $attr => $self->$attr );
98             }
99              
100 1 50       72 if ( my $a = $account_of[$$self] ) {
101 1         7 $xml .= $a->as_xml;
102             }
103              
104 1         4 $w->endTag;
105              
106 1         69 return $xml;
107             }
108              
109             sub account {
110 1     1 0 18726 my $self = shift;
111              
112 1 50       7 return $account_of[$$self] if $account_of[$$self];
113              
114 1 50       43 my $id = $self->account_id or return;
115              
116 1         43 return $account_of[$$self] = $self->_ohloh->fetch_account($id);
117             }
118              
119             'end of WWW::Ohloh::API::ContributorFact';
120              
121             __END__