| 1 | package WWW::Ohloh::API::Stack; | ||||||||||||||||||||
| 2 | 3 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | ▶ | use Object::InsideOut qw/ WWW::Ohloh::API::Role::Fetchable | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 3 | WWW::Ohloh::API::Role::LoadXML /; | |||||||||||||||||||
| 10 | 3 | ▶ | use XML::LibXML; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | use Readonly; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 3 | ▶ | use Scalar::Util qw/ weaken /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 3 | ▶ | use Date::Parse; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 3 | ▶ | use Time::Piece; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 3 | ▶ | use Digest::MD5 qw/ md5_hex /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 3 | ▶ | use WWW::Ohloh::API::StackEntry; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 3 | ▶ | use Params::Validate qw/ validate_with /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 3 | our $VERSION = '1.0_1'; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 3 | my @ohloh_of : Field : Arg(ohloh); | |||||||||||||||||||
| 24 | 3 | my @request_url_of : Field : Arg(request_url) : Get( request_url ); | |||||||||||||||||||
| 25 | 3 | my @xml_of : Field : Arg(xml); | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 3 | my @api_fields = qw/ | |||||||||||||||||||
| 28 | id | ||||||||||||||||||||
| 29 | updated_at | ||||||||||||||||||||
| 30 | project_count | ||||||||||||||||||||
| 31 | stack_entries | ||||||||||||||||||||
| 32 | account_id | ||||||||||||||||||||
| 33 | account | ||||||||||||||||||||
| 34 | /; | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | __PACKAGE__->create_field( '@' . $_, ":Set(_set_$_)", ":Get($_)" ) | ||||||||||||||||||||
| 37 | 3 | for qw/ id updated_at project_count account_id /; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 3 | my @stack_entries_of : Field; | |||||||||||||||||||
| 40 | 3 | my @account_of : Field; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 1 | ▶ | sub element_name { return 'stack'; } | ||||||||||||||||||
|
Subroutine
element_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 5 | ▶ | sub load_xml { | ||||||||||||||||||
|
Subroutine
load_xml: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 49 | 5 | my ( $self, $dom ) = @_; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 5 | for my $f (qw/ id project_count account_id /) { | |||||||||||||||||||
| 52 | 15 | my $method = "_set_$f"; | |||||||||||||||||||
| 53 | 15 | $self->$method( $dom->findvalue("$f/text()") ); | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | $self->_set_updated_at( | ||||||||||||||||||||
| 57 | 5 | scalar Time::Piece::gmtime( | |||||||||||||||||||
| 58 | str2time( $dom->findvalue("updated_at/text()") ) ) ); | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 5 | ▶ | if ( my ($account_xml) = $dom->findnodes('account[1]') ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 4 | $account_of[$$self] = WWW::Ohloh::API::Account->new( | |||||||||||||||||||
| 62 | ohloh => $ohloh_of[$$self], | ||||||||||||||||||||
| 63 | xml => $account_xml, | ||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 5 | $stack_entries_of[$$self] = [ | |||||||||||||||||||
| 68 | map WWW::Ohloh::API::StackEntry->new( | ||||||||||||||||||||
| 69 | ohloh => $ohloh_of[$$self], | ||||||||||||||||||||
| 70 | xml => $_, | ||||||||||||||||||||
| 71 | ) => $dom->findnodes('stack_entries/stack_entry') ]; | ||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 1 | ▶ | sub generate_query_url : Chained(bottom up) { | ||||||||||||||||||
|
Subroutine
generate_query_url: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||
| 77 | 1 | my ( $self, @args ) = @_; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 1 | my %param = validate_with( | |||||||||||||||||||
| 80 | params => \@args, | ||||||||||||||||||||
| 81 | spec => { id => 1 }, | ||||||||||||||||||||
| 82 | allow_extra => 1 | ||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||
| 84 | 1 | my $id = $param{id}; | |||||||||||||||||||
| 85 | 1 | delete $param{id}; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 1 | ▶ | if ( index( $id, '@' ) > -1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | 0 | $id = md5_hex($id); | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 1 | return ( "accounts/$id/stacks/default.xml", ohloh => $param{ohloh} ); | |||||||||||||||||||
| 92 | 3 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 8 | ▶ | sub stack_entries { | ||||||||||||||||||
|
Subroutine
stack_entries: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 97 | 8 | my $self = shift; | |||||||||||||||||||
| 98 | 8 | return @{ $stack_entries_of[$$self] }; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 0 | ▶ | sub as_xml { | ||||||||||||||||||
|
Subroutine
as_xml: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 104 | 0 | my $self = shift; | |||||||||||||||||||
| 105 | 0 | my $xml; | |||||||||||||||||||
| 106 | 0 | my $w = XML::Writer->new( OUTPUT => \$xml ); | |||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | $w->startTag('stack'); | |||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | for my $f (qw/ id updated_at project_count account_id /) { | |||||||||||||||||||
| 111 | 0 | $w->dataElement( $f => $self->$f ); | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 0 | ▶ | if ( my $account = $account_of[$$self] ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | 0 | $xml .= $account->as_xml; | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 0 | ▶ | if ( my @entries = @{ $stack_entries_of[$$self] } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 119 | 0 | $w->startTag('stack_entries'); | |||||||||||||||||||
| 120 | 0 | $xml .= $_->as_xml for @entries; | |||||||||||||||||||
| 121 | 0 | $w->endTag; | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 0 | $w->endTag; | |||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | return $xml; | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 5 | ▶ | sub account { | ||||||||||||||||||
|
Subroutine
account: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||
| 132 | 5 | my $self = shift; | |||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 5 | my $retrieve = shift; | |||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 5 | ▶ | $retrieve = 1 unless defined $retrieve; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 5 | ▶ | if ($retrieve) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 139 | 1 | ▶ | $account_of[$$self] ||= | ||||||||||||||||||
|
Condition33%1/3
$account_of[$$self] ||= $ohloh_of[$$self]->fetch_account($self->account_id)
MC/DC0%0/2
$account_of[$$self] ||= $ohloh_of[$$self]->fetch_account($self->account_id)
$account_of[$$self]
$ohloh_of[$$self]->fetch_account($self->account_id)
Truth table33%1/3
A ||= B
A= $account_of[$$self]B= $ohloh_of[$$self]->fetch_account($self->account_id)
| |||||||||||||||||||||
| 140 | $ohloh_of[$$self]->fetch_account( $self->account_id ); | ||||||||||||||||||||
| 141 | } | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 5 | return $account_of[$$self]; | |||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | } | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 1 | ▶ | sub set_account : Private( WWW::Ohloh::API::Account ) { | ||||||||||||||||||
|
Subroutine
set_account: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 148 | 1 | my $self = shift; | |||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 1 | weaken( $account_of[$$self] = shift ); | |||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | 1 | return; | |||||||||||||||||||
| 153 | 3 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 3 | 'end of WWW::Ohloh::API::Stack'; | |||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||