blib/lib/WWW/Ohloh/API/StackEntry.pm

filter: Statementstmt 98.2% 55 / 56 Branchbran 70.0% 7 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 89.2% 75 / 84 CC 9 SCAR 10.7
CC
9
Cov
90%
project
5.6
_init
4.0
as_xml
3.0
CRAP 2.9
« blib/lib/WWW/Ohloh/API/Messages.pm ↑ Summary blib/lib/WWW/Ohloh/API/Kudos.pm »
1 package WWW::Ohloh::API::StackEntry;
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;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use List::MoreUtils qw/ any /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our $VERSION = '1.0_1';
13  
14 3 my @ohloh_of : Field : Arg(ohloh);
15 3 my @request_url_of : Field : Arg(request_url) : Get( request_url );
16 3 my @xml_of : Field : Arg(xml);
17  
18 3 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 3 for @api_fields;
27  
28 3 my @project : Field;
29  
30 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31  
32 sub _init : Init {
33 379 ▶ my $self = shift;
Subroutine _init: called CC=4 SCAR=13.9
34  
35 379 ▶ my $dom = $xml_of[$$self] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $dom = $xml_of[$$self] or return 0 379 379
36  
37 379 for my $f (@api_fields) {
38 1516 my $method = "_set_$f";
39 1516 $self->$method( $dom->findvalue("$f/text()") );
40 }
41  
42 379 ▶ if ( my ($project_xml) = $dom->findnodes('//project[1]') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($project_xml) = $dom->findnodes("//project[1]")) 70 309 379
43 70 $project[$$self] = WWW::Ohloh::API::Project->new(
44 ohloh => $ohloh_of[$$self],
45 xml => $project_xml,
46 );
47 }
48  
49 379 return;
50 3 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53  
54 sub as_xml {
55 344 ▶ my $self = shift;
Subroutine as_xml: called CC=3 SCAR=11.0
Pod documented
56 344 my $xml;
57 344 my $w = XML::Writer->new( OUTPUT => \$xml );
58  
59 344 $w->startTag('stack_entry');
60  
61 344 for my $f (@api_fields) {
62 1376 $w->dataElement( $f => $self->$f );
63 }
64  
65 344 ▶ if ( my $project = $project[$$self] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $project = $project[$$self]) 35 309 344
66 35 $xml .= $project->as_xml;
67 }
68  
69 344 $w->endTag;
70  
71 344 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
BranchTrueFalseTotal
unless defined $retrieve 0 309 309
80  
81 309 ▶ if ($retrieve) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retrieve) 0 309 309
82 0 ▶ $project[$$self] ||=
Condition0%0/3
$project[$$self] ||= $ohloh_of[$$self]->get_project($self->project_id)
l!l&&r!l&&!r
000
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)
ABresult
1X1
011
000
83 $ohloh_of[$$self]->get_project( $self->project_id );
84 }
85  
86 309 return $project[$$self];
87 }
88  
89 3 '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->fetch_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 1.0_1
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  
« blib/lib/WWW/Ohloh/API/Messages.pm ↑ Summary blib/lib/WWW/Ohloh/API/Kudos.pm »