WWW::Ohloh::API::StackEntry - A project entry in a stack


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

Index


Code Index:

NAME

Top

WWW::Ohloh::API::StackEntry - A project entry in a stack

SYNOPSIS

Top

    use WWW::Ohloh::API;

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

    # from an account
    my @entries = $ohloh->get_account_stack( $account_id )->stack_entries;

    # from a project
    my @stacks = $ohloh->get_project_stacks( $project_id );
    my @entries = $stacks[0]->stack_entries;




DESCRIPTION

Top

W::O::A::StackEntry represents one project in a stack.

METHODS

Top

API Data Accessors

$entry->id

Returns the unique id for the stack entry.

$entry->created_at

Returns the time at which the project was added to the stack.

$entry->stack_id

Returns the id of the stack containing the entry.

$entry->project_id

Returns the id of the project.

$entry->project( $retrieve )

Returns the project as a WWW::Ohloh::API::Project object.

If the optional argument $retrieve is given and false, the project will not be queried from the Ohloh server if it's not already known, and the method will return nothing.

Other Methods

as_xml

Return the stack entry as an XML string. Note that this is not the same xml document as returned by the Ohloh server.

SEE ALSO

Top

*

WWW::Ohloh::API.

*

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

*

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

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.

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::StackEntry;

use strict;
use warnings;

use Carp;
use Object::InsideOut;
use XML::LibXML;
use Readonly;
use List::MoreUtils qw/ any /;

our $VERSION = '0.3.1';

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

my @api_fields = qw/
  id
  created_at
  stack_id
  project_id
  /;

__PACKAGE__->create_field( '%' . $_, ":Set(_set_$_)", ":Get($_)" )
  for @api_fields;

my @project : Field;

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

sub _init : Init {
    my $self = shift;

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

    for my $f (@api_fields) {
        my $method = "_set_$f";
        $self->$method( $dom->findvalue("$f/text()") );
    }

    if ( my ($project_xml) = $dom->findnodes('//project[1]') ) {
        $project[$$self] = WWW::Ohloh::API::Project->new(
            ohloh => $ohloh_of[$$self],
            xml   => $project_xml,
        );
    }

    return;
}

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

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

    $w->startTag('stack_entry');

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

    if ( my $project = $project[$$self] ) {
        $xml .= $project->as_xml;
    }

    $w->endTag;

    return $xml;
}

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

sub project {
    my $self     = shift;
    my $retrieve = shift;
    $retrieve = 1 unless defined $retrieve;

    if ($retrieve) {
        $project[$$self] ||=
          $ohloh_of[$$self]->get_project( $self->project_id );
    }

    return $project[$$self];
}

'end of WWW::Ohloh::API::StackEntry';
__END__