WWW::Ohloh::API::Language - a programming language information on Ohloh


WWW-Ohloh-API documentation Contained in the WWW-Ohloh-API distribution.

Index


Code Index:

NAME

Top

WWW::Ohloh::API::Language - a programming language information on Ohloh

SYNOPSIS

Top

    use WWW::Ohloh::API;

    my $ohloh = WWW::Ohloh::API->new( api_key => $my_api_key );
    my $languages =  $ohloh->get_languages;

    my ( $perl  ) = grep { $_->nice_name eq 'Perl' } $languages->all;

    print $perl->projects, " projects use Perl";

DESCRIPTION

Top

W::O::A::Language contains the information associated with a programming language recognized by Ohloh as defined at http://www.ohloh.net/api/reference/language. To be properly populated, it must be created via the get_languages or get_language method of a WWW::Ohloh::API object.

METHODS

Top

API Data Accessors

id

Return the language's unique id.

name

Return the short name of the language.

nice_name

Return the human-friendly name of the language.

category

Return the type of language, which can be either code or markup.

is_markup

Return true if the language is a markup language, false if it's a code language.

is_code

Return true if the language is a code language, false if it's a markup language.

code

Return the total number of lines of code, excluding comments and blank lines, written in the language across all projects.

comments

Return the total number of comment lines, written in the language across all projects.

blanks

Return the total number of blanks lines, written in the language across all projects.

comment_ratio

Return the ratio of comment lines over the total number of lines for all projects using the language.

projects

Return the number of projects using this language.

contributors

Return the number of contributors who have written at least one line of code using this language.

commits

Return the number of commits which include at least one line in this language.

Other Methods

as_xml

Return the language information as an XML string. Note that this is not the exact xml document as returned by the Ohloh server.

SEE ALSO

Top

*

WWW::Ohloh::API, WWW::Ohloh::API::KudoScore.

*

Ohloh API reference: http://www.ohloh.net/api/getting_started

*

Ohloh Account API reference: http://www.ohloh.net/api/reference/language

VERSION

Top

This document describes WWW::Ohloh::API version 0.3.1

BUGS AND LIMITATIONS

Top

WWW::Ohloh::API is very extremely alpha quality. It'll improve, but till then: Caveat emptor.

The as_xml() method returns a re-encoding of the account data, which can differ of the original xml document sent by the Ohloh server.

Please report any bugs or feature requests to bug-www-ohloh-api@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Top

Yanick Champoux <yanick@cpan.org>

LICENCE AND COPYRIGHT

Top


WWW-Ohloh-API documentation Contained in the WWW-Ohloh-API distribution.

package WWW::Ohloh::API::Language;

use strict;
use warnings;

use Carp;
use Object::InsideOut;
use XML::LibXML;

our $VERSION = '0.3.1';

use overload '""' => sub { $_[0]->nice_name };

my @request_url_of : Field : Arg(request_url) : Get( request_url );
my @xml_of : Field : Arg(xml);
my @ohloh_of : Field : Arg(ohloh);

my @api_fields = qw/
  id
  name
  nice_name
  category
  code
  comments
  blanks
  comment_ratio
  projects
  contributors
  commits
  /;

my @id_of : Field : Set(_set_id) : Get(id);
my @name_of : Field : Set(_set_name) : Get(name);
my @nice_name_of : Field : Set(_set_nice_name) : Get(nice_name);
my @category_of : Field : Set(_set_category) : Get(category);
my @lines_of_code_of : Field : Set(_set_code) : Get(code);
my @comments_of : Field : Set(_set_comments) : Get(comments);
my @comment_ratio_of : Field : Set(_set_comment_ratio) : Get(comment_ratio);
my @blanks_of : Field : Set(_set_blanks) : Get(blanks);
my @projects_of : Field : Set(_set_projects) : Get(projects);
my @contributors_of : Field : Set(_set_contributors) : Get(contributors);
my @commits_of : Field : Set(_set_commits) : Get(commits);

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sub _init : Init {
    my $self = shift;

    my $dom = $xml_of[$$self] or return;

    $self->_set_id( $dom->findvalue("id/text()") );
    $self->_set_name( $dom->findvalue("name/text()") );
    $self->_set_nice_name( $dom->findvalue("nice_name/text()") );
    $self->_set_category( $dom->findvalue("category/text()") );
    $self->_set_code( $dom->findvalue("code/text()") );
    $self->_set_comments( $dom->findvalue("comments/text()") );
    $self->_set_blanks( $dom->findvalue("blanks/text()") );
    $self->_set_comment_ratio( $dom->findvalue("comment_ratio/text()") );
    $self->_set_projects( $dom->findvalue("projects/text()") );
    $self->_set_contributors( $dom->findvalue("contributors/text()") );
    $self->_set_commits( $dom->findvalue("commits/text()") );
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sub as_xml {
    my $self = shift;
    my $xml;
    my $w = XML::Writer->new( OUTPUT => \$xml );

    $w->startTag('language');

    for my $e (@api_fields) {
        $w->dataElement( $e => $self->$e );
    }

    $w->endTag;

    return $xml;
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sub is_code {
    my $self = shift;

    return $self->category eq 'code';
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sub is_markup {
    my $self = shift;

    return $self->category eq 'markup';
}

'end of WWW::Ohloh::API::Language';

__END__