| 1 | package Net::Google::DocumentsList::ACL; | ||
| 2 | use Any::Moose; | ||
| 3 | use Net::Google::DataAPI; | ||
| 4 | use XML::Atom::Util qw(first create_element); | ||
| 5 | use Net::Google::DocumentsList::Types; | ||
| 6 | with 'Net::Google::DocumentsList::Role::EntryWithoutEtag'; | ||
| 7 | |||
| 8 | entry_has 'updated' => ( tagname => 'updated', is => 'ro' ); | ||
| 9 | entry_has 'role' => ( | ||
| 10 | is => 'rw', | ||
| 11 | from_atom => sub { | ||
| 12 | my ($self, $atom) = @_; | ||
| 13 | first($atom->elem, $self->ns('gAcl')->{uri}, 'role')->getAttribute('value'); | ||
| 14 | }, | ||
| 15 | to_atom => sub { | ||
| 16 | my ($self, $atom) = @_; | ||
| 17 | if (my $key = $self->withKey) { | ||
| 18 | my $role = create_element($self->ns('gAcl')->{uri}, 'role'); | ||
| 19 | $role->setAttribute(value => $self->role); | ||
| 20 | my $withKey = create_element($self->ns('gAcl')->{uri}, 'withKey'); | ||
| 21 | $withKey->setAttribute(key => $key); | ||
| 22 | $withKey->appendChild($role); | ||
| 23 | $atom->set($self->ns('gAcl')->{uri}, 'withKey', $withKey); | ||
| 24 | } else { | ||
| 25 | $atom->set($self->ns('gAcl'),'role', '', {value => $self->role}); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | ); | ||
| 29 | entry_has 'scope' => ( | ||
| 30 | is => 'rw', | ||
| 31 | isa => 'Net::Google::DocumentsList::Types::ACL::Scope', | ||
| 32 | from_atom => sub { | ||
| 33 | my ($self, $atom) = @_; | ||
| 34 | my $elem = first($atom->elem, $self->ns('gAcl')->{uri}, 'scope'); | ||
| 35 | my $obj = { | ||
| 36 | type => $elem->getAttribute('type'), | ||
| 37 | }; | ||
| 38 | if (my $value = $elem->getAttribute('value')) { | ||
| 39 | $obj->{value} = $value; | ||
| 40 | } | ||
| 41 | return $obj; | ||
| 42 | }, | ||
| 43 | to_atom => sub { | ||
| 44 | my ($self, $atom) = @_; | ||
| 45 | $atom->set($self->ns('gAcl'),'scope', '', $self->scope); | ||
| 46 | }, | ||
| 47 | ); | ||
| 48 | entry_has 'withKey' => ( | ||
| 49 | is => 'ro', | ||
| 50 | from_atom => sub { | ||
| 51 | my ($self, $atom) = @_; | ||
| 52 | if (my $elem = first($atom->elem, $self->ns('gAcl')->{uri}, 'withKey')) { | ||
| 53 | $elem->getAttribute('key') | ||
| 54 | } | ||
| 55 | }, | ||
| 56 | ); | ||
| 57 | |||
| 58 | sub delete { | ||
| 59 | my ($self) = @_; | ||
| 60 | # delete without etag! | ||
| 61 | my $res = $self->service->request( | ||
| 62 | { | ||
| 63 | method => 'DELETE', | ||
| 64 | uri => $self->editurl, | ||
| 65 | } | ||
| 66 | ); | ||
| 67 | $self->container->sync; | ||
| 68 | return $res->is_success; | ||
| 69 | } | ||
| 70 | |||
| 71 | __PACKAGE__->meta->make_immutable; | ||
| 72 | |||
| 73 | no Any::Moose; | ||
| 74 | |||
| 75 | 1; | ||
| 76 | __END__ |