| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::Amazon::S3::ACL::Set; | 
| 2 |  |  |  |  |  |  | # ABSTRACT: Representation of explicit ACL | 
| 3 |  |  |  |  |  |  | $Net::Amazon::S3::ACL::Set::VERSION = '0.99'; | 
| 4 | 100 |  |  | 100 |  | 1530 | use Moose 0.85; | 
|  | 100 |  |  |  |  | 2244 |  | 
|  | 100 |  |  |  |  | 686 |  | 
| 5 | 100 |  |  | 100 |  | 673509 | use MooseX::StrictConstructor 0.16; | 
|  | 100 |  |  |  |  | 2058 |  | 
|  | 100 |  |  |  |  | 704 |  | 
| 6 | 100 |  |  | 100 |  | 328783 | use Moose::Util::TypeConstraints; | 
|  | 100 |  |  |  |  | 295 |  | 
|  | 100 |  |  |  |  | 842 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 100 |  |  | 100 |  | 218961 | use Ref::Util (); | 
|  | 100 |  |  |  |  | 280 |  | 
|  | 100 |  |  |  |  | 2219 |  | 
| 9 | 100 |  |  | 100 |  | 588 | use Safe::Isa (); | 
|  | 100 |  |  |  |  | 246 |  | 
|  | 100 |  |  |  |  | 2274 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 100 |  |  | 100 |  | 45612 | use Net::Amazon::S3::Constants; | 
|  | 100 |  |  |  |  | 280 |  | 
|  | 100 |  |  |  |  | 3201 |  | 
| 12 | 100 |  |  | 100 |  | 46337 | use Net::Amazon::S3::ACL::Grantee::User; | 
|  | 100 |  |  |  |  | 332 |  | 
|  | 100 |  |  |  |  | 3806 |  | 
| 13 | 100 |  |  | 100 |  | 52674 | use Net::Amazon::S3::ACL::Grantee::Group; | 
|  | 100 |  |  |  |  | 347 |  | 
|  | 100 |  |  |  |  | 4004 |  | 
| 14 | 100 |  |  | 100 |  | 52195 | use Net::Amazon::S3::ACL::Grantee::Email; | 
|  | 100 |  |  |  |  | 347 |  | 
|  | 100 |  |  |  |  | 67835 |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | class_type 'Net::Amazon::S3::ACL::Set'; | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | my %permission_map = ( | 
| 19 |  |  |  |  |  |  | full_control    => Net::Amazon::S3::Constants::HEADER_GRANT_FULL_CONTROL, | 
| 20 |  |  |  |  |  |  | read            => Net::Amazon::S3::Constants::HEADER_GRANT_READ, | 
| 21 |  |  |  |  |  |  | read_acp        => Net::Amazon::S3::Constants::HEADER_GRANT_READ_ACP, | 
| 22 |  |  |  |  |  |  | write           => Net::Amazon::S3::Constants::HEADER_GRANT_WRITE, | 
| 23 |  |  |  |  |  |  | write_acp       => Net::Amazon::S3::Constants::HEADER_GRANT_WRITE_ACP, | 
| 24 |  |  |  |  |  |  | ); | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | my %grantees_map = ( | 
| 27 |  |  |  |  |  |  | id    => 'Net::Amazon::S3::ACL::Grantee::User', | 
| 28 |  |  |  |  |  |  | user  => 'Net::Amazon::S3::ACL::Grantee::User', | 
| 29 |  |  |  |  |  |  | uri   => 'Net::Amazon::S3::ACL::Grantee::Group', | 
| 30 |  |  |  |  |  |  | group => 'Net::Amazon::S3::ACL::Grantee::Group', | 
| 31 |  |  |  |  |  |  | email => 'Net::Amazon::S3::ACL::Grantee::Email', | 
| 32 |  |  |  |  |  |  | ); | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | has _grantees => ( | 
| 35 |  |  |  |  |  |  | is => 'ro', | 
| 36 |  |  |  |  |  |  | default => sub { +{} }, | 
| 37 |  |  |  |  |  |  | ); | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub build_headers { | 
| 40 | 30 |  |  | 30 | 0 | 95 | my ($self) = @_; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 30 |  |  |  |  | 68 | my %headers; | 
| 43 | 30 |  |  |  |  | 68 | while (my ($header, $grantees) = each %{ $self->_grantees }) { | 
|  | 91 |  |  |  |  | 2448 |  | 
| 44 | 61 |  |  |  |  | 276 | $headers{$header} = join ', ', map $_->format_for_header, @$grantees; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 30 |  |  |  |  | 284 | %headers; | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | sub grant_full_control { | 
| 51 | 1 |  |  | 1 | 1 | 314 | my ($self, @grantees) = @_; | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 1 |  |  |  |  | 6 | $self->_grant (full_control => @grantees); | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | sub grant_read { | 
| 57 | 15 |  |  | 15 | 1 | 5266 | my ($self, @grantees) = @_; | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 15 |  |  |  |  | 91 | $self->_grant (read => @grantees); | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | sub grant_read_acp { | 
| 63 | 0 |  |  | 0 | 1 | 0 | my ($self, @grantees) = @_; | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 0 |  |  |  |  | 0 | $self->_grant (read_acp => @grantees); | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | sub grant_write { | 
| 69 | 16 |  |  | 16 | 1 | 622 | my ($self, @grantees) = @_; | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 16 |  |  |  |  | 69 | $self->_grant (write => @grantees); | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | sub grant_write_acp { | 
| 75 | 0 |  |  | 0 | 1 | 0 | my ($self, @grantees) = @_; | 
| 76 |  |  |  |  |  |  |  | 
| 77 | 0 |  |  |  |  | 0 | $self->_grant (write_acp => @grantees); | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | sub _grant { | 
| 81 | 32 |  |  | 32 |  | 116 | my ($self, $permission, @grantees) = @_; | 
| 82 | 32 | 50 |  |  |  | 120 | $self = $self->new unless ref $self; | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 32 |  |  |  |  | 89 | my $key = lc $permission; | 
| 85 | 32 |  |  |  |  | 80 | $key =~ tr/-/_/; | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | die "Unknown permission $permission" | 
| 88 | 32 | 50 |  |  |  | 137 | unless exists $permission_map{$key}; | 
| 89 |  |  |  |  |  |  |  | 
| 90 | 32 | 50 |  |  |  | 96 | return unless @grantees; | 
| 91 |  |  |  |  |  |  |  | 
| 92 | 32 |  | 100 |  |  | 1071 | my $list = $self->_grantees->{$permission_map{$key}} ||= []; | 
| 93 | 32 |  |  |  |  | 113 | while (@grantees) { | 
| 94 | 49 |  |  |  |  | 9881 | my $type = shift @grantees; | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 49 | 100 |  |  |  | 195 | if ($type->$Safe::Isa::_isa ('Net::Amazon::S3::ACL::Grantee')) { | 
| 97 | 2 |  |  |  |  | 32 | push @{ $list }, $type; | 
|  | 2 |  |  |  |  | 5 |  | 
| 98 | 2 |  |  |  |  | 6 | next; | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | die "Unknown grantee type $type" | 
| 102 | 47 | 50 |  |  |  | 644 | unless exists $grantees_map{$type}; | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 47 | 50 |  |  |  | 133 | die "Grantee type $type requires one argument" | 
| 105 |  |  |  |  |  |  | unless @grantees; | 
| 106 |  |  |  |  |  |  |  | 
| 107 | 47 |  |  |  |  | 118 | my @grantee = (shift @grantees); | 
| 108 | 47 | 50 |  |  |  | 152 | @grantees = @{ $grantee[0] } | 
|  | 0 |  |  |  |  | 0 |  | 
| 109 |  |  |  |  |  |  | if Ref::Util::is_plain_arrayref ($grantee[0]); | 
| 110 |  |  |  |  |  |  |  | 
| 111 | 47 |  |  |  |  | 82 | push @{ $list }, map $grantees_map{$type}->new ($_), @grantee; | 
|  | 47 |  |  |  |  | 425 |  | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 32 |  |  |  |  | 15905 | return $self; | 
| 115 |  |  |  |  |  |  | } | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | 1; | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | __END__ | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =pod | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =encoding UTF-8 | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | =head1 NAME | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | Net::Amazon::S3::ACL::Set - Representation of explicit ACL | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =head1 VERSION | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | version 0.99 | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | use Net::Amazon::S3::ACL; | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | $acl = Net::Amazon::S3::ACL->new | 
| 138 |  |  |  |  |  |  | ->grant_full_control ( | 
| 139 |  |  |  |  |  |  | id => 11112222333, | 
| 140 |  |  |  |  |  |  | id => 444455556666, | 
| 141 |  |  |  |  |  |  | uri => 'predefined group uri', | 
| 142 |  |  |  |  |  |  | email => 'email-address', | 
| 143 |  |  |  |  |  |  | ) | 
| 144 |  |  |  |  |  |  | ->grant_write ( | 
| 145 |  |  |  |  |  |  | ... | 
| 146 |  |  |  |  |  |  | ) | 
| 147 |  |  |  |  |  |  | ; | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | Class representing explicit Amazon S3 ACL configuration. | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =head1 METHODS | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | =head2 new | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | Creates new instance. | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | =head2 grant_full_control (@grantees) | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | =head2 grant_read (@grantees) | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | =head2 grant_read_acp (@grantees) | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | =head2 grant_write (@grantees) | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | =head2 grant_write_acp (@grantees) | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | =head1 GRANTEES | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | See also L<"Who Is a Grantee?"|https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#specifying-grantee> | 
| 172 |  |  |  |  |  |  | in Amazon S3 documentation. | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | Each grant_* method accepts list of grantees either in key-value format or as an | 
| 175 |  |  |  |  |  |  | instance of C<Net::Amazon::S3::ACL::Grantee::*>. | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =over | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =item canonical user ID | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | ->grant_read ( | 
| 182 |  |  |  |  |  |  | id => 123, | 
| 183 |  |  |  |  |  |  | Net::Amazon::S3::ACL::Grantee::User->new (123), | 
| 184 |  |  |  |  |  |  | ) | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | =item predefined group uri | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  | ->grant_read ( | 
| 189 |  |  |  |  |  |  | uri => 'http://...', | 
| 190 |  |  |  |  |  |  | Net::Amazon::S3::ACL::Grantee::Group->new ('http://...'), | 
| 191 |  |  |  |  |  |  | Net::Amazon::S3::ACL::Grantee::Group->ALL_USERS, | 
| 192 |  |  |  |  |  |  | ) | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | =item email address | 
| 195 |  |  |  |  |  |  |  | 
| 196 |  |  |  |  |  |  | ->grant_read ( | 
| 197 |  |  |  |  |  |  | email => 'foo@bar.baz', | 
| 198 |  |  |  |  |  |  | Net::Amazon::S3::ACL::Grantee::Email->new ('foo@bar.baz'), | 
| 199 |  |  |  |  |  |  | ); | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | =back | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | =head1 AUTHOR | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | Branislav Zahradník <barney@cpan.org> | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | This module is part of L<Net::Amazon::S3>. | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | =head1 AUTHOR | 
| 212 |  |  |  |  |  |  |  | 
| 213 |  |  |  |  |  |  | Branislav Zahradník <barney@cpan.org> | 
| 214 |  |  |  |  |  |  |  | 
| 215 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 216 |  |  |  |  |  |  |  | 
| 217 |  |  |  |  |  |  | This software is copyright (c) 2021 by Amazon Digital Services, Leon Brocard, Brad Fitzpatrick, Pedro Figueiredo, Rusty Conover, Branislav Zahradník. | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 220 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 221 |  |  |  |  |  |  |  | 
| 222 |  |  |  |  |  |  | =cut |