blib/lib/XMLRPC/Lite/UpdatePing.pm

filter: Statementstmt 83.9% 47 / 56 Branchbran 25.0% 4 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 72.0% 67 / 93 CC 13 SCAR 21.4
CC
13
Cov
69%
_as_string
22.9
_send_ping
6.9
ping
4.0
CRAP 8.5
↑ Summary
1 package XMLRPC::Lite::UpdatePing;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '0.06';
6  
7 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use XMLRPC::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 1 my $class = shift;
12 1 bless { ping_servers => [
13 'http://blogsearch.google.com/ping/RPC2',
14 'http://www.blogpeople.net/servlet/weblogUpdates',
15 'http://rpc.technorati.com/rpc/ping',
16 ], }, $class;
17 }
18  
19 3 ▶sub ping_servers {
Subroutine ping_servers: called CC=1 SCAR=0.0
Pod undocumented
20 3 my $self = shift;
21 3 return $self->{ping_servers};
22 }
23  
24 1 ▶sub add_ping_server {
Subroutine add_ping_server: called CC=1 SCAR=0.0
Pod documented
25 1 my $self = shift;
26 1 my $new_ping_server = shift;
27 1 push @{$self->{ping_servers}}, $new_ping_server;
28 1 return $self;
29 }
30  
31 1 ▶sub setup_ping_servers {
Subroutine setup_ping_servers: called CC=1 SCAR=0.0
Pod documented
32 1 my $self = shift;
33 1 $self->{ping_servers} = shift;
34 1 return $self;
35 }
36  
37 1 ▶sub ping {
Subroutine ping: called CC=4 SCAR=13.9
Pod documented
38 1 my $self = shift;
39 1 my $feed_uris = shift;
40 1 my ($all_res, $recent_res) = ('', '');
41 1 for my $feed_name ( keys %{$feed_uris} ) {
42 1 for my $ping_server_uri (@{$self->ping_servers}) {
43 $recent_res = &_send_ping(
44 rpc => $ping_server_uri,
45 site_name => encode('eucjp', $feed_name),
46 2 feed_uri => $$feed_uris{$feed_name},
47 );
48 2 ▶ $all_res .= &_as_string($recent_res) if defined $recent_res;
Branch: 1 branch
BranchTrueFalseTotal
if defined $recent_res 2 0 2
49 }
50 }
51 1 return $all_res;
52 }
53  
54 2 ▶sub _send_ping {
Subroutine _send_ping: called CC=5 SCAR=19.3
55 2 my %arg = @_;
56 2 my $rpc_uri = $arg{rpc};
57 2 my $site_name = $arg{site_name};
58 2 my $feed_uri = $arg{feed_uri};
59  
60 2 ▶ if ( ! defined $rpc_uri || $rpc_uri !~ m/^http/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rpc_uri and $rpc_uri =~ /^http/) 0 2 2
Condition33%1/3
defined $rpc_uri and $rpc_uri =~ /^http/
!ll&&!rl&&r
002
MC/DC0%0/2
defined $rpc_uri and $rpc_uri =~ /^http/
defined $rpc_uri $rpc_uri =~ /^http/
Truth table33%1/3
A and B
A= defined $rpc_uriB= $rpc_uri =~ /^http/
ABresult
0X0
100
111
61 0 return { flerror => 0,
62 message => 'local echo mode',
63 name => $site_name,
64 uri => $feed_uri, };
65 }
66  
67 2 my $result = eval {
68 2 XMLRPC::Lite->proxy($rpc_uri)
69 ->call( 'weblogUpdates.ping', $site_name, $feed_uri, )
70 ->result ;
71 };
72 2 ▶ return $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 2 0 2
73  
74 0 ▶ return (defined $result) ? $result : { 'flerror' => 'none', 'message' => 'none' };
Branch: 1 branch
BranchTrueFalseTotal
defined $result ? : 0 0 0
75 }
76  
77 2 ▶sub _as_string {
Subroutine _as_string: called CC=6 SCAR=31.3
78 2 my $input = shift;
79 2 ▶ if (not ref $input) {
Branch: 4 branches
BranchTrueFalseTotal
if (not ref $input) { } 2 0 2
elsif (ref $input eq 'SCALAR') { } 0 0 0
elsif (ref $input eq 'ARRAY') { } 0 0 0
elsif (ref $input eq 'HASH') { } 0 0 0
80 2 return $input;
81 } elsif (ref $input eq 'SCALAR') {
82 0 return $$input;
83 } elsif (ref $input eq 'ARRAY') {
84 0 return join("<br />\n", @$input);
85 } elsif (ref $input eq 'HASH') {
86 0 my $return = '';
87 0 for my $key (sort keys %$input) {
88 0 $return .= "$key => $input->{$key}<br />\n";
89 }
90 0 return $return;
91 } else {
92 0 return 'unknown data format';
93 }
94 }
95  
96 1 1;
97  
98 __END__
↑ Summary