File Coverage

blib/lib/WWW/Ohloh/API/Message.pm
Criterion Covered Total %
statement 36 50 72.0
branch 1 4 25.0
condition n/a
subroutine 10 14 71.4
pod 2 6 33.3
total 49 74 66.2


line stmt bran cond sub pod time code
1             package WWW::Ohloh::API::Message;
2             our $AUTHORITY = 'cpan:YANICK';
3              
4 5     5   236977 use strict;
  5         14  
  5         265  
5 5     5   27 use warnings;
  5         9  
  5         317  
6              
7 5     5   28 use Carp;
  5         9  
  5         403  
8 5     5   1006 use Object::InsideOut;
  5         53293  
  5         44  
9 5     5   1095 use XML::LibXML;
  5         34303  
  5         36  
10              
11 5     5   3548 use WWW::Ohloh::API::Message::Tag;
  5         22  
  5         45  
12              
13             our $VERSION = '1.0_1';
14              
15             my @request_url_of : Field : Arg(request_url) : Get( request_url );
16             my @ohloh_of : Field : Arg(ohloh);
17              
18             my @api_fields = qw/ id account avatar created_at body /;
19              
20             my @id_of : Field : Set(_set_id) : Get(id);
21             my @account_of : Field : Set(_set_account) : Get(account);
22             my @avatar_of : Field : Set(_set_avatar) : Get(avatar);
23             my @creation_time_of : Field : Set(_set_creation_time) : Get(creation_time);
24             my @body_of : Field : Set(_set_body) : Get(body);
25             my @tags_of : Field;
26              
27             my %init_args : InitArgs = ( 'xml' => '', );
28              
29             sub _init : Init {
30 0     0   0 my ( $self, $args ) = @_;
31              
32 0 0       0 $self->load_xml( $args->{xml} ) if $args->{xml};
33 5     5   1681 }
  5         27  
  5         31  
34              
35             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36              
37             sub load_xml {
38 4     4 0 40 my $self = shift;
39 4         8 my $dom = shift;
40              
41 4         18 $self->_set_id( $dom->findvalue("id/text()") );
42 4         657 $self->_set_account( $dom->findvalue("account/text()") );
43 4         413 $self->_set_avatar( $dom->findvalue('avatar/@uri') );
44 4         525 $self->_set_creation_time( $dom->findvalue("created_at/text()") );
45 4         380 $self->_set_body( $dom->findvalue("body/text()") );
46              
47 4         392 for ( $dom->findnodes('tags/*') ) {
48 1         31 $self->insert_tag(
49             WWW::Ohloh::API::Message::Tag->new(
50             ohloh => $ohloh_of[$$self],
51             xml => $_,
52             ) );
53             }
54              
55             }
56              
57             sub tags {
58 1     1 1 8355 my $self = shift;
59 1 50       6 return $tags_of[$$self] ? @{ $tags_of[$$self] } : ();
  1         5  
60             }
61              
62             sub insert_tag {
63 1     1 0 179 my $self = shift;
64 1         2 push @{ $tags_of[$$self] }, @_;
  1         14  
65             }
66              
67             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68              
69             sub as_xml {
70 0     0 1   my $self = shift;
71 0           my $xml;
72 0           my $w = XML::Writer->new( OUTPUT => \$xml );
73              
74 0           $w->startTag('language');
75              
76 0           for my $e (@api_fields) {
77 0           $w->dataElement( $e => $self->$e );
78             }
79              
80 0           $w->endTag;
81              
82 0           return $xml;
83             }
84              
85             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86              
87             sub is_code {
88 0     0 0   my $self = shift;
89              
90 0           return $self->category eq 'code';
91             }
92              
93             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94              
95             sub is_markup {
96 0     0 0   my $self = shift;
97              
98 0           return $self->category eq 'markup';
99             }
100              
101             'end of WWW::Ohloh::API::Language';
102              
103             __END__