| 1 | package Net::Google::DataAPI::Role::Entry; | ||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use Any::Moose '::Role'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use XML::Atom; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use XML::Atom::Entry; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 9 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 9 | has container => ( | |||||||||||||||||||||||||||
| 9 | isa => 'Maybe[Net::Google::DataAPI::Role::Entry]', | ||||||||||||||||||||||||||||
| 10 | is => 'ro', | ||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 9 | 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 | 1 | ▶ | sub _build_service { shift->container->service }; | ||||||||||||||||||||||||||
|
Subroutine
_build_service: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 9 | my %rel2label = ( | |||||||||||||||||||||||||||
| 25 | edit => 'editurl', | ||||||||||||||||||||||||||||
| 26 | self => 'selfurl', | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 9 | for my $label (values %rel2label) { | |||||||||||||||||||||||||||
| 30 | 18 | has $label => ( | |||||||||||||||||||||||||||
| 31 | isa => 'Str', | ||||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||
| 33 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | __PACKAGE__->meta->add_method( | ||||||||||||||||||||||||||||
| 37 | "_build_$label" => sub { | ||||||||||||||||||||||||||||
| 38 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_selfurl: called CC=4 SCAR=13.9
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 39 | 9 | for my $link ($self->atom->link) { | |||||||||||||||||||||||||||
| 40 | 10 | ▶ | my $rel = $rel2label{$link->rel} or next; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 41 | 10 | ▶ | return $link->href if $rel eq $label; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 18 | ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | has atom => ( | ||||||||||||||||||||||||||||
| 48 | isa => 'XML::Atom::Entry', | ||||||||||||||||||||||||||||
| 49 | is => 'rw', | ||||||||||||||||||||||||||||
| 50 | trigger => sub { | ||||||||||||||||||||||||||||
| 51 | 37 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 52 | 37 | my $id = $self->atom->get($self->atom->ns, 'id'); | |||||||||||||||||||||||||||
| 53 | 37 | ▶ | croak "can't set different id!" if $self->id && $self->id ne $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->id and $self->id ne $id
MC/DC0%0/2
$self->id and $self->id ne $id
$self->id
$self->id ne $id
Truth table66%2/3
A and B
A= $self->idB= $self->id ne $id
| |||||||||||||||||||||||||||||
| 54 | 37 | $self->from_atom; | |||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||
| 56 | 9 | handles => ['elem', 'author'], | |||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 9 | has id => ( | |||||||||||||||||||||||||||
| 60 | isa => 'Str', | ||||||||||||||||||||||||||||
| 61 | is => 'ro', | ||||||||||||||||||||||||||||
| 62 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub _build_id { | ||||||||||||||||||||||||||||
| 66 | 38 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_id: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 67 | 38 | ▶ | $self->atom->get($self->atom->ns, 'id') || ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | has title => ( | ||||||||||||||||||||||||||||
| 71 | isa => 'Str', | ||||||||||||||||||||||||||||
| 72 | is => 'rw', | ||||||||||||||||||||||||||||
| 73 | 5 | ▶ | trigger => sub {$_[0]->update}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 74 | 9 | lazy_build => 1, | |||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub _build_title { | ||||||||||||||||||||||||||||
| 78 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_title: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 79 | 17 | ▶ | $self->atom ? $self->atom->title : 'untitled'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 9 | has etag => ( | |||||||||||||||||||||||||||
| 83 | isa => 'Str', | ||||||||||||||||||||||||||||
| 84 | is => 'rw', | ||||||||||||||||||||||||||||
| 85 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | sub _build_etag { | ||||||||||||||||||||||||||||
| 89 | 25 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_etag: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 90 | 25 | ▶ | $self->atom or return ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 19 | $self->elem->getAttributeNS($self->ns('gd')->{uri}, 'etag'); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub from_atom { | ||||||||||||||||||||||||||||
| 96 | 37 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
from_atom: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 97 | 37 | for my $attr ($self->meta->get_all_attributes) { | |||||||||||||||||||||||||||
| 98 | 406 | ▶ | $attr->name eq 'service' and next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 369 | ▶ | $attr->clear_value($self) if $attr->{lazy}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub to_atom { | ||||||||||||||||||||||||||||
| 104 | 20 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
to_atom: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 105 | 20 | my $entry = XML::Atom::Entry->new; | |||||||||||||||||||||||||||
| 106 | 20 | $entry->title($self->title); | |||||||||||||||||||||||||||
| 107 | 20 | return $entry; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub sync { | ||||||||||||||||||||||||||||
| 111 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
sync: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 112 | 5 | my $entry = $self->service->get_entry($self->selfurl); | |||||||||||||||||||||||||||
| 113 | 5 | $self->atom($entry); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | sub update { | ||||||||||||||||||||||||||||
| 117 | 14 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
update: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | 14 | ▶ | $self->etag or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 7 | my $atom = $self->service->put( | |||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||
| 121 | self => $self, | ||||||||||||||||||||||||||||
| 122 | entry => $self->to_atom, | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||
| 125 | 7 | ▶ | $self->container->sync if $self->container; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 7 | $self->atom($atom); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | sub delete { | ||||||||||||||||||||||||||||
| 130 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 131 | 3 | my $res = $self->service->delete({self => $self}); | |||||||||||||||||||||||||||
| 132 | 2 | ▶ | $self->container->sync if $self->container; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 2 | return $res->is_success; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 9 | ▶ | no Any::Moose '::Role'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 9 | 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 | |||||||||||||||||||||||||||||