File Coverage

blib/lib/WWW/Ohloh/API/Kudo.pm
Criterion Covered Total %
statement 36 48 75.0
branch 4 8 50.0
condition n/a
subroutine 11 12 91.6
pod 1 4 25.0
total 52 72 72.2


line stmt bran cond sub pod time code
1             package WWW::Ohloh::API::Kudo;
2             our $AUTHORITY = 'cpan:YANICK';
3              
4 30     30   173895 use strict;
  30         64  
  30         1173  
5 30     30   146 use warnings;
  30         51  
  30         1493  
6              
7 30     30   168 use Carp;
  30         68  
  30         2126  
8 30     30   898 use Object::InsideOut;
  30         63059  
  30         265  
9 30     30   3780 use XML::LibXML;
  30         54682  
  30         271  
10 30     30   6600 use WWW::Ohloh::API::KudoScore;
  30         84  
  30         323  
11              
12             our $VERSION = '1.0_1';
13              
14             my @api_fields = qw/
15             created_at
16             sender_account_id
17             sender_account_name
18             receiver_account_name
19             receiver_account_id
20             project_id
21             project_name
22             contributor_id
23             contributor_name
24             /;
25              
26             my @created_at_of : Field : Set(_set_created_at) : Get(created_at);
27             my @sender_account_id_of : Field : Set(_set_sender_account_id) :
28             Get(sender_account_id);
29             my @sender_account_name_of : Field : Set(_set_sender_account_name) :
30             Get(sender_account_name);
31             my @receiver_account_name_of : Field : Set(_set_receiver_account_name) :
32             Get(receiver_account_name);
33             my @receiver_account_id_of : Field : Set(_set_receiver_account_id) :
34             Get(receiver_account_id);
35             my @project_id_of : Field : Set(_set_project_id) : Get(project_id);
36             my @project_name_of : Field : Set(_set_project_name) : Get(project_name);
37             my @contributor_id_of : Field : Set(_set_contributor_id) :
38             Get(contributor_id);
39             my @contributor_name_of : Field : Set(_set_contributor_name) :
40             Get(contributor_name);
41              
42             my @request_url_of : Field : Arg(request_url) : Get( request_url );
43             my @xml_of : Field : Arg(xml);
44             my @ohloh_of : Field : Arg(ohloh) : Get(_ohloh);
45              
46             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47              
48             sub _init : Init {
49 0     0   0 my $self = shift;
50              
51 0 0       0 my $dom = $xml_of[$$self] or return;
52              
53 0         0 $self->_set_created_at( $dom->findvalue("created_at/text()") );
54 0         0 $self->_set_sender_account_id(
55             $dom->findvalue("sender_account_id/text()") );
56 0         0 $self->_set_sender_account_name(
57             $dom->findvalue("sender_account_name/text()") );
58 0         0 $self->_set_receiver_account_name(
59             $dom->findvalue("receiver_account_name/text()") );
60 0         0 $self->_set_receiver_account_id(
61             $dom->findvalue("receiver_account_id/text()") );
62 0         0 $self->_set_project_id( $dom->findvalue("project_id/text()") );
63 0         0 $self->_set_project_name( $dom->findvalue("project_name/text()") );
64 0         0 $self->_set_contributor_id( $dom->findvalue("contributor_id/text()") );
65 0         0 $self->_set_contributor_name(
66             $dom->findvalue("contributor_name/text()") );
67 30     30   14366 }
  30         86  
  30         246  
68              
69             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70              
71             sub recipient_type {
72 1     1 0 16336 my $self = shift;
73              
74 1 50       41 return $self->receiver_account_id ? 'account' : 'contributor';
75             }
76              
77             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78              
79             sub sender {
80 1     1 0 2 my $self = shift;
81              
82 1         31 return $self->_ohloh->fetch_account( $self->sender_account_id );
83             }
84              
85             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86              
87             sub receiver {
88 1     1 0 133 my $self = shift;
89              
90 1 50       17 if ( my $id = $self->receiver_account_id ) {
91 1         21 return $self->_ohloh->fetch_account($id);
92             }
93              
94 0         0 return;
95             }
96              
97             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98              
99             sub as_xml {
100 36     36 1 1543 my $self = shift;
101 36         50 my $xml;
102 36         112 my $w = XML::Writer->new( OUTPUT => \$xml );
103              
104 36         5521 $w->startTag('kudo');
105 36         2287 for my $e (@api_fields) {
106 324 100       35104 $w->dataElement( $e => $self->$e ) if $self->$e;
107             }
108              
109 36         1132 $w->endTag;
110              
111 36         3726 return $xml;
112             }
113              
114             'end of WWW::Ohloh::API::Kudo';
115              
116             __END__