blib/lib/WWW/Ohloh/API/Kudos.pm

filter: Statementstmt 100% 69 / 69 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 75.0% 3 / 4 totaltotal 96.7% 90 / 93 CC 9 SCAR 9.6
CC
9
Cov
97%
as_xml
5.0
received
3.0
sent
3.0
CRAP 2.6
« blib/lib/WWW/Ohloh/API/StackEntry.pm ↑ Summary blib/lib/WWW/Ohloh/API/Stack.pm »
1 package WWW::Ohloh::API::Kudos;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 16 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Object::InsideOut;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use List::MoreUtils qw/ any /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use WWW::Ohloh::API::Kudo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 16 our $VERSION = '1.0_1';
14  
15 16 my @ohloh_of : Field : Arg(ohloh);
16 16 my @account_id_of : Field : Arg(id) : Get(_id);
17 16 my @sent_kudos_of : Field;
18 16 my @received_kudos_of : Field;
19  
20 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21  
22 sub as_xml {
23 1 ▶ my $self = shift;
Subroutine as_xml: called CC=5 SCAR=16.1
Pod documented
24 1 my $xml;
25 1 my $w = XML::Writer->new( OUTPUT => \$xml );
26  
27 1 $w->startTag('kudos');
28  
29 1 ▶ if ( my @k = @{ $sent_kudos_of[$$self] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@k) = @{$sent_kudos_of[$$self];}) 1 0 1
30 1 $w->startTag('kudos_sent');
31 1 $xml .= $_->as_xml for @k;
32 1 $w->endTag;
33 }
34  
35 1 ▶ if ( my @k = @{ $received_kudos_of[$$self] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@k) = @{$received_kudos_of[$$self];}) 1 0 1
36 1 $w->startTag('kudos_received');
37 1 $xml .= $_->as_xml for @k;
38 1 $w->endTag;
39 }
40  
41 1 $w->endTag;
42  
43 1 return $xml;
44 }
45  
46 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47  
48 sub all {
49 1 ▶ my $self = shift;
Subroutine all: called CC=1 SCAR=0.0
Pod documented
50  
51 1 my %kudos;
52  
53 1 $kudos{received} = [ $self->received ];
54 1 $kudos{sent} = [ $self->sent ];
55  
56 1 return %kudos;
57 }
58  
59 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60  
61 sub received {
62 3 ▶ my $self = shift;
Subroutine received: called CC=3 SCAR=11.0
Pod undocumented
63  
64 3 ▶ unless ( $received_kudos_of[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($received_kudos_of[$$self]) 2 1 3
65 2 my ( $url, $xml ) =
66 $ohloh_of[$$self]
67 ->_query_server( 'accounts/' . $self->_id . '/kudos.xml' );
68  
69 2 my @kudos;
70 2 for my $n ( $xml->findnodes('kudo') ) {
71 20 push @kudos,
72 WWW::Ohloh::API::Kudo->new(
73 ohloh => $ohloh_of[$$self],
74 xml => $n,
75 );
76 }
77 2 $received_kudos_of[$$self] = \@kudos;
78 }
79  
80 3 return @{ $received_kudos_of[$$self] };
81 }
82  
83 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
84  
85 sub sent {
86 3 ▶ my $self = shift;
Subroutine sent: called CC=3 SCAR=11.0
Pod documented
87  
88 3 ▶ unless ( $sent_kudos_of[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sent_kudos_of[$$self]) 2 1 3
89 2 my ( $url, $xml ) =
90 $ohloh_of[$$self]
91 ->_query_server( 'accounts/' . $self->_id . '/kudos/sent.xml' );
92  
93 2 my @kudos;
94 2 for my $n ( $xml->findnodes('kudo') ) {
95 50 push @kudos,
96 WWW::Ohloh::API::Kudo->new(
97 ohloh => $ohloh_of[$$self],
98 xml => $n,
99 );
100 }
101 2 $sent_kudos_of[$$self] = \@kudos;
102 }
103  
104 3 return @{ $sent_kudos_of[$$self] };
105 }
106  
107 16 'end of WWW::Ohloh::API::Kudos';
108 __END__
109  
110 =head1 NAME
111  
112 WWW::Ohloh::API::Kudos - Ohloh kudos sent and received by an account
113  
114 =head1 SYNOPSIS
115  
116 use WWW::Ohloh::API;
117  
118 my $ohloh = WWW::Ohloh::API->new( api_key => $my_api_key );
119 my $kudos = $ohloh->get_kudos( id => $account_id );
120  
121 my @received = $kudos->received;
122 my @sent = $kudos->sent;
123  
124 =head1 DESCRIPTION
125  
126 W::O::A::Kudos returns the kudos received and given by
127 an Ohloh account.
128 To be properly populated, it must be created via
129 the C<get_kudos> method of a L<WWW::Ohloh::API> object.
130  
131 =head1 METHODS
132  
133 =head2 all
134  
135 Return the retrieved languages' information as
136 L<WWW::Ohloh::API::Kudos> objects.
137  
138 =head3 as_xml
139  
140 Return the kudos as an XML string.
141 Note that this is not the same xml document as returned
142 by the Ohloh server.
143  
144 =head1 SEE ALSO
145  
146 =over
147  
148 =item *
149  
150 L<WWW::Ohloh::API>,
151 L<WWW::Ohloh::API::Kudo>,
152 L<WWW::Ohloh::API::Language>,
153 L<WWW::Ohloh::API::Project>,
154 L<WWW::Ohloh::API::Analysis>,
155 L<WWW::Ohloh::API::Account>.
156  
157  
158 =item *
159  
160 Ohloh API reference: http://www.ohloh.net/api/getting_started
161  
162 =item *
163  
164 Ohloh Account API reference: http://www.ohloh.net/api/reference/kudo
165  
166 =back
167  
168 =head1 VERSION
169  
170 This document describes WWW::Ohloh::API version 1.0_1
171  
172 =head1 BUGS AND LIMITATIONS
173  
174 WWW::Ohloh::API is very extremely alpha quality. It'll improve,
175 but till then: I<Caveat emptor>.
176  
177 Please report any bugs or feature requests to
178 C<bug-www-ohloh-api@rt.cpan.org>, or through the web interface at
179 L<http://rt.cpan.org>.
180  
181  
182 =head1 AUTHOR
183  
184 Yanick Champoux C<< <yanick@cpan.org> >>
185  
186 =head1 LICENCE AND COPYRIGHT
187  
188 Copyright (c) 2008, Yanick Champoux C<< <yanick@cpan.org> >>. All rights reserved.
189  
190 This module is free software; you can redistribute it and/or
191 modify it under the same terms as Perl itself. See L<perlartistic>.
192  
193 =cut
« blib/lib/WWW/Ohloh/API/StackEntry.pm ↑ Summary blib/lib/WWW/Ohloh/API/Stack.pm »