Blogger.pm

filter: Statementstmt 55.5% 30 / 54 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 57.1% 8 / 14 Podpod 25.0% 1 / 4 totaltotal 49.3% 39 / 79 CC 4 SCAR 17.5
CC
4
Cov
50%
BUILD
20.0
__ANON__
2.0
_build_blogs
2.0
CRAP 5.8
« Blogger/Blog/Entry.pm ↑ Summary
1 package Net::Google::Blogger;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Net::Google::Blogger::Blog;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 2 our $VERSION = '0.09';
16  
17 2 has login_id => ( is => 'ro', isa => 'Str', required => 1 );
18 2 has password => ( is => 'ro', isa => 'Str', required => 1 );
19  
20 2 has blogs => (
21 is => 'ro',
22 isa => 'ArrayRef[Net::Google::Blogger::Blog]',
23 lazy_build => 1,
24 auto_deref => 1,
25 );
26  
27 has ua => (
28 0 ▶ builder => sub { LWP::UserAgent->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 2 lazy_build => 1,
30 is => 'ro',
31 );
32  
33 2 __PACKAGE__->meta->make_immutable;
34  
35  
36 0 ▶sub BUILD {
Subroutine BUILD: not called CC=4 SCAR=30.0
Pod documented
37 ## Authenticates with Blogger.
38 0 my $self = shift;
39  
40 0 my $response = $self->ua->post(
41 'https://www.google.co.uk/accounts/ClientLogin',
42 {
43 Email => $self->login_id,
44 Passwd => $self->password,
45 service => 'blogger',
46 }
47 );
48  
49 0 ▶ unless ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
50 0 ▶ my $error_msg = ($response->content =~ /\bError=(.+)/)[0] || 'Google error message unavailable';
Condition0%0/2
($response->content =~ /\bError=(.+)/)[0] || 'Google error message unavailable'
l!l
00
MC/DC0%0/1
($response->content =~ /\bError=(.+)/)[0] || 'Google error message unavailable'
($response->content =~ /\bError=(.+)/)[0]
Truth table0%0/2
A
A= ($response->content =~ /\bError=(.+)/)[0]
Aresult
11
00
51 0 die 'HTTP error when trying to authenticate: ' . $response->status_line . " ($error_msg)";
52 }
53  
54 0 ▶ my ($auth_token) = $response->content =~ /\bAuth=(.+)/
Branch: 1 branch
BranchTrueFalseTotal
my($auth_token) = $response->content =~ /\bAuth=(.+)/ or die 'Authentication token not found in the response: ' . $response->content 0 0 0
55 or die 'Authentication token not found in the response: ' . $response->content;
56  
57 0 $self->ua->default_header(Authorization => "GoogleLogin auth=$auth_token");
58 0 $self->ua->default_header(Content_Type => 'application/atom+xml');
59 }
60  
61  
62 0 ▶sub _build_blogs {
Subroutine _build_blogs: not called CC=1 SCAR=6.9
63 ## Populates 'blogs' property with list of instances of Net::Google::Blogger::Blog.
64 0 my $self = shift;
65  
66 0 my $response = $self->http_get('http://www.blogger.com/feeds/default/blogs');
67 0 my $response_tree = XML::Simple::XMLin($response->content, ForceArray => 1);
68  
69 return [
70 map Net::Google::Blogger::Blog->new(
71 source_xml_tree => $_,
72 blogger => $self,
73 ),
74 0 @{ $response_tree->{entry} }
75 ];
76 }
77  
78  
79 0 ▶sub http_put {
Subroutine http_put: not called CC=1 SCAR=6.9
Pod undocumented
80 ## Executes a PUT request using configured user agent instance.
81 0 my $self = shift;
82 0 my ($url, $content) = @_;
83  
84 0 my $request = HTTP::Request->new(PUT => $url, $self->ua->default_headers, $content);
85 0 return $self->ua->request($request);
86 }
87  
88  
89 0 ▶sub http_get {
Subroutine http_get: not called CC=1 SCAR=6.9
Pod undocumented
90 ## Executes a GET request.
91 0 my $self = shift;
92 0 my @req_args = @_;
93  
94 0 return $self->ua->get(@req_args);
95 }
96  
97  
98 0 ▶sub http_post {
Subroutine http_post: not called CC=1 SCAR=6.9
Pod undocumented
99 ## Executes a POST request.
100 0 my $self = shift;
101 0 my @args = @_;
102  
103 0 return $self->ua->request(HTTP::Request::Common::POST(@args));
104 }
105  
106  
107 __END__
« Blogger/Blog/Entry.pm ↑ Summary