| 1 | package WWW::Ohloh::API::Stack; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 15 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 15 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 15 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 15 | ▶ | use Object::InsideOut; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 15 | ▶ | use XML::LibXML; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 15 | ▶ | use Readonly; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 15 | ▶ | use Scalar::Util qw/ weaken /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 15 | ▶ | use Date::Parse; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 15 | ▶ | use Time::Piece; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 15 | ▶ | use WWW::Ohloh::API::StackEntry; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 15 | our $VERSION = '0.3.2'; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 15 | my @ohloh_of : Field : Arg(ohloh); | |||||||||||||||||||
| 19 | 15 | my @request_url_of : Field : Arg(request_url) : Get( request_url ); | |||||||||||||||||||
| 20 | 15 | my @xml_of : Field : Arg(xml); | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 15 | my @api_fields = qw/ | |||||||||||||||||||
| 23 | id | ||||||||||||||||||||
| 24 | updated_at | ||||||||||||||||||||
| 25 | project_count | ||||||||||||||||||||
| 26 | stack_entries | ||||||||||||||||||||
| 27 | account_id | ||||||||||||||||||||
| 28 | account | ||||||||||||||||||||
| 29 | /; | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | __PACKAGE__->create_field( '@' . $_, ":Set(_set_$_)", ":Get($_)" ) | ||||||||||||||||||||
| 32 | 15 | for qw/ id updated_at project_count account_id /; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 15 | my @stack_entries_of : Field; | |||||||||||||||||||
| 35 | 15 | my @account_of : Field; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | sub _init : Init { | ||||||||||||||||||||
| 40 | 5 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
_init: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 5 | ▶ | my $dom = $xml_of[$$self] or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 5 | for my $f (qw/ id project_count account_id /) { | |||||||||||||||||||
| 45 | 15 | my $method = "_set_$f"; | |||||||||||||||||||
| 46 | 15 | $self->$method( $dom->findvalue("$f/text()") ); | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | $self->_set_updated_at( | ||||||||||||||||||||
| 50 | 5 | Time::Piece->new( str2time( $dom->findvalue("updated_at/text()") ) ) | |||||||||||||||||||
| 51 | ); | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 5 | ▶ | if ( my ($account_xml) = $dom->findnodes('account[1]') ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 4 | $account_of[$$self] = WWW::Ohloh::API::Account->new( | |||||||||||||||||||
| 55 | ohloh => $ohloh_of[$$self], | ||||||||||||||||||||
| 56 | xml => $account_xml, | ||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 5 | $stack_entries_of[$$self] = [ | |||||||||||||||||||
| 61 | map WWW::Ohloh::API::StackEntry->new( | ||||||||||||||||||||
| 62 | ohloh => $ohloh_of[$$self], | ||||||||||||||||||||
| 63 | xml => $_, | ||||||||||||||||||||
| 64 | ) => $dom->findnodes('stack_entries/stack_entry') ]; | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 5 | return; | |||||||||||||||||||
| 67 | 15 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | sub stack_entries { | ||||||||||||||||||||
| 72 | 8 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
stack_entries: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 73 | 8 | return @{ $stack_entries_of[$$self] }; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | sub as_xml { | ||||||||||||||||||||
| 79 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
as_xml: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 80 | 0 | my $xml; | |||||||||||||||||||
| 81 | 0 | my $w = XML::Writer->new( OUTPUT => \$xml ); | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | $w->startTag('stack'); | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | for my $f (qw/ id updated_at project_count account_id /) { | |||||||||||||||||||
| 86 | 0 | $w->dataElement( $f => $self->$f ); | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | ▶ | if ( my $account = $account_of[$$self] ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 0 | $xml .= $account->as_xml; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | if ( my @entries = @{ $stack_entries_of[$$self] } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 0 | $w->startTag('stack_entries'); | |||||||||||||||||||
| 95 | 0 | $xml .= $_->as_xml for @entries; | |||||||||||||||||||
| 96 | 0 | $w->endTag; | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | $w->endTag; | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | return $xml; | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | sub account { | ||||||||||||||||||||
| 107 | 5 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
account: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 5 | my $retrieve = shift; | |||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 5 | ▶ | $retrieve = 1 unless defined $retrieve; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 5 | ▶ | if ($retrieve) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | 1 | ▶ | $account_of[$$self] ||= | ||||||||||||||||||
|
Condition33%1/3
$account_of[$$self] ||= $ohloh_of[$$self]->get_account("id", $self->account_id)
MC/DC0%0/2
$account_of[$$self] ||= $ohloh_of[$$self]->get_account("id", $self->account_id)
$account_of[$$self]
$ohloh_of[$$self]->get_account("id", $self->account_id)
Truth table33%1/3
A ||= B
A= $account_of[$$self]B= $ohloh_of[$$self]->get_account("id", $self->account_id)
| |||||||||||||||||||||
| 115 | $ohloh_of[$$self]->get_account( id => $self->account_id ); | ||||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 5 | return $account_of[$$self]; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | sub set_account : Private( WWW::Ohloh::API::Account ) { | ||||||||||||||||||||
| 123 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
set_account: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 1 | weaken( $account_of[$$self] = shift ); | |||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 1 | return; | |||||||||||||||||||
| 128 | 15 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 15 | 'end of WWW::Ohloh::API::Stack'; | |||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | =begin test | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | use lib 't'; | ||||||||||||||||||||
| 136 | use FakeOhloh; | ||||||||||||||||||||
| 137 | use WWW::Ohloh::API::Stack; | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | my $ohloh = Fake::Ohloh->new; | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | $ohloh->stash( 'yadah', 'stack.xml' ); | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | my $thingy = $ohloh->get_account_stack( 123 ); | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | =end test | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | =head1 NAME | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | WWW::Ohloh::API::Stack - a collection of projects used by a person | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | =head1 SYNOPSIS | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | use WWW::Ohloh::API; | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | my $ohloh = WWW::Ohloh::API->new( api_key => $my_api_key ); | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | # get the stack of a person | ||||||||||||||||||||
| 158 | my $stack = $ohloh->get_account_stack( $account_id ); | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | # get stacks containing a project | ||||||||||||||||||||
| 161 | my @stacks = $ohloh->get_project_stacks( $project_id ); | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | =head1 DESCRIPTION | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | W::O::A::Stack represents a collection of projects used | ||||||||||||||||||||
| 167 | by a person. | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | =head1 METHODS | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | =for test ignore | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | =head2 API Data Accessors | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | =for test | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | =head3 id | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | Returns the unique id for the stack. | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | =for test | ||||||||||||||||||||
| 182 | is $result[0] => 21420, 'id()'; | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =head3 updated_at | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | Returns the most recent time at which any projects were added to | ||||||||||||||||||||
| 187 | or removed from this stack as a L<Time::Piece> object. | ||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | =for test | ||||||||||||||||||||
| 190 | isa_ok $result[0], 'Time::Piece'; | ||||||||||||||||||||
| 191 | is $result[0], 'Mon Mar 17 13:09:16 2008', 'updated_at()'; | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | =head3 project_count | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | Returns the number of projects in the stack. | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | =head3 stack_entries | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | Returns a list of the entries contained by the stack as | ||||||||||||||||||||
| 200 | L<WWW::Ohloh::API::StackEntry> objects. | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | =for test | ||||||||||||||||||||
| 203 | isa_ok $_, 'WWW::Ohloh::API::StackEntry' for @result; | ||||||||||||||||||||
| 204 | is @result => 35, '35 stack entries'; | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | =head3 account_id | ||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | Returns the id of the account owning the stack. | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | =for test | ||||||||||||||||||||
| 211 | $ohloh->stash( 'account', 'account.xml' ); | ||||||||||||||||||||
| 212 | my $retrieve = 1; | ||||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | =head3 account( I<$retrieve> ) | ||||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | Returns the account associated | ||||||||||||||||||||
| 217 | to the stack as a L<WWW::Ohloh::API::Account> object. | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | If the account information was not present at the object's | ||||||||||||||||||||
| 220 | creation time, it will be queried from the ohloh server, | ||||||||||||||||||||
| 221 | unless I<$retrieve> is defined and set to false. | ||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | =for test | ||||||||||||||||||||
| 224 | isa_ok $result[0], 'WWW::Ohloh::API::Account'; | ||||||||||||||||||||
| 225 | # querying it again shouldn't cause a fetch | ||||||||||||||||||||
| 226 | is $thingy->account => $result[0], 'querying again'; | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | =for test ignore | ||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | =head2 Other Methods | ||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | =for test | ||||||||||||||||||||
| 233 | |||||||||||||||||||||
| 234 | =head3 as_xml | ||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | Returns the stack as an XML string. | ||||||||||||||||||||
| 237 | Note that this is not the same xml document as returned | ||||||||||||||||||||
| 238 | by the Ohloh server. | ||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | =for test | ||||||||||||||||||||
| 241 | use XML::LibXML; | ||||||||||||||||||||
| 242 | ok( XML::LibXML->new->parse_string( $result[0] ), 'as_xml' ); | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | =head1 SEE ALSO | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | =over | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | =item * | ||||||||||||||||||||
| 249 | |||||||||||||||||||||
| 250 | L<WWW::Ohloh::API>. | ||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | =item * | ||||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | Ohloh API reference: http://www.ohloh.net/api/getting_started | ||||||||||||||||||||
| 255 | |||||||||||||||||||||
| 256 | =item * | ||||||||||||||||||||
| 257 | |||||||||||||||||||||
| 258 | Ohloh Account API reference: http://www.ohloh.net/api/reference/stack | ||||||||||||||||||||
| 259 | |||||||||||||||||||||
| 260 | =back | ||||||||||||||||||||
| 261 | |||||||||||||||||||||
| 262 | =head1 VERSION | ||||||||||||||||||||
| 263 | |||||||||||||||||||||
| 264 | This document describes WWW::Ohloh::API version 0.3.2 | ||||||||||||||||||||
| 265 | |||||||||||||||||||||
| 266 | =head1 BUGS AND LIMITATIONS | ||||||||||||||||||||
| 267 | |||||||||||||||||||||
| 268 | WWW::Ohloh::API is very extremely alpha quality. It'll improve, | ||||||||||||||||||||
| 269 | but till then: I<Caveat emptor>. | ||||||||||||||||||||
| 270 | |||||||||||||||||||||
| 271 | Please report any bugs or feature requests to | ||||||||||||||||||||
| 272 | C<bug-www-ohloh-api@rt.cpan.org>, or through the web interface at | ||||||||||||||||||||
| 273 | L<http://rt.cpan.org>. | ||||||||||||||||||||
| 274 | |||||||||||||||||||||
| 275 | |||||||||||||||||||||
| 276 | =head1 AUTHOR | ||||||||||||||||||||
| 277 | |||||||||||||||||||||
| 278 | Yanick Champoux C<< <yanick@cpan.org> >> | ||||||||||||||||||||
| 279 | |||||||||||||||||||||
| 280 | =head1 LICENCE AND COPYRIGHT | ||||||||||||||||||||
| 281 | |||||||||||||||||||||
| 282 | Copyright (c) 2008, Yanick Champoux C<< <yanick@cpan.org> >>. All rights reserved. | ||||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | This module is free software; you can redistribute it and/or | ||||||||||||||||||||
| 285 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||||||||||||
| 286 | |||||||||||||||||||||
| 287 | =cut | ||||||||||||||||||||