StackExchange/Answers/Response.pm

filter: Statementstmt 43.4% 20 / 46 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 100% 1 / 1 totaltotal 40.0% 26 / 65 CC 7 SCAR 29.6
CC
7
Cov
36%
_populate_answers_object
42.0
answers
6.0
__ANON__
2.0
CRAP 19.4
↑ Summary StackExchange/Types.pm »
1 package Net::StackExchange::Answers::Response;
2 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 $Net::StackExchange::Answers::Response::VERSION = '0.102740';
4 }
5  
6 # ABSTRACT: Accessors for a set of answers
7  
8 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 with 'Net::StackExchange::Role::Response';
12  
13 4 has 'json' => (
14 is => 'ro',
15 isa => 'Str',
16 required => 1,
17 );
18  
19 4 has 'answers' => (
20 is => 'ro',
21 isa => 'ArrayRef[Net::StackExchange::Answers]',
22 writer => 'set_answers',
23 reader => 'get_answers',
24 );
25  
26 has '_json_decoded' => (
27 is => 'ro',
28 isa => 'HashRef',
29 required => 1,
30 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 my $self = shift;
32  
33 0 _populate_answers_object($self);
34 },
35 4 );
36  
37 4 has '_NSE' => (
38 is => 'rw',
39 isa => 'Net::StackExchange',
40 required => 1,
41 );
42  
43 0 ▶sub _populate_answers_object {
Subroutine _populate_answers_object: not called CC=6 SCAR=37.4
44 0 my $self = shift;
45 0 my $json = $self->json();
46  
47 0 my $json_decoded = $self->_json_decoded();
48  
49 0 my @answers;
50 0 for my $answer_ref ( @{ $json_decoded->{'answers'} } ) {
51 0 my $owner_ref = $answer_ref->{'owner'};
52  
53 my $user = Net::StackExchange::Owner->new(
54 'user_id' => $owner_ref->{'user_id' },
55 'user_type' => $owner_ref->{'user_type' },
56 'display_name' => $owner_ref->{'display_name'},
57 'reputation' => $owner_ref->{'reputation' },
58 0 'email_hash' => $owner_ref->{'email_hash' },
59 );
60  
61 0 my $locked_date = $answer_ref->{'locked_date' };
62 0 my $last_edit_date = $answer_ref->{'last_edit_date' };
63 0 my $body = $answer_ref->{'body' };
64 0 my $last_activity_date = $answer_ref->{'last_activity_date'};
65  
66 0 ▶ $locked_date = defined $locked_date ? $locked_date : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $locked_date ? : 0 0 0
67 0 ▶ $last_edit_date = defined $last_edit_date ? $last_edit_date : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $last_edit_date ? : 0 0 0
68 0 ▶ $body = defined $body ? $body : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $body ? : 0 0 0
69 0 ▶ $last_activity_date = defined $last_activity_date ?
Branch: 1 branch
BranchTrueFalseTotal
defined $last_activity_date ? : 0 0 0
70 $last_activity_date : 0;
71  
72 my $answers = Net::StackExchange::Answers->new( {
73 '_NSE' => $self->_NSE(),
74 'answer_id' => $answer_ref->{'answer_id' },
75 'accepted' => $answer_ref->{'accepted' },
76 'answer_comments_url' => $answer_ref->{'answer_comments_url'},
77 'question_id' => $answer_ref->{'question_id' },
78 'locked_date' => $locked_date,
79 'owner' => $user,
80 'creation_date' => $answer_ref->{'creation_date' },
81 'last_edit_date' => $last_edit_date,
82 'last_activity_date' => $last_activity_date,
83 'up_vote_count' => $answer_ref->{'up_vote_count' },
84 'down_vote_count' => $answer_ref->{'down_vote_count' },
85 'view_count' => $answer_ref->{'view_count' },
86 'score' => $answer_ref->{'score' },
87 'community_owned' => $answer_ref->{'community_owned' },
88 0 'title' => $answer_ref->{'title' },
89 'body' => $body,
90 } );
91  
92 0 push @answers, $answers;
93 }
94 0 $self->set_answers( \@answers );
95 }
96  
97 0 ▶sub answers {
Subroutine answers: not called CC=2 SCAR=17.9
Pod documented
98 0 my ( $self, $nth ) = @_;
99 0 my $answers = $self->get_answers();
100  
101 0 ▶ if ( defined $nth ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nth) { } 0 0 0
102 0 return $answers->[$nth];
103 }
104 else {
105 0 return $answers;
106 }
107 }
108  
109 4 __PACKAGE__->meta()->make_immutable();
110  
111 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 4 ▶no Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
113  
114 4 1;
115  
116  
117  
118 =pod
119  
120 =head1 NAME
121  
122 Net::StackExchange::Answers::Response - Accessors for a set of answers
123  
124 =head1 VERSION
125  
126 version 0.102740
127  
128 =head1 SYNOPSIS
129  
130 use Net::StackExchange;
131  
132 my $se = Net::StackExchange->new( {
133 'network' => 'stackoverflow.com',
134 'version' => '1.0',
135 } );
136  
137 my $answers_route = $se->route('answers');
138 my $answers_request = $answers_route->prepare_request( { 'id' => '1036353' } );
139  
140 my $answers_response = $answers_request->execute( );
141 print "Total: ", $answers_response->total (), "\n";
142 print "Page: ", $answers_response->page (), "\n";
143 print "Page size: ", $answers_response->pagesize(), "\n";
144  
145 =head1 ATTRIBUTES
146  
147 =head2 C<json>
148  
149 Returns JSON returned by the StackExchange API.
150  
151 =head1 METHODS
152  
153 =head2 C<answers>
154  
155 Returns a list of L<Net::StackExchange::Answers> objects.
156  
157 =head1 CONSUMES ROLES
158  
159 L<Net::StackExchange::Role::Response>
160  
161 =head1 AUTHOR
162  
163 Alan Haggai Alavi <alanhaggai@alanhaggai.org>
164  
165 =head1 COPYRIGHT AND LICENSE
166  
167 This software is copyright (c) 2010 by Alan Haggai Alavi.
168  
169 This is free software; you can redistribute it and/or modify it under
170 the same terms as the Perl 5 programming language system itself.
171  
172 =cut
173  
174  
175 __END__
↑ Summary StackExchange/Types.pm »