line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Google::DataAPI::Role::Entry; |
2
|
1
|
|
|
1
|
|
95903
|
use Any::Moose '::Role'; |
|
1
|
|
|
|
|
37629
|
|
|
1
|
|
|
|
|
8
|
|
3
|
1
|
|
|
1
|
|
2459
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
95
|
|
4
|
1
|
|
|
1
|
|
884
|
use XML::Atom; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use XML::Atom::Entry; |
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has container => ( |
9
|
|
|
|
|
|
|
isa => 'Maybe[Net::Google::DataAPI::Role::Entry]', |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has service => ( |
14
|
|
|
|
|
|
|
does => 'Net::Google::DataAPI::Role::Service', |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
required => 1, |
17
|
|
|
|
|
|
|
lazy_build => 1, |
18
|
|
|
|
|
|
|
weak_ref => 1, |
19
|
|
|
|
|
|
|
handles => ['ns'], |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _build_service { shift->container->service }; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my %rel2label = ( |
25
|
|
|
|
|
|
|
edit => 'editurl', |
26
|
|
|
|
|
|
|
self => 'selfurl', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
for my $label (values %rel2label) { |
30
|
|
|
|
|
|
|
has $label => ( |
31
|
|
|
|
|
|
|
isa => 'Str', |
32
|
|
|
|
|
|
|
is => 'ro', |
33
|
|
|
|
|
|
|
lazy_build => 1, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__PACKAGE__->meta->add_method( |
37
|
|
|
|
|
|
|
"_build_$label" => sub { |
38
|
|
|
|
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
for my $link ($self->atom->link) { |
40
|
|
|
|
|
|
|
my $rel = $rel2label{$link->rel} or next; |
41
|
|
|
|
|
|
|
return $link->href if $rel eq $label; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has atom => ( |
48
|
|
|
|
|
|
|
isa => 'XML::Atom::Entry', |
49
|
|
|
|
|
|
|
is => 'rw', |
50
|
|
|
|
|
|
|
trigger => sub { |
51
|
|
|
|
|
|
|
my ($self, $arg) = @_; |
52
|
|
|
|
|
|
|
my $id = $self->atom->get($self->atom->ns, 'id'); |
53
|
|
|
|
|
|
|
croak "can't set different id!" if $self->id && $self->id ne $id; |
54
|
|
|
|
|
|
|
$self->from_atom; |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
handles => ['elem', 'author'], |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
has id => ( |
60
|
|
|
|
|
|
|
isa => 'Str', |
61
|
|
|
|
|
|
|
is => 'ro', |
62
|
|
|
|
|
|
|
lazy_build => 1, |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _build_id { |
66
|
|
|
|
|
|
|
my $self = shift; |
67
|
|
|
|
|
|
|
$self->atom->get($self->atom->ns, 'id') || ''; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
has title => ( |
71
|
|
|
|
|
|
|
isa => 'Str', |
72
|
|
|
|
|
|
|
is => 'rw', |
73
|
|
|
|
|
|
|
trigger => sub {$_[0]->update}, |
74
|
|
|
|
|
|
|
lazy_build => 1, |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _build_title { |
78
|
|
|
|
|
|
|
my $self = shift; |
79
|
|
|
|
|
|
|
$self->atom ? $self->atom->title : 'untitled'; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
has etag => ( |
83
|
|
|
|
|
|
|
isa => 'Str', |
84
|
|
|
|
|
|
|
is => 'rw', |
85
|
|
|
|
|
|
|
lazy_build => 1, |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _build_etag { |
89
|
|
|
|
|
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
$self->atom or return ''; |
91
|
|
|
|
|
|
|
$self->elem->getAttributeNS($self->ns('gd')->{uri}, 'etag'); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub from_atom { |
96
|
|
|
|
|
|
|
my ($self) = @_; |
97
|
|
|
|
|
|
|
for my $attr ($self->meta->get_all_attributes) { |
98
|
|
|
|
|
|
|
$attr->name eq 'service' and next; |
99
|
|
|
|
|
|
|
$attr->clear_value($self) if $attr->{lazy}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub to_atom { |
104
|
|
|
|
|
|
|
my ($self) = @_; |
105
|
|
|
|
|
|
|
my $entry = XML::Atom::Entry->new; |
106
|
|
|
|
|
|
|
$entry->title($self->title); |
107
|
|
|
|
|
|
|
return $entry; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub sync { |
111
|
|
|
|
|
|
|
my ($self) = @_; |
112
|
|
|
|
|
|
|
my $entry = $self->service->get_entry($self->selfurl); |
113
|
|
|
|
|
|
|
$self->atom($entry); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub update { |
117
|
|
|
|
|
|
|
my ($self) = @_; |
118
|
|
|
|
|
|
|
$self->etag or return; |
119
|
|
|
|
|
|
|
my $atom = $self->service->put( |
120
|
|
|
|
|
|
|
{ |
121
|
|
|
|
|
|
|
self => $self, |
122
|
|
|
|
|
|
|
entry => $self->to_atom, |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
$self->container->sync if $self->container; |
126
|
|
|
|
|
|
|
$self->atom($atom); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub delete { |
130
|
|
|
|
|
|
|
my $self = shift; |
131
|
|
|
|
|
|
|
my $res = $self->service->delete({self => $self}); |
132
|
|
|
|
|
|
|
$self->container->sync if $self->container; |
133
|
|
|
|
|
|
|
return $res->is_success; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
no Any::Moose '::Role'; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
__END__ |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=pod |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 NAME |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Net::Google::DataAPI::Role::Entry - represents entry of Google Data API |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 SYNOPSIS |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
package MyEntry; |
151
|
|
|
|
|
|
|
use Any::Moose; |
152
|
|
|
|
|
|
|
use Net::Google::DataAPI; |
153
|
|
|
|
|
|
|
with 'Net::Google::DataAPI::Role::Entry'; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
entry_has some_data => ( |
156
|
|
|
|
|
|
|
is => 'ro', |
157
|
|
|
|
|
|
|
isa => 'Str', |
158
|
|
|
|
|
|
|
tagname => 'somedata', |
159
|
|
|
|
|
|
|
ns => 'gd', |
160
|
|
|
|
|
|
|
); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 DESCRIPTION |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Net::Google::DataAPI::Role::Entry provides base functionalities for the entry of Google Data API. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Nobuo Danjou E<lt>danjou@soffritto.orgE<gt> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 SEE ALSO |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L<Net::Google::DataAPI> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 LICENSE |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
179
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|