File Coverage

blib/lib/WWW/Ohloh/API/Kudos.pm
Criterion Covered Total %
statement 63 63 100.0
branch 6 8 75.0
condition n/a
subroutine 12 12 100.0
pod 3 4 75.0
total 84 87 96.5


line stmt bran cond sub pod time code
1             package WWW::Ohloh::API::Kudos;
2             our $AUTHORITY = 'cpan:YANICK';
3              
4 29     29   316231 use strict;
  29         62  
  29         1265  
5 29     29   150 use warnings;
  29         57  
  29         1419  
6              
7 29     29   152 use Carp;
  29         56  
  29         2143  
8 29     29   1222 use Object::InsideOut;
  29         66538  
  29         208  
9 29     29   3645 use XML::LibXML;
  29         32296  
  29         272  
10 29     29   5364 use Readonly;
  29         3513  
  29         1809  
11 29     29   699 use List::MoreUtils qw/ any /;
  29         12348  
  29         276  
12 29     29   39506 use WWW::Ohloh::API::Kudo;
  29         142  
  29         220  
13              
14             our $VERSION = '1.0_1';
15              
16             my @ohloh_of : Field : Arg(ohloh);
17             my @account_id_of : Field : Arg(id) : Get(_id);
18             my @sent_kudos_of : Field;
19             my @received_kudos_of : Field;
20              
21             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22              
23             sub as_xml {
24 1     1 1 2 my $self = shift;
25 1         2 my $xml;
26 1         4 my $w = XML::Writer->new( OUTPUT => \$xml );
27              
28 1         112 $w->startTag('kudos');
29              
30 1 50       48 if ( my @k = @{ $sent_kudos_of[$$self] } ) {
  1         8  
31 1         3 $w->startTag('kudos_sent');
32 1         38 $xml .= $_->as_xml for @k;
33 1         6 $w->endTag;
34             }
35              
36 1 50       31 if ( my @k = @{ $received_kudos_of[$$self] } ) {
  1         11  
37 1         5 $w->startTag('kudos_received');
38 1         97 $xml .= $_->as_xml for @k;
39 1         4 $w->endTag;
40             }
41              
42 1         20 $w->endTag;
43              
44 1         95 return $xml;
45             }
46              
47             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48              
49             sub all {
50 1     1 1 1922 my $self = shift;
51              
52 1         3 my %kudos;
53              
54 1         6 $kudos{received} = [ $self->received ];
55 1         5 $kudos{sent} = [ $self->sent ];
56              
57 1         10 return %kudos;
58             }
59              
60             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61              
62             sub received {
63 3     3 0 13 my $self = shift;
64              
65 3 100       13 unless ( $received_kudos_of[$$self] ) {
66 2         87 my ( $url, $xml ) =
67             $ohloh_of[$$self]
68             ->_query_server( 'accounts/' . $self->_id . '/kudos.xml' );
69              
70 2         53 my @kudos;
71 2         13 for my $n ( $xml->findnodes('kudo') ) {
72 20         2414 push @kudos,
73             WWW::Ohloh::API::Kudo->new(
74             ohloh => $ohloh_of[$$self],
75             xml => $n,
76             );
77             }
78 2         269 $received_kudos_of[$$self] = \@kudos;
79             }
80              
81 3         49 return @{ $received_kudos_of[$$self] };
  3         21  
82             }
83              
84             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85              
86             sub sent {
87 3     3 1 14 my $self = shift;
88              
89 3 100       14 unless ( $sent_kudos_of[$$self] ) {
90 2         62 my ( $url, $xml ) =
91             $ohloh_of[$$self]
92             ->_query_server( 'accounts/' . $self->_id . '/kudos/sent.xml' );
93              
94 2         42 my @kudos;
95 2         7 for my $n ( $xml->findnodes('kudo') ) {
96 50         5478 push @kudos,
97             WWW::Ohloh::API::Kudo->new(
98             ohloh => $ohloh_of[$$self],
99             xml => $n,
100             );
101             }
102 2         284 $sent_kudos_of[$$self] = \@kudos;
103             }
104              
105 3         50 return @{ $sent_kudos_of[$$self] };
  3         24  
106             }
107              
108             'end of WWW::Ohloh::API::Kudos';
109              
110             __END__