API/Project.pm

filter: Statementstmt 89.9% 89 / 99 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.8% 116 / 151 CC 15 SCAR 20.4
CC
15
Cov
79%
activity_facts
30.0
as_xml
5.6
analysis
3.8
CRAP 7.7
« API.pm ↑ Summary API/Stack.pm »
1 package WWW::Ohloh::API::Project;
2 29 our $AUTHORITY = 'cpan:YANICK';
3  
4 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 29 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 29 ▶use Object::InsideOut;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 29 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 29 ▶use WWW::Ohloh::API::Analysis;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 29 ▶use WWW::Ohloh::API::ContributorFact;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 29 our $VERSION = '1.0_1';
14  
15 29 my @request_url_of : Field : Arg(request_url) : Get( request_url );
16 29 my @ohloh_of : Field : Arg(ohloh) : Get( _ohloh );
17 29 my @xml_of : Field : Arg(xml);
18  
19 29 my @id_of : Field : Get(id) : Set(_set_id);
20 29 my @name_of : Field : Get(name) : Set(_set_name);
21 29 my @created_at_of : Field : Get(created_at) : Set(_set_created_at);
22 29 my @updated_at_of : Field : Get(updated_at) : Set(_set_updated_at);
23 29 my @description_of : Field : Get(description) : Set(_set_description);
24 29 my @homepage_url_of : Field : Get(homepage_url) : Set(_set_homepage_url);
25 29 my @download_url_of : Field : Get(download_url) : Set(_set_download_url);
26 29 my @irc_url_of : Field : Get(irc_url) : Set(_set_irc_url);
27 29 my @stack_count_of : Field : Get(stack_count) : Set(_set_stack_count);
28 29 my @average_rating_of : Field : Get(average_rating) :
29 Set(_set_average_rating);
30 29 my @rating_count_of : Field : Get(rating_count) : Set(_set_rating_count);
31 29 my @analysis_id_of : Field : Get(analysis_id) : Set(_set_analysis_id);
32 29 my @analysis_of : Field;
33 29 my @facts_of : Field;
34 29 my @factoids_of : Field;
35  
36 29 my @contributors_of : Field;
37  
38 37 ▶sub _init : Init {
Subroutine _init: called CC=3 SCAR=11.0
39 37 my $self = shift;
40  
41 37 ▶ my $dom = $xml_of[$$self] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $dom = $xml_of[$$self] or return 37 0 37
42  
43 37 $self->_set_id( $dom->findvalue('id/text()') );
44 37 $self->_set_name( $dom->findvalue('name/text()') );
45 37 $self->_set_created_at( $dom->findvalue('created_at/text()') );
46 37 $self->_set_updated_at( $dom->findvalue('updated_at/text()') );
47 37 $self->_set_description( $dom->findvalue('description/text()') );
48 37 $self->_set_homepage_url( $dom->findvalue('homepage_url/text()') );
49 37 $self->_set_download_url( $dom->findvalue('download_url/text()') );
50 37 $self->_set_irc_url( $dom->findvalue('irc_url/text()') );
51 37 $self->_set_stack_count( $dom->findvalue('stack_count/text()') );
52 37 $self->_set_average_rating( $dom->findvalue('average_rating/text()') );
53 37 $self->_set_rating_count( $dom->findvalue('rating_count/text()') );
54 37 $self->_set_analysis_id( $dom->findvalue('analysis_id/text()') );
55  
56 37 ▶ if ( my ($n) = $dom->findnodes('analysis[1]') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($n) = $dom->findnodes("analysis[1]")) 2 35 37
57 2 $analysis_of[$$self] = WWW::Ohloh::API::Analysis->new( xml => $n );
58 }
59  
60 37 return;
61 29 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64  
65 2 ▶sub analysis {
Subroutine analysis: called CC=3 SCAR=13.5
Pod documented
66 2 my $self = shift;
67 2 my $id = shift;
68  
69 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
70 0 $analysis_of[$$self] =
71 $ohloh_of[$$self]->fetch_analysis( $self->id, $id );
72 0 $analysis_id_of[$$self] = $analysis_of[$$self]->id;
73 }
74  
75 2 return $analysis_of[$$self];
76 }
77  
78 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79  
80 0 ▶sub activity_facts {
Subroutine activity_facts: not called CC=5 SCAR=34.0
Pod documented
81 0 my $self = shift;
82 0 my $id = shift;
83  
84 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
85 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
86 $ohloh_of[$$self]->fetch_activity_facts( $self->id,
87 $id || $self->analysis_id || 'latest' );
88 }
89  
90 0 return $facts_of[$$self];
91 }
92  
93 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94  
95 1 ▶sub as_xml {
Subroutine as_xml: called CC=5 SCAR=17.3
Pod documented
96 1 my $self = shift;
97 1 my $xml;
98 1 my $w = XML::Writer->new( OUTPUT => \$xml );
99  
100 1 $w->startTag('project');
101 1 for my $attr (
102 qw/ id name created_at updated_at
103 description homepage_url
104 download_url irc_url stack_count
105 average_rating rating_count
106 analysis_id /
107 ) {
108 12 $w->dataElement( $attr, $self->$attr );
109 }
110 1 ▶ $xml .= $self->analysis->as_xml if $analysis_of[$$self];
Branch: 1 branch
BranchTrueFalseTotal
if $analysis_of[$$self] 1 0 1
111  
112 1 ▶ if ( my $factoids = $factoids_of[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $factoids = $factoids_of[$$self]) 0 1 1
113 0 $xml .= '<factoids>';
114 0 $xml .= $_->as_xml for @$factoids;
115 0 $xml .= '</factoids>';
116 }
117  
118 1 $w->endTag;
119  
120 1 return $xml;
121 }
122  
123 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124  
125 1 ▶sub contributors {
Subroutine contributors: called CC=2 SCAR=7.0
Pod undocumented
126 1 my $self = shift;
127  
128 1 ▶ unless ( $contributors_of[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($contributors_of[$$self]) 1 0 1
129 1 my ( $url, $xml ) = $self->_ohloh->_query_server(
130 'projects/' . $self->id . '/contributors.xml' );
131  
132 $contributors_of[$$self] = [
133 map {
134 1 WWW::Ohloh::API::ContributorFact->new(
135 request_url => $url,
136 xml => $_,
137 ohloh => $self->_ohloh
138 )
139 } $xml->findnodes('//contributor_fact') ];
140 }
141  
142 1 return @{ $contributors_of[$$self] };
143 }
144  
145 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146  
147 2 ▶sub factoids {
Subroutine factoids: called CC=2 SCAR=6.9
Pod documented
148 2 my $self = shift;
149  
150 2 ▶ unless ( defined $factoids_of[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $factoids_of[$$self]) 1 1 2
151 1 $factoids_of[$$self] =
152 [ $ohloh_of[$$self]->fetch_factoids( $self->id ) ];
153 }
154  
155 2 return @{ $factoids_of[$$self] };
156 }
157  
158 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
159  
160 29 'end of WWW::Ohloh::API::Project';
161  
162 __END__
« API.pm ↑ Summary API/Stack.pm »