WWW::Ohloh::API::Message::Tag - a tag associated to an Ohloh message


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

Index


Code Index:

NAME

Top

WWW::Ohloh::API::Message::Tag - a tag associated to an Ohloh message

SYNOPSIS

Top

    use WWW::Ohloh::API;

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

    while ( my $msg = $messages->next ) {
        print $msg->body, "\n";
        for my $tag ( $msg->tags ) {
            print "\t", $tag->content, "\n";
        }
    }

DESCRIPTION

Top

W::O::A::Message::Tag contains the information of a tag associated with a message.

METHODS

Top

API Data Accessors

type

Returns the tag type, which can be 'account' or 'project'.

set_type( $type )

Sets the tag type. Must be either 'account' or 'project'.

uri

Returns the tag uri.

set_uri( $uri )

Sets the tag uri.

content

Returns the content of the tag, which will either be the name of the tagged project or account.

set_content( $name )

Sets the content of the tag to $name.

Other Methods

as_xml

Returns the tag 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::Message.

*

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

*

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

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::Message::Tag;

use strict;
use warnings;

use Object::InsideOut qw/
  WWW::Ohloh::API::Role::Fetchable
  WWW::Ohloh::API::Role::LoadXML
  /;

use Carp;
use XML::LibXML;

use List::MoreUtils qw/ any /;

our $VERSION = '0.3.1';

my @type_of : Field : Set(set_type) : Get(type);
my @uri_of : Field : Set(set_uri) : Get(uri);
my @content_of : Field : Set(set_content) : Get(content);

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

sub load_xml {
    my $self = shift;
    my $dom  = shift;

    my $type = $dom->nodeName;
    die "tag is of type $type, should be 'project' or 'account'"
      unless any { $_ eq $type } qw/ project account /;

    $self->set_type($type);
    $self->set_uri( $dom->getAttribute('uri') );
    $self->set_content( $dom->findvalue('text()') );
}

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

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

    $w->dataElement( $self->type, $self->content, uri => $self->uri );

    return $xml;
}

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

sub is_project {
    return $_[0]->type eq 'project';
}

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

sub is_account {
    return $_[0]->type eq 'account';
}

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

'end of WWW::Ohloh::API::Message::Tag';

__END__