| 1 | package WWW::Ohloh::API::Message; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Object::InsideOut; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use XML::LibXML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use WWW::Ohloh::API::Message::Tag; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | our $VERSION = '1.0_1'; | |||||||||
| 13 | |||||||||||
| 14 | 1 | my @request_url_of : Field : Arg(request_url) : Get( request_url ); | |||||||||
| 15 | 1 | my @ohloh_of : Field : Arg(ohloh); | |||||||||
| 16 | |||||||||||
| 17 | 1 | my @api_fields = qw/ id account avatar created_at body /; | |||||||||
| 18 | |||||||||||
| 19 | 1 | my @id_of : Field : Set(_set_id) : Get(id); | |||||||||
| 20 | 1 | my @account_of : Field : Set(_set_account) : Get(account); | |||||||||
| 21 | 1 | my @avatar_of : Field : Set(_set_avatar) : Get(avatar); | |||||||||
| 22 | 1 | my @creation_time_of : Field : Set(_set_creation_time) : Get(creation_time); | |||||||||
| 23 | 1 | my @body_of : Field : Set(_set_body) : Get(body); | |||||||||
| 24 | 1 | my @tags_of : Field; | |||||||||
| 25 | |||||||||||
| 26 | 1 | my %init_args : InitArgs = ( 'xml' => '', ); | |||||||||
| 27 | |||||||||||
| 28 | sub _init : Init { | ||||||||||
| 29 | 4 | ▶ | my ( $self, $args ) = @_; | ||||||||
|
Subroutine
_init: called CC=2 SCAR=7.2
| |||||||||||
| 30 | |||||||||||
| 31 | 4 | ▶ | $self->load_xml( $args->{xml} ) if $args->{xml}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 35 | |||||||||||
| 36 | sub load_xml { | ||||||||||
| 37 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
load_xml: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 38 | 4 | my $dom = shift; | |||||||||
| 39 | |||||||||||
| 40 | 4 | $self->_set_id( $dom->findvalue("id/text()") ); | |||||||||
| 41 | 4 | $self->_set_account( $dom->findvalue("account/text()") ); | |||||||||
| 42 | 4 | $self->_set_avatar( $dom->findvalue('avatar/@uri') ); | |||||||||
| 43 | 4 | $self->_set_creation_time( $dom->findvalue("created_at/text()") ); | |||||||||
| 44 | 4 | $self->_set_body( $dom->findvalue("body/text()") ); | |||||||||
| 45 | |||||||||||
| 46 | 4 | for ( $dom->findnodes('tags/*') ) { | |||||||||
| 47 | 1 | $self->insert_tag( | |||||||||
| 48 | WWW::Ohloh::API::Message::Tag->new( | ||||||||||
| 49 | ohloh => $ohloh_of[$$self], | ||||||||||
| 50 | xml => $_, | ||||||||||
| 51 | ) ); | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | sub tags { | ||||||||||
| 57 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
tags: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 58 | 1 | ▶ | return $tags_of[$$self] ? @{ $tags_of[$$self] } : (); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | sub insert_tag { | ||||||||||
| 62 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
insert_tag: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 63 | 1 | push @{ $tags_of[$$self] }, @_; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 67 | |||||||||||
| 68 | sub as_xml { | ||||||||||
| 69 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
as_xml: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 70 | 0 | my $xml; | |||||||||
| 71 | 0 | my $w = XML::Writer->new( OUTPUT => \$xml ); | |||||||||
| 72 | |||||||||||
| 73 | 0 | $w->startTag('language'); | |||||||||
| 74 | |||||||||||
| 75 | 0 | for my $e (@api_fields) { | |||||||||
| 76 | 0 | $w->dataElement( $e => $self->$e ); | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 0 | $w->endTag; | |||||||||
| 80 | |||||||||||
| 81 | 0 | return $xml; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 85 | |||||||||||
| 86 | sub is_code { | ||||||||||
| 87 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
is_code: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 88 | |||||||||||
| 89 | 0 | return $self->category eq 'code'; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 93 | |||||||||||
| 94 | sub is_markup { | ||||||||||
| 95 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
is_markup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 96 | |||||||||||
| 97 | 0 | return $self->category eq 'markup'; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 1 | 'end of WWW::Ohloh::API::Language'; | |||||||||
| 101 | |||||||||||
| 102 | __END__ | ||||||||||
| 103 | |||||||||||
| 104 | =head1 NAME | ||||||||||
| 105 | |||||||||||
| 106 | WWW::Ohloh::API::Message - a Ohloh message | ||||||||||
| 107 | |||||||||||
| 108 | =head1 SYNOPSIS | ||||||||||
| 109 | |||||||||||
| 110 | use WWW::Ohloh::API; | ||||||||||
| 111 | |||||||||||
| 112 | my $ohloh = WWW::Ohloh::API->new( api_key => $my_api_key ); | ||||||||||
| 113 | my $messages = $ohloh->fetch_messages( account => $id ); | ||||||||||
| 114 | |||||||||||
| 115 | while( my $msg = $messages->next ) { | ||||||||||
| 116 | print $msg->body, "\n"; | ||||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | |||||||||||
| 120 | =head1 DESCRIPTION | ||||||||||
| 121 | |||||||||||
| 122 | W::O::A::Message contains the information associated with an Ohloh message. | ||||||||||
| 123 | |||||||||||
| 124 | =head1 METHODS | ||||||||||
| 125 | |||||||||||
| 126 | =head2 API Data Accessors | ||||||||||
| 127 | |||||||||||
| 128 | =head3 id | ||||||||||
| 129 | |||||||||||
| 130 | Returns the message's id. | ||||||||||
| 131 | |||||||||||
| 132 | =head3 account | ||||||||||
| 133 | |||||||||||
| 134 | Returns the author of the message (as a string). | ||||||||||
| 135 | |||||||||||
| 136 | =head3 avatar | ||||||||||
| 137 | |||||||||||
| 138 | Returns (if available) the url pointing to the message author's avatar. | ||||||||||
| 139 | |||||||||||
| 140 | =head3 creation_time | ||||||||||
| 141 | |||||||||||
| 142 | Returns the time at which the message has been written. | ||||||||||
| 143 | |||||||||||
| 144 | =head3 body | ||||||||||
| 145 | |||||||||||
| 146 | Returns the body of the message. | ||||||||||
| 147 | |||||||||||
| 148 | =head3 tags | ||||||||||
| 149 | |||||||||||
| 150 | Returns the tags associated to the message as an array of | ||||||||||
| 151 | L<WWW::Ohloh::API::Message::Tag> objects. | ||||||||||
| 152 | |||||||||||
| 153 | =head2 Other Methods | ||||||||||
| 154 | |||||||||||
| 155 | =head3 as_xml | ||||||||||
| 156 | |||||||||||
| 157 | Return the message's information | ||||||||||
| 158 | as an XML string. Note that this is not the exact xml document as returned | ||||||||||
| 159 | by the Ohloh server. | ||||||||||
| 160 | |||||||||||
| 161 | =head1 SEE ALSO | ||||||||||
| 162 | |||||||||||
| 163 | =over | ||||||||||
| 164 | |||||||||||
| 165 | =item * | ||||||||||
| 166 | |||||||||||
| 167 | L<WWW::Ohloh::API>, | ||||||||||
| 168 | L<WWW::Ohloh::API::Messages>, | ||||||||||
| 169 | L<WWW::Ohloh::API::Message::Tag>. | ||||||||||
| 170 | |||||||||||
| 171 | =item * | ||||||||||
| 172 | |||||||||||
| 173 | Ohloh API reference: http://www.ohloh.net/api/getting_started | ||||||||||
| 174 | |||||||||||
| 175 | =item * | ||||||||||
| 176 | |||||||||||
| 177 | Ohloh Account API reference: http://www.ohloh.net/api/reference/message | ||||||||||
| 178 | |||||||||||
| 179 | =back | ||||||||||
| 180 | |||||||||||
| 181 | =head1 VERSION | ||||||||||
| 182 | |||||||||||
| 183 | This document describes WWW::Ohloh::API version 1.0_1 | ||||||||||
| 184 | |||||||||||
| 185 | =head1 BUGS AND LIMITATIONS | ||||||||||
| 186 | |||||||||||
| 187 | WWW::Ohloh::API is very extremely alpha quality. It'll improve, | ||||||||||
| 188 | but till then: I<Caveat emptor>. | ||||||||||
| 189 | |||||||||||
| 190 | The C<as_xml()> method returns a re-encoding of the account data, which | ||||||||||
| 191 | can differ of the original xml document sent by the Ohloh server. | ||||||||||
| 192 | |||||||||||
| 193 | Please report any bugs or feature requests to | ||||||||||
| 194 | C<bug-www-ohloh-api@rt.cpan.org>, or through the web interface at | ||||||||||
| 195 | L<http://rt.cpan.org>. | ||||||||||
| 196 | |||||||||||
| 197 | |||||||||||
| 198 | =head1 AUTHOR | ||||||||||
| 199 | |||||||||||
| 200 | Yanick Champoux C<< <yanick@cpan.org> >> | ||||||||||
| 201 | |||||||||||
| 202 | =head1 LICENCE AND COPYRIGHT | ||||||||||
| 203 | |||||||||||
| 204 | Copyright (c) 2008, Yanick Champoux C<< <yanick@cpan.org> >>. All rights reserved. | ||||||||||
| 205 | |||||||||||
| 206 | This module is free software; you can redistribute it and/or | ||||||||||
| 207 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||
| 208 | |||||||||||
| 209 | =cut | ||||||||||
| 210 | |||||||||||