WWW::Ohloh::API::Stack - a collection of projects used by a person


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

Index


Code Index:

NAME

Top

WWW::Ohloh::API::Stack - a collection of projects used by a person

SYNOPSIS

Top

    use WWW::Ohloh::API;

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

    # get the stack of a person
    my $stack = $ohloh->get_account_stack( $account_id );

    # get stacks containing a project
    my @stacks = $ohloh->get_project_stacks( $project_id );




DESCRIPTION

Top

W::O::A::Stack represents a collection of projects used by a person.

METHODS

Top

API Data Accessors

id

Returns the unique id for the stack.

updated_at

Returns the most recent time at which any projects were added to or removed from this stack as a Time::Piece object.

project_count

Returns the number of projects in the stack.

stack_entries

Returns a list of the entries contained by the stack as WWW::Ohloh::API::StackEntry objects.

account_id

Returns the id of the account owning the stack.

account( $retrieve )

Returns the account associated to the stack as a WWW::Ohloh::API::Account object.

If the account information was not present at the object's creation time, it will be queried from the ohloh server, unless $retrieve is defined and set to false.

Other Methods

as_xml

Returns the stack 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

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

use strict;
use warnings;

use Carp;
use Object::InsideOut;
use XML::LibXML;
use Readonly;
use Scalar::Util qw/ weaken /;
use Date::Parse;
use Time::Piece;

use WWW::Ohloh::API::StackEntry;

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
  updated_at
  project_count
  stack_entries
  account_id
  account
  /;

__PACKAGE__->create_field( '@' . $_, ":Set(_set_$_)", ":Get($_)" )
  for qw/ id updated_at project_count account_id /;

my @stack_entries_of : Field;
my @account_of : Field;

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

sub _init : Init {
    my $self = shift;

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

    for my $f (qw/ id project_count account_id /) {
        my $method = "_set_$f";
        $self->$method( $dom->findvalue("$f/text()") );
    }

    $self->_set_updated_at(
        Time::Piece->new( str2time( $dom->findvalue("updated_at/text()") ) )
    );

    if ( my ($account_xml) = $dom->findnodes('account[1]') ) {
        $account_of[$$self] = WWW::Ohloh::API::Account->new(
            ohloh => $ohloh_of[$$self],
            xml   => $account_xml,
        );
    }

    $stack_entries_of[$$self] = [
        map WWW::Ohloh::API::StackEntry->new(
            ohloh => $ohloh_of[$$self],
            xml   => $_,
          ) => $dom->findnodes('stack_entries/stack_entry') ];

    return;
}

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

sub stack_entries {
    my $self = shift;
    return @{ $stack_entries_of[$$self] };
}

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

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

    $w->startTag('stack');

    for my $f (qw/ id updated_at project_count account_id /) {
        $w->dataElement( $f => $self->$f );
    }

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

    if ( my @entries = @{ $stack_entries_of[$$self] } ) {
        $w->startTag('stack_entries');
        $xml .= $_->as_xml for @entries;
        $w->endTag;
    }

    $w->endTag;

    return $xml;
}

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

sub account {
    my $self = shift;

    my $retrieve = shift;

    $retrieve = 1 unless defined $retrieve;

    if ($retrieve) {
        $account_of[$$self] ||=
          $ohloh_of[$$self]->get_account( id => $self->account_id );
    }

    return $account_of[$$self];

}

sub set_account : Private( WWW::Ohloh::API::Account ) {
    my $self = shift;

    weaken( $account_of[$$self] = shift );

    return;
}

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