line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Google::Blogger; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
53707
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
69
|
|
4
|
2
|
|
|
2
|
|
65
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
66
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1958
|
use Any::Moose; |
|
2
|
|
|
|
|
126174
|
|
|
2
|
|
|
|
|
15
|
|
7
|
2
|
|
|
2
|
|
4304
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
169306
|
|
|
2
|
|
|
|
|
239
|
|
8
|
2
|
|
|
2
|
|
2691
|
use HTTP::Request::Common; |
|
2
|
|
|
|
|
5581
|
|
|
2
|
|
|
|
|
190
|
|
9
|
2
|
|
|
2
|
|
2346
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Data::Dumper; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Net::Google::Blogger::Blog; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has login_id => ( is => 'ro', isa => 'Str', required => 1 ); |
18
|
|
|
|
|
|
|
has password => ( is => 'ro', isa => 'Str', required => 1 ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
builder => sub { LWP::UserAgent->new }, |
29
|
|
|
|
|
|
|
lazy_build => 1, |
30
|
|
|
|
|
|
|
is => 'ro', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub BUILD { |
37
|
|
|
|
|
|
|
## Authenticates with Blogger. |
38
|
|
|
|
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
unless ($response->is_success) { |
50
|
|
|
|
|
|
|
my $error_msg = ($response->content =~ /\bError=(.+)/)[0] || 'Google error message unavailable'; |
51
|
|
|
|
|
|
|
die 'HTTP error when trying to authenticate: ' . $response->status_line . " ($error_msg)"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my ($auth_token) = $response->content =~ /\bAuth=(.+)/ |
55
|
|
|
|
|
|
|
or die 'Authentication token not found in the response: ' . $response->content; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self->ua->default_header(Authorization => "GoogleLogin auth=$auth_token"); |
58
|
|
|
|
|
|
|
$self->ua->default_header(Content_Type => 'application/atom+xml'); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _build_blogs { |
63
|
|
|
|
|
|
|
## Populates 'blogs' property with list of instances of Net::Google::Blogger::Blog. |
64
|
|
|
|
|
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $response = $self->http_get('http://www.blogger.com/feeds/default/blogs'); |
67
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
@{ $response_tree->{entry} } |
75
|
|
|
|
|
|
|
]; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub http_put { |
80
|
|
|
|
|
|
|
## Executes a PUT request using configured user agent instance. |
81
|
|
|
|
|
|
|
my $self = shift; |
82
|
|
|
|
|
|
|
my ($url, $content) = @_; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $request = HTTP::Request->new(PUT => $url, $self->ua->default_headers, $content); |
85
|
|
|
|
|
|
|
return $self->ua->request($request); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub http_get { |
90
|
|
|
|
|
|
|
## Executes a GET request. |
91
|
|
|
|
|
|
|
my $self = shift; |
92
|
|
|
|
|
|
|
my @req_args = @_; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return $self->ua->get(@req_args); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub http_post { |
99
|
|
|
|
|
|
|
## Executes a POST request. |
100
|
|
|
|
|
|
|
my $self = shift; |
101
|
|
|
|
|
|
|
my @args = @_; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return $self->ua->request(HTTP::Request::Common::POST(@args)); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |