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