| 1 | package WWW::Ohloh::API::Kudos; | ||||||||||
| 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; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 29 | ▶ | use XML::LibXML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 29 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 29 | ▶ | use List::MoreUtils qw/ any /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 29 | ▶ | use WWW::Ohloh::API::Kudo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 29 | our $VERSION = '1.0_1'; | |||||||||
| 15 | |||||||||||
| 16 | 29 | my @ohloh_of : Field : Arg(ohloh); | |||||||||
| 17 | 29 | my @account_id_of : Field : Arg(id) : Get(_id); | |||||||||
| 18 | 29 | my @sent_kudos_of : Field; | |||||||||
| 19 | 29 | my @received_kudos_of : Field; | |||||||||
| 20 | |||||||||||
| 21 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | sub as_xml { | ||||||||
|
Subroutine
as_xml: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 24 | 1 | my $self = shift; | |||||||||
| 25 | 1 | my $xml; | |||||||||
| 26 | 1 | my $w = XML::Writer->new( OUTPUT => \$xml ); | |||||||||
| 27 | |||||||||||
| 28 | 1 | $w->startTag('kudos'); | |||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | if ( my @k = @{ $sent_kudos_of[$$self] } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 1 | $w->startTag('kudos_sent'); | |||||||||
| 32 | 1 | $xml .= $_->as_xml for @k; | |||||||||
| 33 | 1 | $w->endTag; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 1 | ▶ | if ( my @k = @{ $received_kudos_of[$$self] } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 1 | $w->startTag('kudos_received'); | |||||||||
| 38 | 1 | $xml .= $_->as_xml for @k; | |||||||||
| 39 | 1 | $w->endTag; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 1 | $w->endTag; | |||||||||
| 43 | |||||||||||
| 44 | 1 | return $xml; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 48 | |||||||||||
| 49 | 1 | ▶ | sub all { | ||||||||
|
Subroutine
all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 50 | 1 | my $self = shift; | |||||||||
| 51 | |||||||||||
| 52 | 1 | my %kudos; | |||||||||
| 53 | |||||||||||
| 54 | 1 | $kudos{received} = [ $self->received ]; | |||||||||
| 55 | 1 | $kudos{sent} = [ $self->sent ]; | |||||||||
| 56 | |||||||||||
| 57 | 1 | return %kudos; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 61 | |||||||||||
| 62 | 3 | ▶ | sub received { | ||||||||
|
Subroutine
received: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 63 | 3 | my $self = shift; | |||||||||
| 64 | |||||||||||
| 65 | 3 | ▶ | unless ( $received_kudos_of[$$self] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 2 | my ( $url, $xml ) = | |||||||||
| 67 | $ohloh_of[$$self] | ||||||||||
| 68 | ->_query_server( 'accounts/' . $self->_id . '/kudos.xml' ); | ||||||||||
| 69 | |||||||||||
| 70 | 2 | my @kudos; | |||||||||
| 71 | 2 | for my $n ( $xml->findnodes('kudo') ) { | |||||||||
| 72 | 20 | push @kudos, | |||||||||
| 73 | WWW::Ohloh::API::Kudo->new( | ||||||||||
| 74 | ohloh => $ohloh_of[$$self], | ||||||||||
| 75 | xml => $n, | ||||||||||
| 76 | ); | ||||||||||
| 77 | } | ||||||||||
| 78 | 2 | $received_kudos_of[$$self] = \@kudos; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 3 | return @{ $received_kudos_of[$$self] }; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 85 | |||||||||||
| 86 | 3 | ▶ | sub sent { | ||||||||
|
Subroutine
sent: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 87 | 3 | my $self = shift; | |||||||||
| 88 | |||||||||||
| 89 | 3 | ▶ | unless ( $sent_kudos_of[$$self] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 2 | my ( $url, $xml ) = | |||||||||
| 91 | $ohloh_of[$$self] | ||||||||||
| 92 | ->_query_server( 'accounts/' . $self->_id . '/kudos/sent.xml' ); | ||||||||||
| 93 | |||||||||||
| 94 | 2 | my @kudos; | |||||||||
| 95 | 2 | for my $n ( $xml->findnodes('kudo') ) { | |||||||||
| 96 | 50 | push @kudos, | |||||||||
| 97 | WWW::Ohloh::API::Kudo->new( | ||||||||||
| 98 | ohloh => $ohloh_of[$$self], | ||||||||||
| 99 | xml => $n, | ||||||||||
| 100 | ); | ||||||||||
| 101 | } | ||||||||||
| 102 | 2 | $sent_kudos_of[$$self] = \@kudos; | |||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | 3 | return @{ $sent_kudos_of[$$self] }; | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 29 | 'end of WWW::Ohloh::API::Kudos'; | |||||||||
| 109 | |||||||||||
| 110 | __END__ | ||||||||||