File Coverage

blib/lib/WWW/Ohloh/API/StackEntry.pm
Criterion Covered Total %
statement 38 48 79.1
branch 3 10 30.0
condition 0 3 0.0
subroutine 10 11 90.9
pod 2 2 100.0
total 53 74 71.6


line stmt bran cond sub pod time code
1             package WWW::Ohloh::API::StackEntry;
2             our $AUTHORITY = 'cpan:YANICK';
3              
4 4     4   205737 use strict;
  4         9  
  4         207  
5 4     4   24 use warnings;
  4         9  
  4         279  
6              
7 4     4   24 use Carp;
  4         12  
  4         308  
8 4     4   950 use Object::InsideOut;
  4         46247  
  4         32  
9 4     4   1806 use XML::LibXML;
  4         34720  
  4         32  
10 4     4   1298 use Readonly;
  4         3164  
  4         267  
11 4     4   1167 use List::MoreUtils qw/ any /;
  4         31402  
  4         48  
12              
13             our $VERSION = '1.0_1';
14              
15             my @ohloh_of : Field : Arg(ohloh);
16             my @request_url_of : Field : Arg(request_url) : Get( request_url );
17             my @xml_of : Field : Arg(xml);
18              
19             my @api_fields = qw/
20             id
21             created_at
22             stack_id
23             project_id
24             /;
25              
26             __PACKAGE__->create_field( '%' . $_, ":Set(_set_$_)", ":Get($_)" )
27             for @api_fields;
28              
29             my @project : Field;
30              
31             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32              
33             sub _init : Init {
34 0     0   0 my $self = shift;
35              
36 0 0       0 my $dom = $xml_of[$$self] or return;
37              
38 0         0 for my $f (@api_fields) {
39 0         0 my $method = "_set_$f";
40 0         0 $self->$method( $dom->findvalue("$f/text()") );
41             }
42              
43 0 0       0 if ( my ($project_xml) = $dom->findnodes('//project[1]') ) {
44 0         0 $project[$$self] = WWW::Ohloh::API::Project->new(
45             ohloh => $ohloh_of[$$self],
46             xml => $project_xml,
47             );
48             }
49              
50 0         0 return;
51 4     4   5864 }
  4         11  
  4         61  
52              
53             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54              
55             sub as_xml {
56 309     309 1 1597 my $self = shift;
57 309         807 my $xml;
58 309         1943 my $w = XML::Writer->new( OUTPUT => \$xml );
59              
60 309         72998 $w->startTag('stack_entry');
61              
62 309         23304 for my $f (@api_fields) {
63 1236         151795 $w->dataElement( $f => $self->$f );
64             }
65              
66 309 50       36439 if ( my $project = $project[$$self] ) {
67 0         0 $xml .= $project->as_xml;
68             }
69              
70 309         1115 $w->endTag;
71              
72 309         42439 return $xml;
73             }
74              
75             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76              
77             sub project {
78 309     309 1 1503337 my $self = shift;
79 309         786 my $retrieve = shift;
80 309 50       1250 $retrieve = 1 unless defined $retrieve;
81              
82 309 50       1049 if ($retrieve) {
83 0   0     0 $project[$$self] ||=
84             $ohloh_of[$$self]->get_project( $self->project_id );
85             }
86              
87 309         1324 return $project[$$self];
88             }
89              
90             'end of WWW::Ohloh::API::StackEntry';
91              
92             __END__