| 1 | package WWW::Ohloh::API::StackEntry; | ||||||||||||||||||||
| 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 List::MoreUtils qw/ any /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 15 | our $VERSION = '0.3.2'; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 15 | my @ohloh_of : Field : Arg(ohloh); | |||||||||||||||||||
| 15 | 15 | my @request_url_of : Field : Arg(request_url) : Get( request_url ); | |||||||||||||||||||
| 16 | 15 | my @xml_of : Field : Arg(xml); | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 15 | my @api_fields = qw/ | |||||||||||||||||||
| 19 | id | ||||||||||||||||||||
| 20 | created_at | ||||||||||||||||||||
| 21 | stack_id | ||||||||||||||||||||
| 22 | project_id | ||||||||||||||||||||
| 23 | /; | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | __PACKAGE__->create_field( '%' . $_, ":Set(_set_$_)", ":Get($_)" ) | ||||||||||||||||||||
| 26 | 15 | for @api_fields; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 15 | my @project : Field; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | sub _init : Init { | ||||||||||||||||||||
| 33 | 344 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
_init: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 344 | ▶ | my $dom = $xml_of[$$self] or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 344 | for my $f (@api_fields) { | |||||||||||||||||||
| 38 | 1376 | my $method = "_set_$f"; | |||||||||||||||||||
| 39 | 1376 | $self->$method( $dom->findvalue("$f/text()") ); | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 344 | ▶ | if ( my ($project_xml) = $dom->findnodes('//project[1]') ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 35 | $project[$$self] = WWW::Ohloh::API::Project->new( | |||||||||||||||||||
| 44 | ohloh => $ohloh_of[$$self], | ||||||||||||||||||||
| 45 | xml => $project_xml, | ||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 344 | return; | |||||||||||||||||||
| 50 | 15 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | sub as_xml { | ||||||||||||||||||||
| 55 | 309 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
as_xml: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||
| 56 | 309 | my $xml; | |||||||||||||||||||
| 57 | 309 | my $w = XML::Writer->new( OUTPUT => \$xml ); | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 309 | $w->startTag('stack_entry'); | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 309 | for my $f (@api_fields) { | |||||||||||||||||||
| 62 | 1236 | $w->dataElement( $f => $self->$f ); | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 309 | ▶ | if ( my $project = $project[$$self] ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | 0 | $xml .= $project->as_xml; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 309 | $w->endTag; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 309 | return $xml; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | sub project { | ||||||||||||||||||||
| 77 | 309 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
project: called CC=4 SCAR=17.2
Pod
documented
| |||||||||||||||||||||
| 78 | 309 | my $retrieve = shift; | |||||||||||||||||||
| 79 | 309 | ▶ | $retrieve = 1 unless defined $retrieve; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 309 | ▶ | if ($retrieve) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | 0 | ▶ | $project[$$self] ||= | ||||||||||||||||||
|
Condition0%0/3
$project[$$self] ||= $ohloh_of[$$self]->get_project($self->project_id)
MC/DC0%0/2
$project[$$self] ||= $ohloh_of[$$self]->get_project($self->project_id)
$project[$$self]
$ohloh_of[$$self]->get_project($self->project_id)
Truth table0%0/3
A ||= B
A= $project[$$self]B= $ohloh_of[$$self]->get_project($self->project_id)
| |||||||||||||||||||||
| 83 | $ohloh_of[$$self]->get_project( $self->project_id ); | ||||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 309 | return $project[$$self]; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 15 | 'end of WWW::Ohloh::API::StackEntry'; | |||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =head1 NAME | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | WWW::Ohloh::API::StackEntry - A project entry in a stack | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =head1 SYNOPSIS | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | use WWW::Ohloh::API; | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | my $ohloh = WWW::Ohloh::API->new( api_key => $my_api_key ); | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | # from an account | ||||||||||||||||||||
| 103 | my @entries = $ohloh->get_account_stack( $account_id )->stack_entries; | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | # from a project | ||||||||||||||||||||
| 106 | my @stacks = $ohloh->get_project_stacks( $project_id ); | ||||||||||||||||||||
| 107 | my @entries = $stacks[0]->stack_entries; | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | =head1 DESCRIPTION | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | W::O::A::StackEntry represents one project in a stack. | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | =head1 METHODS | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =head2 API Data Accessors | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =head3 $entry->id | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | Returns the unique id for the stack entry. | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =head3 $entry->created_at | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | Returns the time at which the project was added to the stack. | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head3 $entry->stack_id | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | Returns the id of the stack containing the entry. | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | =head3 $entry->project_id | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | Returns the id of the project. | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =head3 $entry->project( $retrieve ) | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | Returns the project as a L<WWW::Ohloh::API::Project> object. | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | If the optional argument I<$retrieve> is given and false, the project | ||||||||||||||||||||
| 139 | will not be queried from the Ohloh server if it's not already known, | ||||||||||||||||||||
| 140 | and the method will return nothing. | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =head2 Other Methods | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =head3 as_xml | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | Return the stack entry as an XML string. | ||||||||||||||||||||
| 147 | Note that this is not the same xml document as returned | ||||||||||||||||||||
| 148 | by the Ohloh server. | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | =head1 SEE ALSO | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | =over | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | =item * | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | L<WWW::Ohloh::API>. | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =item * | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | Ohloh API reference: http://www.ohloh.net/api/getting_started | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | =item * | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | Ohloh Account API reference: http://www.ohloh.net/api/reference/stack_entry | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | =back | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | =head1 VERSION | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | This document describes WWW::Ohloh::API version 0.3.2 | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | =head1 BUGS AND LIMITATIONS | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | WWW::Ohloh::API is very extremely alpha quality. It'll improve, | ||||||||||||||||||||
| 176 | but till then: I<Caveat emptor>. | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | Please report any bugs or feature requests to | ||||||||||||||||||||
| 179 | C<bug-www-ohloh-api@rt.cpan.org>, or through the web interface at | ||||||||||||||||||||
| 180 | L<http://rt.cpan.org>. | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | =head1 AUTHOR | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | Yanick Champoux C<< <yanick@cpan.org> >> | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | =head1 LICENCE AND COPYRIGHT | ||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | Copyright (c) 2008, Yanick Champoux C<< <yanick@cpan.org> >>. All rights reserved. | ||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | This module is free software; you can redistribute it and/or | ||||||||||||||||||||
| 192 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | |||||||||||||||||||||