| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::AmazonS3::Simple::Object::Memory; | 
| 2 | 1 |  |  | 1 |  | 705 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 26 |  | 
| 3 | 1 |  |  | 1 |  | 3 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 30 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 1 |  |  | 1 |  | 437 | use parent 'Net::AmazonS3::Simple::Object'; | 
|  | 1 |  |  |  |  | 276 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 38 | use Digest::MD5 qw(md5_hex); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 49 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 3 | use Class::Tiny qw(content); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 2 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 NAME | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | Net::AmazonS3::Simple::Object::Memory - S3 object in memory | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 16 |  |  |  |  |  |  | Net::AmazonS3::Simple::Object::File->create_from_response( | 
| 17 |  |  |  |  |  |  | response  => $response, | 
| 18 |  |  |  |  |  |  | content   => '...', | 
| 19 |  |  |  |  |  |  | ); | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | This class represents downloaded object with content in memory. | 
| 25 |  |  |  |  |  |  | This class is based on L. | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =head1 METHODS | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | =head2 new(%attributes) | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | =head3 %attributes | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | attributes from L | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =head4 content | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =cut | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub BUILD { | 
| 40 | 2 |  |  | 2 | 0 | 20 | my ($self) = @_; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 2 |  |  |  |  | 3 | foreach my $req (qw/content/) { | 
| 43 | 2 | 50 |  |  |  | 28 | die "$req attribute required" unless defined $self->$req; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 2 |  |  |  |  | 33 | my $content_md5  = uc md5_hex($self->content); | 
| 47 | 2 |  |  |  |  | 35 | my $expected_md5 = uc $self->etag; | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 2 | 100 | 66 |  |  | 30 | if ($self->validate && $content_md5 ne $expected_md5) { | 
| 50 | 1 |  |  |  |  | 18 | die "Object content (md5:$content_md5) isn't expected ETag (md5:$expected_md5)"; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | =head2 create_from_response(%options) | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =head3 %options | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =head4 validate | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | =head4 response | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =cut | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub create_from_response { | 
| 65 | 2 |  |  | 2 | 1 | 2537 | my ($class, %options) = @_; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 2 |  |  |  |  | 4 | foreach my $req (qw/validate response/) { | 
| 68 | 4 | 50 |  |  |  | 11 | die "$req parameter required" unless defined $options{$req}; | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 2 |  |  |  |  | 13 | my $etag = $options{response}->header('ETag'); | 
| 72 | 2 |  |  |  |  | 70 | $etag =~ s/"//g; | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 2 |  | 50 |  |  | 8 | my $content_encoding = $options{response}->content_encoding() || undef; | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | return $class->new( | 
| 77 |  |  |  |  |  |  | validate         => $options{validate}, | 
| 78 |  |  |  |  |  |  | etag             => $etag, | 
| 79 |  |  |  |  |  |  | content_encoding => $content_encoding, | 
| 80 |  |  |  |  |  |  | content_type     => $options{response}->content_type(), | 
| 81 |  |  |  |  |  |  | content_length   => $options{response}->content_length(), | 
| 82 |  |  |  |  |  |  | last_modified    => $options{response}->last_modified(), | 
| 83 | 2 |  |  |  |  | 57 | content          => $options{response}->content(), | 
| 84 |  |  |  |  |  |  | ); | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =head1 LICENSE | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | Copyright (C) Avast Software. | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify | 
| 92 |  |  |  |  |  |  | it under the same terms as Perl itself. | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | =head1 AUTHOR | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | Jan Seidl Eseidl@avast.comE | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =cut | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | 1; |