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

filter: Statementstmt 79.6% 51 / 64 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 8 / 12 Podpod 100% 3 / 3 totaltotal 77.7% 63 / 81 CC 3 SCAR 6.9
CC
3
Cov
79%
as_xml
6.0
_init
2.0
is_code
2.0
CRAP 2.0
« blib/lib/WWW/Ohloh/API/Message.pm ↑ Summary blib/lib/WWW/Ohloh/API/Account.pm »
1 package WWW::Ohloh::API::Language;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 16 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Object::InsideOut;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 16 our $VERSION = '1.0_1';
11  
12 16 ▶use overload '""' => sub { $_[0]->nice_name };
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
13  
14 16 my @request_url_of : Field : Arg(request_url) : Get( request_url );
15 16 my @xml_of : Field : Arg(xml);
16 16 my @ohloh_of : Field : Arg(ohloh);
17  
18 16 my @api_fields = qw/
19 id
20 name
21 nice_name
22 category
23 code
24 comments
25 blanks
26 comment_ratio
27 projects
28 contributors
29 commits
30 /;
31  
32 16 my @id_of : Field : Set(_set_id) : Get(id);
33 16 my @name_of : Field : Set(_set_name) : Get(name);
34 16 my @nice_name_of : Field : Set(_set_nice_name) : Get(nice_name);
35 16 my @category_of : Field : Set(_set_category) : Get(category);
36 16 my @lines_of_code_of : Field : Set(_set_code) : Get(code);
37 16 my @comments_of : Field : Set(_set_comments) : Get(comments);
38 16 my @comment_ratio_of : Field : Set(_set_comment_ratio) : Get(comment_ratio);
39 16 my @blanks_of : Field : Set(_set_blanks) : Get(blanks);
40 16 my @projects_of : Field : Set(_set_projects) : Get(projects);
41 16 my @contributors_of : Field : Set(_set_contributors) : Get(contributors);
42 16 my @commits_of : Field : Set(_set_commits) : Get(commits);
43  
44 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45  
46 sub _init : Init {
47 32 ▶ my $self = shift;
Subroutine _init: called CC=2 SCAR=6.9
48  
49 32 ▶ my $dom = $xml_of[$$self] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $dom = $xml_of[$$self] or return 0 32 32
50  
51 32 $self->_set_id( $dom->findvalue("id/text()") );
52 32 $self->_set_name( $dom->findvalue("name/text()") );
53 32 $self->_set_nice_name( $dom->findvalue("nice_name/text()") );
54 32 $self->_set_category( $dom->findvalue("category/text()") );
55 32 $self->_set_code( $dom->findvalue("code/text()") );
56 32 $self->_set_comments( $dom->findvalue("comments/text()") );
57 32 $self->_set_blanks( $dom->findvalue("blanks/text()") );
58 32 $self->_set_comment_ratio( $dom->findvalue("comment_ratio/text()") );
59 32 $self->_set_projects( $dom->findvalue("projects/text()") );
60 32 $self->_set_contributors( $dom->findvalue("contributors/text()") );
61 32 $self->_set_commits( $dom->findvalue("commits/text()") );
62 16 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65  
66 sub as_xml {
67 0 ▶ my $self = shift;
Subroutine as_xml: not called CC=2 SCAR=17.9
Pod documented
68 0 my $xml;
69 0 my $w = XML::Writer->new( OUTPUT => \$xml );
70  
71 0 $w->startTag('language');
72  
73 0 for my $e (@api_fields) {
74 0 $w->dataElement( $e => $self->$e );
75 }
76  
77 0 $w->endTag;
78  
79 0 return $xml;
80 }
81  
82 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83  
84 sub is_code {
85 0 ▶ my $self = shift;
Subroutine is_code: not called CC=1 SCAR=6.9
Pod documented
86  
87 0 return $self->category eq 'code';
88 }
89  
90 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91  
92 sub is_markup {
93 0 ▶ my $self = shift;
Subroutine is_markup: not called CC=1 SCAR=6.9
Pod documented
94  
95 0 return $self->category eq 'markup';
96 }
97  
98 16 'end of WWW::Ohloh::API::Language';
99  
100 __END__
101  
102 =head1 NAME
103  
104 WWW::Ohloh::API::Language - a programming language information on Ohloh
105  
106 =head1 SYNOPSIS
107  
108 use WWW::Ohloh::API;
109  
110 my $ohloh = WWW::Ohloh::API->new( api_key => $my_api_key );
111 my $languages = $ohloh->get_languages;
112  
113 my ( $perl ) = grep { $_->nice_name eq 'Perl' } $languages->all;
114  
115 print $perl->projects, " projects use Perl";
116  
117 =head1 DESCRIPTION
118  
119 W::O::A::Language contains the information associated with a programming
120 language recognized by Ohloh as defined at http://www.ohloh.net/api/reference/language.
121 To be properly populated, it must be created via
122 the C<get_languages> or C<get_language> method of a L<WWW::Ohloh::API> object.
123  
124 =head1 METHODS
125  
126 =head2 API Data Accessors
127  
128 =head3 id
129  
130 Return the language's unique id.
131  
132 =head3 name
133  
134 Return the short name of the language.
135  
136 =head3 nice_name
137  
138 Return the human-friendly name of the language.
139  
140 =head3 category
141  
142 Return the type of language, which can be either C<code> or
143 C<markup>.
144  
145 =head3 is_markup
146  
147 Return true if the language is a markup language, false if it's a
148 code language.
149  
150 =head3 is_code
151  
152 Return true if the language is a code language, false if it's a
153 markup language.
154  
155  
156 =head3 code
157  
158 Return the total number of lines of code, excluding comments and blank lines, written
159 in the language across all projects.
160  
161 =head3 comments
162  
163 Return the total number of comment lines, written
164 in the language across all projects.
165  
166 =head3 blanks
167  
168 Return the total number of blanks lines, written
169 in the language across all projects.
170  
171 =head3 comment_ratio
172  
173 Return the ratio of comment lines over the total number of lines for all projects using
174 the language.
175  
176 =head3 projects
177  
178 Return the number of projects using this language.
179  
180 =head3 contributors
181  
182 Return the number of contributors who have written at least one line of code
183 using this language.
184  
185 =head3 commits
186  
187 Return the number of commits which include at least one line in this language.
188  
189 =head2 Other Methods
190  
191 =head3 as_xml
192  
193 Return the language information
194 as an XML string. Note that this is not the exact xml document as returned
195 by the Ohloh server.
196  
197 =head1 SEE ALSO
198  
199 =over
200  
201 =item *
202  
203 L<WWW::Ohloh::API>,
204 L<WWW::Ohloh::API::KudoScore>.
205  
206 =item *
207  
208 Ohloh API reference: http://www.ohloh.net/api/getting_started
209  
210 =item *
211  
212 Ohloh Account API reference: http://www.ohloh.net/api/reference/language
213  
214 =back
215  
216 =head1 VERSION
217  
218 This document describes WWW::Ohloh::API version 1.0_1
219  
220 =head1 BUGS AND LIMITATIONS
221  
222 WWW::Ohloh::API is very extremely alpha quality. It'll improve,
223 but till then: I<Caveat emptor>.
224  
225 The C<as_xml()> method returns a re-encoding of the account data, which
226 can differ of the original xml document sent by the Ohloh server.
227  
228 Please report any bugs or feature requests to
229 C<bug-www-ohloh-api@rt.cpan.org>, or through the web interface at
230 L<http://rt.cpan.org>.
231  
232  
233 =head1 AUTHOR
234  
235 Yanick Champoux C<< <yanick@cpan.org> >>
236  
237 =head1 LICENCE AND COPYRIGHT
238  
239 Copyright (c) 2008, Yanick Champoux C<< <yanick@cpan.org> >>. All rights reserved.
240  
241 This module is free software; you can redistribute it and/or
242 modify it under the same terms as Perl itself. See L<perlartistic>.
243  
244 =cut
« blib/lib/WWW/Ohloh/API/Message.pm ↑ Summary blib/lib/WWW/Ohloh/API/Account.pm »