StackExchange.pm

filter: Statementstmt 97.7% 44 / 45 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 96.6% 58 / 60 CC 2 SCAR 1.5
CC
2
Cov
96%
__ANON__
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« StackExchange/Core.pm ↑ Summary StackExchange/Answers.pm »
1 package Net::StackExchange;
2 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 $Net::StackExchange::VERSION = '0.102740';
4 }
5  
6 # ABSTRACT: Access Stack Exchange API from Perl
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 Carp qw{ confess };
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use Net::StackExchange::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Net::StackExchange::Route;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Net::StackExchange::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Net::StackExchange::Owner;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Net::StackExchange::Answers;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use Net::StackExchange::Answers::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use Net::StackExchange::Answers::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 has 'network' => (
22 is => 'ro',
23 isa => enum( [
24 qw{
25 stackoverflow.com
26 serverfault.com
27 meta.stackoverflow.com
28 superuser.com
29 stackapps.com
30 webapps.stackexchange.com
31 gaming.stackexchange.com
32 webmasters.stackexchange.com
33 cooking.stackexchange.com
34 gamedev.stackexchange.com
35 gadgets.stackexchange.com
36 photo.stackexchange.com
37 stats.stackexchange.com
38 math.stackexchange.com
39 diy.stackexchange.com
40 gis.stackexchange.com
41 tex.stackexchange.com
42 ubuntu.stackexchange.com
43 money.stackexchange.com
44 english.stackexchange.com
45 ui.stackexchange.com
46 unix.stackexchange.com
47 wordpress.stackexchange.com
48 cstheory.stackexchange.com
49 apple.stackexchange.com
50 rpg.stackexchange.com
51 }
52 ] ),
53 required => 1,
54 );
55  
56 4 has 'version' => (
57 is => 'ro',
58 isa => 'Str',
59 required => 1,
60 default => '1.0',
61 );
62  
63 4 has 'route' => (
64 is => 'rw',
65 isa => 'Str',
66 );
67  
68 1 ▶around 'route' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.4
69 1 my ( $method, $self, $route ) = @_;
70  
71 # this is a workaround as enum() requires at least two values
72 1 ▶ if ( $route ne 'answers' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($route ne "answers") 0 1 1
73 0 confess q{'answers' is the only valid value'};
74 }
75  
76 1 $route = "\u$route";
77 1 return Net::StackExchange::Route->new( {
78 '_NSE' => $self,
79 '_route' => $route,
80 } );
81 4 };
82  
83 4 __PACKAGE__->meta()->make_immutable();
84 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 4 1;
87  
88  
89  
90 =pod
91  
92 =head1 NAME
93  
94 Net::StackExchange - Access Stack Exchange API from Perl
95  
96 =head1 VERSION
97  
98 version 0.102740
99  
100 =head1 SYNOPSIS
101  
102 use Net::StackExchange;
103  
104 my $se = Net::StackExchange->new( {
105 'network' => 'stackoverflow.com',
106 'version' => '1.0',
107 } );
108  
109 my $answers_route = $se->route('answers');
110 my $answers_request = $answers_route->prepare_request( { 'id' => '1036353' } );
111  
112 $answers_request->body(1);
113  
114 my $answers_response = $answers_request ->execute( );
115 my $answer = $answers_response->answers(0);
116  
117 print "__Answer__\n";
118 print "Title: ", $answer->title(), "\n";
119 print "Body: ", $answer->body (), "\n";
120  
121 =head1 ATTRIBUTES
122  
123 =head2 C<new>
124  
125 Accepts a hash reference with C<network> and C<version> as keys. Returns a
126 L<Net::StackExchange> object.
127  
128 =over 4
129  
130 =item * C<network>
131  
132 Sets the network to which API requests should be sent. Valid values are:
133  
134 stackoverflow.com
135 serverfault.com
136 meta.stackoverflow.com
137 superuser.com
138 stackapps.com
139 webapps.stackexchange.com
140 gaming.stackexchange.com
141 webmasters.stackexchange.com
142 cooking.stackexchange.com
143 gamedev.stackexchange.com
144 gadgets.stackexchange.com
145 photo.stackexchange.com
146 stats.stackexchange.com
147 math.stackexchange.com
148 diy.stackexchange.com
149 gis.stackexchange.com
150 tex.stackexchange.com
151 ubuntu.stackexchange.com
152 money.stackexchange.com
153 english.stackexchange.com
154 ui.stackexchange.com
155 unix.stackexchange.com
156 wordpress.stackexchange.com
157 cstheory.stackexchange.com
158 apple.stackexchange.com
159 rpg.stackexchange.com
160  
161 =item * C<version>
162  
163 Sets the API version. Defaults to C<1.0>.
164  
165 =back
166  
167 =head2 C<route>
168  
169 Returns a L<Net::StackExchange::Route> object depending on the route that is
170 passed to it. Valid routes are:
171  
172 answers
173  
174 =head1 !!! WARNING !!!
175  
176 Incomplete implementation. Interface may change.
177  
178 =head1 AUTHOR
179  
180 Alan Haggai Alavi <alanhaggai@alanhaggai.org>
181  
182 =head1 COPYRIGHT AND LICENSE
183  
184 This software is copyright (c) 2010 by Alan Haggai Alavi.
185  
186 This is free software; you can redistribute it and/or modify it under
187 the same terms as the Perl 5 programming language system itself.
188  
189 =cut
190  
191  
192 __END__
« StackExchange/Core.pm ↑ Summary StackExchange/Answers.pm »