API/Account.pm

filter: Statementstmt 99.0% 101 / 102 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 22 / 22 Podpod 33.3% 3 / 9 totaltotal 82.8% 135 / 163 CC 11 SCAR 6.7
CC
11
Cov
89%
stack
4.4
as_xml
3.0
kudos
2.3
CRAP 2.0
« API/Language.pm ↑ Summary API/Kudo.pm »
1 package WWW::Ohloh::API::Account;
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 qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
9 WWW::Ohloh::API::Role::Fetchable
10 29 WWW::Ohloh::API::Role::LoadXML /;
11 29 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 29 ▶use WWW::Ohloh::API::KudoScore;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 29 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 29 ▶use Date::Parse;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 29 ▶use Params::Validate qw/ validate validate_with /;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 29 ▶use Digest::MD5 qw/ md5_hex /;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 29 our $VERSION = '1.0_1';
21  
22 29 ▶use overload '""' => sub { $_[0]->name };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
23  
24 #<<<
25 29 my @id_of : Field
26 : Set(_set_id)
27 : Get(id)
28 ;
29 29 my @name_of : Field
30 : Set(_set_name)
31 : Get(name)
32 ;
33 29 my @creation_date_of : Field
34 : Set(_set_created_at)
35 : Get(created_at)
36 : Type(Time::Piece)
37 ;
38 29 my @update_date_of : Field
39 : Set(_set_updated_at)
40 : Get(updated_at)
41 : Type(Time::Piece)
42 ;
43 29 my @homepage_url_of : Field
44 : Set(_set_homepage_url)
45 : Get(homepage_url)
46 ;
47 29 my @avatar_url_of : Field
48 : Set(_set_avatar_url)
49 : Get(avatar_url)
50 ;
51 29 my @posts_count_of : Field
52 : Set(_set_posts_count)
53 : Get(posts_count)
54 ;
55 29 my @location_of : Field
56 : Set(_set_location)
57 : Get(location)
58 ;
59 29 my @latitude_of : Field
60 : Set(_set_latitude)
61 : Get(latitude)
62 ;
63 29 my @longitude_of : Field
64 : Set(_set_longitude)
65 : Get(longitude)
66 ;
67 29 my @country_code_of : Field
68 : Set(_set_country_code)
69 : Get(country_code)
70 ;
71 29 my @kudo_of : Field
72 : Set(_set_kudo)
73 : Get(kudo_score)
74 ;
75 #>>>
76 29 my @kudos_of : Field : Arg(kudos);
77  
78 29 my @stack : Field;
79  
80 5 ▶sub element_name { return 'account' }
Subroutine element_name: called CC=1 SCAR=0.0
Pod undocumented
81  
82 5 ▶sub generate_query_url : Chained(bottom up) {
Subroutine generate_query_url: called CC=2 SCAR=7.1
Pod undocumented
83 5 my ( $self, @args ) = @_;
84  
85 5 my %param = validate_with(
86 params => \@args,
87 spec => { id => 1 },
88 allow_extra => 1
89 );
90 5 my $id = $param{id};
91 5 delete $param{id};
92  
93 5 ▶ if ( index( $id, '@' ) > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($id, "\@") != -1) 0 5 5
94 0 $id = md5_hex($id);
95 }
96  
97 5 return ( "accounts/$id.xml", ohloh => $param{ohloh} );
98 29 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
99  
100 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101  
102 9 ▶sub load_xml {
Subroutine load_xml: called CC=2 SCAR=6.9
Pod undocumented
103 9 my ( $self, $dom ) = @_;
104  
105 9 $self->_set_id( $dom->findvalue('id/text()') );
106 9 $self->_set_name( $dom->findvalue('name/text()') );
107 9 $self->_set_created_at(
108 scalar Time::Piece::gmtime(
109 str2time( $dom->findvalue('created_at/text()') ) ) );
110 9 $self->_set_updated_at(
111 scalar Time::Piece::gmtime(
112 str2time( $dom->findvalue('updated_at/text()') ) ) );
113 9 $self->_set_homepage_url( $dom->findvalue('homepage_url/text()') );
114 9 $self->_set_avatar_url( $dom->findvalue('avatar_url/text()') );
115 9 $self->_set_posts_count( $dom->findvalue('posts_count/text()') );
116 9 $self->_set_location( $dom->findvalue('location/text()') );
117 9 $self->_set_country_code( $dom->findvalue('country_code/text()') );
118 9 $self->_set_latitude( $dom->findvalue('latitude/text()') );
119 9 $self->_set_longitude( $dom->findvalue('longitude/text()') );
120  
121 9 ▶ if ( my ($node) = $dom->findnodes('kudo_score[1]') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($node) = $dom->findnodes("kudo_score[1]")) 9 0 9
122 9 $kudo_of[$$self] = WWW::Ohloh::API::KudoScore->new( xml => $node );
123 }
124 }
125  
126 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127  
128 2 ▶sub as_xml {
Subroutine as_xml: called CC=3 SCAR=11.0
Pod documented
129 2 my $self = shift;
130 2 my $xml;
131 2 my $w = XML::Writer->new( OUTPUT => \$xml );
132  
133 2 $w->startTag('account');
134  
135 2 $w->dataElement( $_ => $self->$_ ) for qw/
136 id name created_at updated_at homepage_url
137 avatar_url posts_count
138 location
139 country_code
140 latitude
141 longitude
142 /;
143  
144 2 ▶ $xml .= $self->kudo->as_xml if $self->kudo;
Branch: 1 branch
BranchTrueFalseTotal
if $self->kudo 2 0 2
145  
146 2 $w->endTag;
147  
148 2 return $xml;
149 }
150  
151 4 ▶sub kudoScore {
Subroutine kudoScore: called CC=1 SCAR=0.0
Pod documented
152 4 my $self = shift;
153 4 return $kudo_of[$$self];
154 }
155  
156 # aliases
157 29 *kudo = *kudoScore;
158  
159 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
160  
161 1 ▶sub stack {
Subroutine stack: called CC=4 SCAR=14.8
Pod documented
162 1 my $self = shift;
163  
164 1 my $retrieve = shift;
165 1 ▶ $retrieve = 1 unless defined $retrieve;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $retrieve 1 0 1
166  
167 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
168 1 $stack[$$self] = $self->ohloh->fetch_account_stack( $self->id );
169 1 $stack[$$self]->set_account($self);
170 }
171  
172 1 return $stack[$$self];
173 }
174  
175 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
176  
177 1 ▶sub sent_kudos {
Subroutine sent_kudos: called CC=2 SCAR=7.6
Pod undocumented
178 1 my $self = shift;
179  
180 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
181  
182 1 return $kudos_of[$$self]->sent;
183 }
184  
185 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186  
187 1 ▶sub received_kudos {
Subroutine received_kudos: called CC=2 SCAR=7.6
Pod undocumented
188 1 my $self = shift;
189  
190 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
191  
192 1 return $kudos_of[$$self]->received;
193 }
194  
195 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
196  
197 1 ▶sub kudos {
Subroutine kudos: called CC=2 SCAR=8.1
Pod undocumented
198 1 my $self = shift;
199  
200 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
201 }
202  
203 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
204  
205 29 'end of WWW::Ohloh::API::Account';
206  
207 __END__
« API/Language.pm ↑ Summary API/Kudo.pm »