blib/lib/Net/Blogger/Engine/Base.pm

filter: Statementstmt 28.0% 30 / 107 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 44.4% 8 / 18 Podpod 100% 4 / 4 totaltotal 25.0% 42 / 168 SCAR 52.9
CC
19
Cov
21%
AUTOLOAD
72.0
_Client
56.0
new
6.0
CRAP 198.1
« blib/lib/Net/Blogger/Engine/Movabletype/mt.pm ↑ Summary blib/lib/Net/Blogger/Engine/Slash.pm »
1 {
2
3 1 =head1 NAME
4
5 Net::Blogger::Engine::Base - base class for Blogger API engines
6
7 =head1 SYNOPSIS
8
9 package Net::Blogger::Engine::SuperFly;
10
11 use vars qw ( @ISA );
12 @ISA = qw ( Net::Blogger::Engine::Base );
13 use Net::Blogger::Engine::Base;
14
15 sub new {
16 my $pkg = shift;
17
18 my $self = {};
19 bless $self,$pkg;
20
21 $self->SUPER::init(@_);
22 return $self;
23 }
24
25 =head1 DESCRIPTION
26
27 Base.pm is used a base class by implementation specific modules
28 for the Blogger API.
29
30 If an implementation follows the Blogger API to the letter then,
31 conceivably, all it's package would need to define is a constructor
32 and I<Proxy> method to define the
33 URI of it's XML-RPC server.
34
35 Base.pm inherits the functionality of Net::Blogger::Base::API and
36 Net::Blogger::Base::Ext and defines private methods used by each.
37
38 =cut
39
40 package Net::Blogger::Engine::Base;
41 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
42
43 1 ▶use vars qw ( $AUTOLOAD );
Subroutine BEGIN: called CC=1 SCAR=0.0
44
45 1 $Net::Blogger::Engine::Base::VERSION = '1.0';
46 1 @Net::Blogger::Engine::Base::ISA = qw ( Exporter Net::Blogger::API::Core Net::Blogger::API::Extended );
47 1 @Net::Blogger::Engine::Base::ISA::EXPORT = qw ();
48 1 @Net::Blogger::Engine::Base::ISA::EXPORT_OK = qw ();
49
50 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 ▶use Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
53
54 1 ▶use SOAP::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
55
56 1 ▶use Net::Blogger::API::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use Net::Blogger::API::Extended;
Subroutine BEGIN: called CC=1 SCAR=0.0
58
59 =head1 PACKAGE METHODS
60
61 =cut
62
63 =head2 __PACKAGE->new(\%args)
64
65 Instantiate a new Blogger object.
66
67 Valid arguments are :
68
69 =over 4
70
71 =item *
72
73 B<appkey>
74
75 String. The magic appkey for connecting to the Blogger XMLRPC server.
76
77 =item *
78
79 B<blogid>
80
81 String. The unique ID that Blogger uses for your weblog
82
83 =item *
84
85 B<username>
86
87 String. A valid username for blogid
88
89 =item *
90
91 B<password>
92
93 String. A valid password for the username/blogid pair.
94
95 =back
96
97 Releases prior to Net::Blogger 0.85 accepted a list of arguments
98 rather than a reference. Version 0.85+ are backwards compatible.
99
100 Returns an object. Woot!
101
102 =head2 __PACKAGE__->init
103
104 Initializes the option values
105
106 =cut
107
108 sub new {
109 0 ▶ my $pkg = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
110
111 0 my $self = {};
112 0 bless $self,$pkg;
113
114 0 ▶ $self->init(@_) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->init(@_) or return undef 0 0 0
115
116 0 return $self;
117 }
118
119 sub init {
120 0 ▶ my $self = shift;
Subroutine init: not called CC=2 SCAR=17.9
Pod documented
121 0 ▶ my $args = (ref($_[0]) eq "HASH") ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
122
123 0 $self->AppKey($args->{'appkey'});
124 0 $self->Username($args->{'username'});
125 0 $self->Password($args->{'password'});
126 0 $self->BlogId($args->{'blogid'});
127
128 0 $self->{'debug'} = $args->{'debug'};
129 0 $self->{"_posts"} = [];
130
131 # Note to self: this is what comments are for.
132 # It's late, I'm hungry, I don't want to have
133 # to remember what I was smoking when I wrote
134 # this...
135
136 0 (my $caller = (caller(2))[3]) =~ /(.*)[:]{2}([^:]{1,})[:]{2}([^:]{1,})$/;
137
138 0 $self->{'__parent'} = $2;
139 0 return 1;
140 }
141
142 =head1 OBJECT METHODS
143
144 There are no public methods. See I<Net::Blogger::Base::API> and
145 I<Net::Blogger::Base::Ext>.
146
147 =cut
148
149 =head1 PRIVATE METHODS
150
151 =cut
152
153 =head2 $pkg->Proxy()
154
155 Get/set the URI of the Blogger API server.
156
157 =head2 $pkg->AppKey($key)
158
159 Get/set the magic appkey
160
161 =head2 $pkg->BlogId($id)
162
163 Get/set the blogid
164
165 =head2 $pkg->Username($username)
166
167 Get/set the username
168
169 =head2 $pkg->Password($password)
170
171 Get/set the password
172
173 =head2 $pkg->MaxPostLength()
174
175 Return the maximum number of characters a single post may contain.
176
177 =cut
178
179 =head2 $pkg->LastError($e)
180
181 Fetch the last recorded error message.
182
183 Returns a string.
184
185 =cut
186
187 sub LastError {
188 0 ▶ my $self = shift;
Subroutine LastError: not called CC=2 SCAR=17.9
Pod documented
189 0 my $e = shift;
190
191 0 ▶ if ($e) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e) 0 0 0
192 0 Error::Simple->record($e);
193 0 return 1;
194 }
195
196 0 $e = Error->prior();
197 0 chomp $e;
198
199 0 return $e;
200 }
201
202 =head2 $pkg->Transport
203
204 Just returns XMLRPC by default
205
206 =cut
207
208 sub Transport {
209 0 ▶ return "XMLRPC";
Subroutine Transport: not called CC=1 SCAR=6.9
Pod documented
210 }
211
212 sub _Client {
213 0 ▶ my $self = shift;
Subroutine _Client: not called CC=7 SCAR=40.3
214
215 0 ▶ unless (ref($self->{"_client"}) =~ /^(XMLRPC|SOAP)::Lite$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref($self->{"_client"}) =~ /^(XMLRPC|SOAP)::Lite$/) 0 0 0
216
217 0 my $pkg = uc $self->Transport();
218
219 0 ▶ if ($pkg =~ /^(XMLRPC|SOAP)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg =~ /^(XMLRPC|SOAP)$/) { } 0 0 0
220 0 $pkg = join("::",$pkg,"Lite");
221 }
222
223 else {
224 0 die "Unknown transport : '$pkg'\n";
225 0 $self->LastError("Unknown transport : $pkg");
226 0 return undef;
227 }
228
229 0 eval "require $pkg";
230
231 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
232 0 die "Failed to eval, $@\n";
233 }
234 0 ▶ my $client = $pkg->new()
Condition0%0/3
$pkg->new || 'Error'->throw('-text', $!)
l!l&&r!l&&!r
000
MC/DC0%0/2
$pkg->new || 'Error'->throw('-text', $!)
$pkg->new 'Error'->throw('-text', $!)
Truth table0%0/3
A || B
A= $pkg->newB= 'Error'->throw('-text', $!)
ABresult
1X1
011
000
235 || Error->throw(-text=>$!);
236
237 0 $client->on_fault(\&_ClientFault);
238
239 # Obey $http_proxy, if set.
240
241 0 ▶ if (defined($ENV{http_proxy})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{'http_proxy'}) { } 0 0 0
242 0 $client->proxy($self->Proxy, proxy => ['http' => $ENV{http_proxy} ]);
243 } else {
244 0 $client->proxy($self->Proxy);
245 }
246
247 0 $client->uri($self->Uri());
248
249 # Fix this.
250 0 ▶ if ($self->{'debug'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
251 0 ▶ $client->on_debug(sub { print @_; });
Subroutine __ANON__: not called CC=1 SCAR=6.9
252 }
253
254 0 $self->{"_client"} = $client;
255 }
256
257 0 return $self->{"_client"};
258 }
259
260 sub _ClientFault {
261 0 ▶ my $client = shift;
Subroutine _ClientFault: not called CC=2 SCAR=17.9
262 0 my $res = shift;
263 0 ▶ Error::Simple->record(join("\n",
Branch: 1 branch
BranchTrueFalseTotal
ref $res ? : 0 0 0
264 "Fatal client error.",
265 ((ref $res) ? $res->faultstring() : $client->transport->status()))
266 );
267 0 return 0;
268 }
269
270 sub _Type {
271 0 ▶ my $self = shift;
Subroutine _Type: not called CC=2 SCAR=17.9
272 0 my $name = shift;
273
274 0 ▶ if ($name =~ /^(hash|array)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^(hash|array)$/) 0 0 0
275 0 return SOAP::Data->name(args=>@_);
276 }
277
278 0 return SOAP::Data->type($name,@_);
279 }
280
281 sub DESTROY {
282 0 ▶ return 1;
Subroutine DESTROY: not called CC=1 SCAR=6.9
283 }
284
285 sub AUTOLOAD {
286 0 ▶ my $self = shift;
Subroutine AUTOLOAD: not called CC=8 SCAR=42.8
287 0 $AUTOLOAD =~ s/.*:://;
288
289 0 ▶ if ($AUTOLOAD eq "Publish") {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Blogger::Engine::Base::AUTOLOAD eq "Publish") 0 0 0
290 0 $self->LastError("This method has been deprecated.");
291 0 return undef;
292 }
293
294 0 ▶ unless ($AUTOLOAD =~ /^(Proxy|Uri|AppKey|BlogId|Username|Password)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Net::Blogger::Engine::Base::AUTOLOAD =~ /^(Proxy|Uri|AppKey|BlogId|Username|Password)$/) 0 0 0
295 0 $self->LastError("Unknown method '$AUTOLOAD' called. Skipping.");
296 0 return undef;
297 }
298
299 0 my $property = lc "_".$AUTOLOAD;
300
301 0 ▶ if (my $arg = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift()) 0 0 0
302 0 $self->{ $property } = $arg;
303
304 0 ▶ if ($AUTOLOAD eq "Proxy") {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Blogger::Engine::Base::AUTOLOAD eq "Proxy") 0 0 0
305 0 $self->{"_client"} = undef;
306 }
307
308 #
309
310 0 ▶ if (exists $self->{'__meta'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"__meta"}) 0 0 0
311 0 $self->{'__meta'}->$property($arg);
312 }
313
314 0 ▶ if (exists $self->{'__mt'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"__mt"}) 0 0 0
315 0 $self->{'__mt'}->$property($arg);
316 }
317
318 0 ▶ if (exists $self->{'__slash'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"__slash"}) 0 0 0
319 0 $self->{'__slash'}->$property($arg);
320 }
321
322 }
323
324 0 return $self->{ $property };
325 }
326
327 =head1 VERSION
328
329 1.0
330
331 =head1 DATE
332
333 $Date: 2005/03/26 19:29:08 $
334
335 =head1 AUTHOR
336
337 Aaron Straup Cope
338
339 =head1 SEE ALSO
340
341 L<Net::Blogger::API::Core>
342
343 L<Net::Blogger::API::Extended>
344
345 L<SOAP::Lite>
346
347 =head1 LICENSE
348
349 Copyright (c) 2001-2005 Aaron Straup Cope.
350
351 This is free software, you may use it and distribute it under the same terms as Perl itself.
352
353 =cut
354
355 1 return 1;
356
357 }
« blib/lib/Net/Blogger/Engine/Movabletype/mt.pm ↑ Summary blib/lib/Net/Blogger/Engine/Slash.pm »