| 1 | package WebService::Bloglines::Blogroll; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use fields qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | user_name | ||||||||||||||||||||||||||||
| 9 | folder | ||||||||||||||||||||||||||||
| 10 | url | ||||||||||||||||||||||||||||
| 11 | uri | ||||||||||||||||||||||||||||
| 12 | html | ||||||||||||||||||||||||||||
| 13 | blogroll_hash | ||||||||||||||||||||||||||||
| 14 | blogroll_html | ||||||||||||||||||||||||||||
| 15 | page | ||||||||||||||||||||||||||||
| 16 | http_proxy | ||||||||||||||||||||||||||||
| 17 | ftp_proxy | ||||||||||||||||||||||||||||
| 18 | 1 | ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use vars qw($VERSION %FIELDS $AUTOLOAD); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use LWP::Simple qw($ua get); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | my $_def_values = { | ||||||||||||||||||||||||||||
| 33 | url => 'rpc.bloglines.com', | ||||||||||||||||||||||||||||
| 34 | uri => 'blogroll', | ||||||||||||||||||||||||||||
| 35 | html => 1, | ||||||||||||||||||||||||||||
| 36 | http_proxy => $ENV{http_proxy}, | ||||||||||||||||||||||||||||
| 37 | ftp_proxy => $ENV{ftp_proxy}, | ||||||||||||||||||||||||||||
| 38 | 1 | }; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub _get_defaults { %$_def_values } | ||||||||||||||||||||||||||
|
Subroutine
_get_defaults: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 45 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 46 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 47 | 1 | $self->_init(@_); | |||||||||||||||||||||||||||
| 48 | 1 | return $self; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 52 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 53 | 1 | my %pars = @_; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | my %_defaults = $self->_get_defaults; | |||||||||||||||||||||||||||
| 56 | 1 | for(keys %FIELDS) { | |||||||||||||||||||||||||||
| 57 | 10 | ▶ | $self->{$_} = exists $pars{$_} ? $pars{$_} : $_defaults{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | ▶ | sub retrieve_blogroll { | ||||||||||||||||||||||||||
|
Subroutine
retrieve_blogroll: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | $ua->proxy('http', $self->http_proxy); | |||||||||||||||||||||||||||
| 66 | 1 | $ua->proxy('ftp', $self->ftp_proxy); | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | $self->page(get($self->_get_url)); | |||||||||||||||||||||||||||
| 69 | 0 | $self->_parse_blogroll(); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub get_blogroll_as_html { | ||||||||||||||||||||||||||
|
Subroutine
get_blogroll_as_html: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my $blogroll_hash = $self->blogroll_hash; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my $blogroll_html; | |||||||||||||||||||||||||||
| 78 | 0 | for(keys %{$blogroll_hash}) { | |||||||||||||||||||||||||||
| 79 | 0 | $blogroll_html .= "<h2>$_</h2>\n"; | |||||||||||||||||||||||||||
| 80 | 0 | $blogroll_html .= "<ul>\n"; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | for my $item (@{$blogroll_hash->{$_}}) { | |||||||||||||||||||||||||||
| 83 | $blogroll_html .= "<li><a href='$item->{item_url}'>$item->{item_title}</a></li>\n" | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if $item->{item_url} && $item->{item_title}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$item->{"item_url"} and $item->{"item_title"}
MC/DC0%0/2
$item->{"item_url"} and $item->{"item_title"}
$item->{"item_url"}
$item->{"item_title"}
Truth table0%0/3
A and B
A= $item->{"item_url"}B= $item->{"item_title"}
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | $blogroll_html .= '</ul>' | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | $self->blogroll_html($blogroll_html); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | sub page { | ||||||||||||||||||||||||||
|
Subroutine
page: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 95 | 1 | ▶ | if(@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 1 | my $page = shift; | |||||||||||||||||||||||||||
| 97 | 1 | ▶ | if(!$page) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 98 | 1 | croak "Cannot retireve a blogroll: \n\tproxy url is | |||||||||||||||||||||||||||
| 99 | [$ENV{http_proxy}]\n\turl is [".$self->get_url."]"; | ||||||||||||||||||||||||||||
| 100 | } elsif($page =~ /The user name you are using to access this blogroll is incorrect/i) { | ||||||||||||||||||||||||||||
| 101 | 0 | croak "User name [".$self->user_name."] is not correct!"; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | $self->{page} = $page; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | return $self->{page}; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub _parse_blogroll { | ||||||||||||||||||||||||||
|
Subroutine
_parse_blogroll: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | my($folder, $item_title, $item_url, %list); | |||||||||||||||||||||||||||
| 114 | 0 | for(split/\n/, $self->page) { | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | if(/blogrollfolder/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 116 | 0 | ($folder) = m#(?:.+)>(.+?)<#; | |||||||||||||||||||||||||||
| 117 | } elsif(/blogrollitem/) { | ||||||||||||||||||||||||||||
| 118 | 0 | ($item_url, $item_title) = m#href="(.+?)">(.+?)<#; | |||||||||||||||||||||||||||
| 119 | 0 | push @{ $list{$folder} }, {item_title => $item_title, item_url => $item_url}; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | $self->blogroll_hash(\%list); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1 | ▶ | sub _get_url { | ||||||||||||||||||||||||||
|
Subroutine
_get_url: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 127 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 1 | ▶ | croak "User name is not specified!" unless $self->user_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 1 | my $url = 'http://'.$self->url.'/'.$self->uri.'?id='.$self->user_name; | |||||||||||||||||||||||||||
| 132 | 1 | ▶ | $url .= '&folder='.$self->folder if $self->folder; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 1 | $url .= '&html='.$self->html; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 1 | return $url; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub get_blogroll_hash { | ||||||||||||||||||||||||||
|
Subroutine
get_blogroll_hash: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 140 | 0 | my $folder = shift; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | return $self->{blogroll_hash}{$folder} if $self->{blogroll_hash} && $folder; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"blogroll_hash"} and $folder
MC/DC0%0/2
$self->{"blogroll_hash"} and $folder
$self->{"blogroll_hash"}
$folder
Truth table0%0/3
A and B
A= $self->{"blogroll_hash"}B= $folder
| |||||||||||||||||||||||||||||
| 143 | return $self->{blogroll_hash} | ||||||||||||||||||||||||||||
| 144 | 0 | } | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub get_list_folders { | ||||||||||||||||||||||||||
|
Subroutine
get_list_folders: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 148 | 0 | ▶ | if($self->{blogroll_hash}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 0 | return [ keys %{ $self->{blogroll_hash} } ] | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 9 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 154 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 155 | 9 | my($class, $attr) = $AUTOLOAD =~ /(.+)::(.+)/; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 9 | ▶ | if(exists $FIELDS{$attr}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 8 | ▶ | $self->{$attr} = shift() if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 8 | return $self->{$attr}; | |||||||||||||||||||||||||||
| 160 | } else { | ||||||||||||||||||||||||||||
| 161 | 1 | croak "Method [$attr] is not found in the class [$class]!"; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 1 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 166 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 1 | 1; | |||||||||||||||||||||||||||
| 170 | __END__ | ||||||||||||||||||||||||||||