StackExchange/Answers/Request.pm

filter: Statementstmt 86.1% 31 / 36 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 100% 1 / 1 totaltotal 75.4% 40 / 53 CC 3 SCAR 13.9
CC
3
Cov
76%
__ANON__
12.0
execute
1.0
BEGIN
1.0
CRAP 4.0
« StackExchange/Types.pm ↑ Summary StackExchange/Role/Request.pm »
1 package Net::StackExchange::Answers::Request;
2 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 $Net::StackExchange::Answers::Request::VERSION = '0.102740';
4 }
5  
6 # ABSTRACT: Request methods for 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 ▶use JSON qw{ decode_json };
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 with 'Net::StackExchange::Role::Request';
14  
15 4 has 'id' => (
16 is => 'ro',
17 isa => 'Str',
18 required => 1,
19 );
20  
21 4 has [
22 qw{
23 body
24 comments
25 }
26 ] => (
27 is => 'rw',
28 isa => 'Boolean',
29 coerce => 1,
30 );
31  
32 4 has [
33 qw{
34 fromdate
35 max
36 min
37 page
38 todate
39 }
40 ] => (
41 is => 'rw',
42 isa => 'Int',
43 );
44  
45 has 'pagesize' => (
46 is => 'rw',
47 isa => 'Int',
48 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
49 0 my ( $self, $pagesize ) = @_;
50  
51 0 ▶ if ( $pagesize < 1 || $pagesize > 100 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pagesize < 1 or $pagesize > 100) 0 0 0
Condition0%0/3
$pagesize < 1 or $pagesize > 100
l!l&&r!l&&!r
000
MC/DC0%0/2
$pagesize < 1 or $pagesize > 100
$pagesize < 1 $pagesize > 100
Truth table0%0/3
A or B
A= $pagesize < 1B= $pagesize > 100
ABresult
1X1
011
000
52 0 confess 'value should be between 1 and 100 inclusive';
53 }
54 },
55 4 );
56  
57 4 has 'order' => (
58 is => 'rw',
59 isa => enum( [ qw{ asc desc } ] ),
60 default => 'desc',
61 );
62  
63 4 has 'sort' => (
64 is => 'rw',
65 isa => enum( [ qw{ activity views creation votes } ] ),
66 default => 'activity',
67 );
68  
69 4 has '_NSE' => (
70 is => 'rw',
71 isa => 'Net::StackExchange',
72 required => 1,
73 );
74  
75 1 ▶sub execute {
Subroutine execute: called CC=1 SCAR=0.4
Pod documented
76 1 my $self = shift;
77 1 my $json = Net::StackExchange::Core::_execute($self);
78 1 my $se = $self->_NSE();
79 1 my $json_decoded = decode_json($json);
80  
81 my $response = Net::StackExchange::Answers::Response->new( {
82 '_NSE' => $se,
83 '_json_decoded' => $json_decoded,
84 'json' => $json,
85 'total' => $json_decoded->{'total' },
86 'page' => $json_decoded->{'page' },
87 0 'pagesize' => $json_decoded->{'pagesize'},
88 } );
89 0 return $response;
90 }
91  
92 1 ▶sub _get_request_attributes {
Subroutine _get_request_attributes: called CC=1 SCAR=0.0
93 1 return qw{
94 body
95 comments
96 fromdate
97 max
98 min
99 order
100 page
101 pagesize
102 sort
103 todate
104 };
105 }
106  
107 4 __PACKAGE__->meta()->make_immutable();
108  
109 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 4 ▶no Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 4 1;
113  
114  
115  
116 =pod
117  
118 =head1 NAME
119  
120 Net::StackExchange::Answers::Request - Request methods for answers
121  
122 =head1 VERSION
123  
124 version 0.102740
125  
126 =head1 SYNOPSIS
127  
128 use Net::StackExchange;
129  
130 my $se = Net::StackExchange->new( {
131 'network' => 'stackoverflow.com',
132 'version' => '1.0',
133 } );
134  
135 my $answers_route = $se->route('answers');
136 my $answers_request = $answers_route->prepare_request( { 'id' => 1036353 } );
137  
138 $answers_request->body(1);
139  
140 my $answers_response = $answers_request->execute();
141  
142 =head1 ATTRIBUTES
143  
144 =head2 C<id>
145  
146 A single primary key identifier or a vectorised, semicolon-delimited list of
147 identifiers.
148  
149 =head2 C<body>
150  
151 When true, a post's body will be included in the response.
152  
153 =head2 C<comments>
154  
155 When true, any comments on a post will be included in the response.
156  
157 =head2 C<fromdate>
158  
159 Unix timestamp of the minimum creation date on a returned item. Accepted range
160 is 0 to 253_402_300_799.
161  
162 =head2 C<max>
163  
164 Maximum of the range to include in the response according to the current C<sort>.
165  
166 =head2 C<min>
167  
168 Minimum of the range to include in the response according to the current C<sort>.
169  
170 =head2 C<order>
171  
172 How the current C<sort> should be ordered. Accepted values are C<desc> (default)
173 or C<asc>.
174  
175 =head2 C<page>
176  
177 The pagination offset for the current collection. Affected by the specified
178 C<pagesize>.
179  
180 =head2 C<pagesize>
181  
182 The number of collection results to display during pagination. Should be between
183 1 and 100 inclusive.
184  
185 =head2 C<sort>
186  
187 How a collection should be sorted. Valid values are one of C<activity> (default),
188 C<views>, C<creation>, or C<votes>.
189  
190 =head2 C<todate>
191  
192 Unix timestamp of the maximum creation date on a returned item. Accepted range
193 is 0 to 253_402_300_799.
194  
195 =head1 METHODS
196  
197 =head2 C<execute>
198  
199 Executes the request and returns a L<Net::StackExchange::Answers::Response>
200 object.
201  
202 =head1 CONSUMES ROLES
203  
204 L<Net::StackExchange::Roles::Request>
205  
206 =head1 AUTHOR
207  
208 Alan Haggai Alavi <alanhaggai@alanhaggai.org>
209  
210 =head1 COPYRIGHT AND LICENSE
211  
212 This software is copyright (c) 2010 by Alan Haggai Alavi.
213  
214 This is free software; you can redistribute it and/or modify it under
215 the same terms as the Perl 5 programming language system itself.
216  
217 =cut
218  
219  
220 __END__
« StackExchange/Types.pm ↑ Summary StackExchange/Role/Request.pm »