File Coverage

blib/lib/WWW/Ohloh/API/Account.pm
Criterion Covered Total %
statement 77 84 91.6
branch 4 10 40.0
condition 4 12 33.3
subroutine 21 22 95.4
pod 3 9 33.3
total 109 137 79.5


line stmt bran cond sub pod time code
1             package WWW::Ohloh::API::Account;
2             our $AUTHORITY = 'cpan:YANICK';
3              
4 29     29   244806 use strict;
  29         58  
  29         1144  
5 29     29   149 use warnings;
  29         55  
  29         1473  
6              
7 29     29   176 use Carp;
  29         53  
  29         2185  
8 29         366 use Object::InsideOut qw/
9             WWW::Ohloh::API::Role::Fetchable
10 29     29   928 WWW::Ohloh::API::Role::LoadXML /;
  29         44838  
11 29     29   4990 use XML::LibXML;
  29         40097  
  29         642  
12 29     29   21238 use WWW::Ohloh::API::KudoScore;
  29         115  
  29         214  
13 29     29   21520 use Time::Piece;
  29         311103  
  29         228  
14 29     29   18113 use Date::Parse;
  29         181628  
  29         5340  
15              
16 29     29   256 use Params::Validate qw/ validate validate_with /;
  29         60  
  29         2035  
17              
18 29     29   179 use Digest::MD5 qw/ md5_hex /;
  29         63  
  29         3376  
19              
20             our $VERSION = '1.0_1';
21              
22 29     29   229 use overload '""' => sub { $_[0]->name };
  29     9   107  
  29         334  
  9         596  
23              
24             #<<<
25             my @id_of : Field
26             : Set(_set_id)
27             : Get(id)
28             ;
29             my @name_of : Field
30             : Set(_set_name)
31             : Get(name)
32             ;
33             my @creation_date_of : Field
34             : Set(_set_created_at)
35             : Get(created_at)
36             : Type(Time::Piece)
37             ;
38             my @update_date_of : Field
39             : Set(_set_updated_at)
40             : Get(updated_at)
41             : Type(Time::Piece)
42             ;
43             my @homepage_url_of : Field
44             : Set(_set_homepage_url)
45             : Get(homepage_url)
46             ;
47             my @avatar_url_of : Field
48             : Set(_set_avatar_url)
49             : Get(avatar_url)
50             ;
51             my @posts_count_of : Field
52             : Set(_set_posts_count)
53             : Get(posts_count)
54             ;
55             my @location_of : Field
56             : Set(_set_location)
57             : Get(location)
58             ;
59             my @latitude_of : Field
60             : Set(_set_latitude)
61             : Get(latitude)
62             ;
63             my @longitude_of : Field
64             : Set(_set_longitude)
65             : Get(longitude)
66             ;
67             my @country_code_of : Field
68             : Set(_set_country_code)
69             : Get(country_code)
70             ;
71             my @kudo_of : Field
72             : Set(_set_kudo)
73             : Get(kudo_score)
74             ;
75             #>>>
76             my @kudos_of : Field : Arg(kudos);
77              
78             my @stack : Field;
79              
80 5     5 0 27 sub element_name { return 'account' }
81              
82             sub generate_query_url : Chained(bottom up) {
83 0     0 0 0 my ( $self, @args ) = @_;
84              
85 0         0 my %param = validate_with(
86             params => \@args,
87             spec => { id => 1 },
88             allow_extra => 1
89             );
90 0         0 my $id = $param{id};
91 0         0 delete $param{id};
92              
93 0 0       0 if ( index( $id, '@' ) > -1 ) {
94 0         0 $id = md5_hex($id);
95             }
96              
97 0         0 return ( "accounts/$id.xml", ohloh => $param{ohloh} );
98 29     29   13674 }
  29         69  
  29         308  
99              
100             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101              
102             sub load_xml {
103 9     9 0 104 my ( $self, $dom ) = @_;
104              
105 9         40 $self->_set_id( $dom->findvalue('id/text()') );
106 9         1226 $self->_set_name( $dom->findvalue('name/text()') );
107 9         784 $self->_set_created_at(
108             scalar Time::Piece::gmtime(
109             str2time( $dom->findvalue('created_at/text()') ) ) );
110 9         4044 $self->_set_updated_at(
111             scalar Time::Piece::gmtime(
112             str2time( $dom->findvalue('updated_at/text()') ) ) );
113 9         3141 $self->_set_homepage_url( $dom->findvalue('homepage_url/text()') );
114 9         786 $self->_set_avatar_url( $dom->findvalue('avatar_url/text()') );
115 9         729 $self->_set_posts_count( $dom->findvalue('posts_count/text()') );
116 9         638 $self->_set_location( $dom->findvalue('location/text()') );
117 9         642 $self->_set_country_code( $dom->findvalue('country_code/text()') );
118 9         668 $self->_set_latitude( $dom->findvalue('latitude/text()') );
119 9         663 $self->_set_longitude( $dom->findvalue('longitude/text()') );
120              
121 9 50       645 if ( my ($node) = $dom->findnodes('kudo_score[1]') ) {
122 9         309 $kudo_of[$$self] = WWW::Ohloh::API::KudoScore->new( xml => $node );
123             }
124             }
125              
126             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127              
128             sub as_xml {
129 2     2 1 2099 my $self = shift;
130 2         4 my $xml;
131 2         16 my $w = XML::Writer->new( OUTPUT => \$xml );
132              
133 2         458 $w->startTag('account');
134              
135 2         274 $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 50       3134 $xml .= $self->kudo->as_xml if $self->kudo;
145              
146 2         13 $w->endTag;
147              
148 2         194 return $xml;
149             }
150              
151             sub kudoScore {
152 4     4 1 9 my $self = shift;
153 4         21 return $kudo_of[$$self];
154             }
155              
156             # aliases
157             *kudo = *kudoScore;
158              
159             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
160              
161             sub stack {
162 1     1 1 3 my $self = shift;
163              
164 1         4 my $retrieve = shift;
165 1 50       6 $retrieve = 1 unless defined $retrieve;
166              
167 1 50 33     11 if ( $retrieve and not $stack[$$self] ) {
168 1         52 $stack[$$self] = $self->ohloh->fetch_account_stack( $self->id );
169 1         559 $stack[$$self]->set_account($self);
170             }
171              
172 1         6 return $stack[$$self];
173             }
174              
175             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
176              
177             sub sent_kudos {
178 1     1 0 1471 my $self = shift;
179              
180 1   33     6 $kudos_of[$$self] ||= $self->ohloh->get_kudos( id => $self->id );
181              
182 1         5 return $kudos_of[$$self]->sent;
183             }
184              
185             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186              
187             sub received_kudos {
188 1     1 0 3 my $self = shift;
189              
190 1   33     8 $kudos_of[$$self] ||= $self->ohloh->get_kudos( id => $self->id );
191              
192 1         6 return $kudos_of[$$self]->received;
193             }
194              
195             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
196              
197             sub kudos {
198 1     1 0 124 my $self = shift;
199              
200 1   33     31 return $kudos_of[$$self] ||= $self->ohloh->fetch_kudos( $self->id );
201             }
202              
203             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
204              
205             'end of WWW::Ohloh::API::Account';
206              
207             __END__