r8736 - in /branches/upstream/libnet-amazon-s3-perl/current: CHANGES META.yml README lib/Net/Amazon/S3.pm lib/Net/Amazon/S3/Bucket.pm t/01api.t

gregoa-guest at users.alioth.debian.org gregoa-guest at users.alioth.debian.org
Thu Nov 1 12:15:58 UTC 2007


Author: gregoa-guest
Date: Thu Nov  1 12:15:57 2007
New Revision: 8736

URL: http://svn.debian.org/wsvn/?sc=1&rev=8736
Log:
[svn-upgrade] Integrating new upstream version, libnet-amazon-s3-perl (0.40)

Modified:
    branches/upstream/libnet-amazon-s3-perl/current/CHANGES
    branches/upstream/libnet-amazon-s3-perl/current/META.yml
    branches/upstream/libnet-amazon-s3-perl/current/README
    branches/upstream/libnet-amazon-s3-perl/current/lib/Net/Amazon/S3.pm
    branches/upstream/libnet-amazon-s3-perl/current/lib/Net/Amazon/S3/Bucket.pm
    branches/upstream/libnet-amazon-s3-perl/current/t/01api.t

Modified: branches/upstream/libnet-amazon-s3-perl/current/CHANGES
URL: http://svn.debian.org/wsvn/branches/upstream/libnet-amazon-s3-perl/current/CHANGES?rev=8736&op=diff
==============================================================================
--- branches/upstream/libnet-amazon-s3-perl/current/CHANGES (original)
+++ branches/upstream/libnet-amazon-s3-perl/current/CHANGES Thu Nov  1 12:15:57 2007
@@ -1,4 +1,10 @@
 Revision history for Perl module Net::Amazon::S3:
+
+0.40 Tue Oct 30 11:40:42 GMT 2007
+     - fix for content length with empty keys by Mark A. Hershberger
+     - get_key and get_key_filename now return content_length
+     - rewrote synopsis
+     - added support for common prefix (thanks to Andy Grundman)
 
 0.39 Sun Aug 19 14:47:01 BST 2007
      - add add_key_filename and get_key_filename which send files

Modified: branches/upstream/libnet-amazon-s3-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libnet-amazon-s3-perl/current/META.yml?rev=8736&op=diff
==============================================================================
--- branches/upstream/libnet-amazon-s3-perl/current/META.yml (original)
+++ branches/upstream/libnet-amazon-s3-perl/current/META.yml Thu Nov  1 12:15:57 2007
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:                Net-Amazon-S3
-version:             0.39
+version:             0.40
 abstract:            ~
 license:             perl
 generated_by:        ExtUtils::MakeMaker version 6.32

Modified: branches/upstream/libnet-amazon-s3-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libnet-amazon-s3-perl/current/README?rev=8736&op=diff
==============================================================================
--- branches/upstream/libnet-amazon-s3-perl/current/README (original)
+++ branches/upstream/libnet-amazon-s3-perl/current/README Thu Nov  1 12:15:57 2007
@@ -2,113 +2,69 @@
     Net::Amazon::S3 - Use the Amazon S3 - Simple Storage Service
 
 SYNOPSIS
-      #!/usr/bin/perl
-      use warnings;
-      use strict;
-      use Test::More qw/no_plan/;
-  
-      # this synopsis is presented as a test file
-
       use Net::Amazon::S3;
-  
-      use vars qw/$OWNER_ID $OWNER_DISPLAYNAME/;
-  
-      my $aws_access_key_id     = "Fill me in!";
-      my $aws_secret_access_key = "Fill me in too!";
-  
+      my $aws_access_key_id     = 'fill me in';
+      my $aws_secret_access_key = 'fill me in too';
+
       my $s3 = Net::Amazon::S3->new(
           {   aws_access_key_id     => $aws_access_key_id,
-              aws_secret_access_key => $aws_secret_access_key
+              aws_secret_access_key => $aws_secret_access_key,
           }
       );
-  
-      # you can also pass a timeout in seconds
-  
+
+      # a bucket is a globally-unique directory
       # list all buckets that i own
       my $response = $s3->buckets;
-  
-      TODO: {
-          local $TODO = "These tests only work if you're leon";
-          $OWNER_ID          = $response->{owner_id};
-          $OWNER_DISPLAYNAME = $response->{owner_displayname};
-  
-          is( $response->{owner_id},          '46a801915a1711f...' );
-          is( $response->{owner_displayname}, '_acme_' );
-          is_deeply( $response->{buckets}, [] );
+      foreach my $bucket ( @{ $response->{buckets} } ) {
+          print "You have a bucket: " . $bucket->bucket . "\n";
       }
-  
-      # create a bucket
-      my $bucketname = $aws_access_key_id . '-net-amazon-s3-test';
-      my $bucket_obj = $s3->add_bucket( { bucket => $bucketname } )
-          or die $s3->err . ": " . $s3->errstr;
-      is( ref $bucket_obj, "Net::Amazon::S3::Bucket" );
-  
-      # another way to get a bucket object (does no network I/O,
-      # assumes it already exists).  Read Net::Amazon::S3::Bucket.
-      $bucket_obj = $s3->bucket($bucketname);
-      is( ref $bucket_obj, "Net::Amazon::S3::Bucket" );
-  
-      # fetch contents of the bucket
-      # note prefix, marker, max_keys options can be passed in
-      $response = $bucket_obj->list
-          or die $s3->err . ": " . $s3->errstr;
-      is( $response->{bucket},       $bucketname );
-      is( $response->{prefix},       '' );
-      is( $response->{marker},       '' );
-      is( $response->{max_keys},     1_000 );
-      is( $response->{is_truncated}, 0 );
-      is_deeply( $response->{keys}, [] );
-  
-      # store a key with a content-type and some optional metadata
-      my $keyname = 'testing.txt';
-      my $value   = 'T';
-      $bucket_obj->add_key(
-          $keyname, $value,
-          {   content_type        => 'text/plain',
-              'x-amz-meta-colour' => 'orange',
-          }
-      );
-  
-      # list keys in the bucket
-      $response = $bucket_obj->list
-          or die $s3->err . ": " . $s3->errstr;
-      is( $response->{bucket},       $bucketname );
-      is( $response->{prefix},       '' );
-      is( $response->{marker},       '' );
-      is( $response->{max_keys},     1_000 );
-      is( $response->{is_truncated}, 0 );
-      my @keys = @{ $response->{keys} };
-      is( @keys, 1 );
-      my $key = $keys[0];
-      is( $key->{key}, $keyname );
-  
-      # the etag is the MD5 of the value
-      is( $key->{etag}, 'b9ece18c950afbfa6b0fdbfa4ff731d3' );
-      is( $key->{size}, 1 );
-  
-      is( $key->{owner_id},          $OWNER_ID );
-      is( $key->{owner_displayname}, $OWNER_DISPLAYNAME );
-  
-      # You can't delete a bucket with things in it
-      ok( !$bucket_obj->delete_bucket() );
-  
-      $bucket_obj->delete_key($keyname);
-  
-      # fetch contents of the bucket
-      # note prefix, marker, max_keys options can be passed in
-      $response = $bucket_obj->list
-          or die $s3->err . ": " . $s3->errstr;
-      is( $response->{bucket},       $bucketname );
-      is( $response->{prefix},       '' );
-      is( $response->{marker},       '' );
-      is( $response->{max_keys},     1_000 );
-      is( $response->{is_truncated}, 0 );
-      is_deeply( $response->{keys}, [] );
-  
-      ok( $bucket_obj->delete_bucket() );
-  
-      # see more docs in Net::Amazon::S3::Bucket
-  
+
+      # create a new bucket
+      my $bucketname = 'acmes_photo_backups';
+      my $bucket = $s3->add_bucket( { bucket => $bucketname } )
+          or die $s3->err . ": " . $s3->errstr;
+
+      # or use an existing bucket
+      $bucket = $s3->bucket($bucketname);
+
+      # store a file in the bucket
+      $bucket->add_key_filename( '1.JPG', 'DSC06256.JPG',
+          { content_type => 'image/jpeg', },
+      ) or die $s3->err . ": " . $s3->errstr;
+
+      # store a value in the bucket
+      $bucket->add_key( 'reminder.txt', 'this is where my photos are backed up' )
+          or die $s3->err . ": " . $s3->errstr;
+
+      # list files in the bucket
+      $response = $bucket->list_all
+          or die $s3->err . ": " . $s3->errstr;
+      foreach my $key ( @{ $response->{keys} } ) {
+          my $key_name = $key->{key};
+          my $key_size = $key->{size};
+          print "Bucket contains key '$key_name' of size $key_size\n";
+      }
+
+      # fetch file from the bucket
+      $response = $bucket->get_key_filename( '1.JPG', 'GET', 'backup.jpg' )
+          or die $s3->err . ": " . $s3->errstr;
+
+      # fetch value from the bucket
+      $response = $bucket->get_key('reminder.txt')
+          or die $s3->err . ": " . $s3->errstr;
+      print "reminder.txt:\n";
+      print "  content length: " . $response->{content_length} . "\n";
+      print "    content type: " . $response->{content_type} . "\n";
+      print "            etag: " . $response->{content_type} . "\n";
+      print "         content: " . $response->{value} . "\n";
+
+      # delete keys
+      $bucket->delete_key('reminder.txt') or die $s3->err . ": " . $s3->errstr;
+      $bucket->delete_key('1.JPG')        or die $s3->err . ": " . $s3->errstr;
+
+      # and finally delete the bucket
+      $bucket->delete_bucket or die $s3->err . ": " . $s3->errstr;
+
 DESCRIPTION
     This module provides a Perlish interface to Amazon S3. From the
     developer blurb: "Amazon S3 is storage for the Internet. It is designed
@@ -132,8 +88,6 @@
     stored in values. Values are referenced by keys, and keys are stored in
     buckets. Bucket names are global.
 
-    Some features, such as ACLs, are not yet implemented. Patches welcome!
-
 METHODS
   new
     Create a new S3 client object. Takes some arguments:
@@ -170,6 +124,9 @@
 
     bucket
         The name of the bucket you want to add
+
+    acl_short (optional)
+        See the set_acl subroutine for documenation on the acl_short options
 
     Returns 0 on failure, Net::Amazon::S3::Bucket object on success
 
@@ -225,9 +182,6 @@
         present in your request, keys in the result set will not be
         rolled-up and neither the CommonPrefixes collection nor the
         NextMarker element will be present in the response.
-
-        NOTE (TODO): CommonPrefixes isn't currently supported by
-        Net::Amazon::S3. Patches welcome
 
     max-keys
         This optional argument limits the number of results returned in
@@ -259,16 +213,22 @@
     The hashref looks like this:
 
       {
-            bucket       => $bucket_name,
-            prefix       => $bucket_prefix, 
-            marker       => $bucket_marker, 
-            next_marker  => $bucket_next_available_marker,
-            max_keys     => $bucket_max_keys,
-            is_truncated => $bucket_is_truncated_boolean
-            keys          => [$key1,$key2,...]
+            bucket          => $bucket_name,
+            prefix          => $bucket_prefix, 
+            common_prefixes => [$prefix1,$prefix2,...]
+            marker          => $bucket_marker, 
+            next_marker     => $bucket_next_available_marker,
+            max_keys        => $bucket_max_keys,
+            is_truncated    => $bucket_is_truncated_boolean
+            keys            => [$key1,$key2,...]
        }
 
     Explanation of bits of that:
+
+    common_prefixes
+        If list_bucket was requested with a delimiter, common_prefixes will
+        contain a list of prefixes matching that delimiter. Drill down into
+        these prefixes by making another request with the prefix parameter.
 
     is_truncated
         B flag that indicates whether or not all results of your query were

Modified: branches/upstream/libnet-amazon-s3-perl/current/lib/Net/Amazon/S3.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libnet-amazon-s3-perl/current/lib/Net/Amazon/S3.pm?rev=8736&op=diff
==============================================================================
--- branches/upstream/libnet-amazon-s3-perl/current/lib/Net/Amazon/S3.pm (original)
+++ branches/upstream/libnet-amazon-s3-perl/current/lib/Net/Amazon/S3.pm Thu Nov  1 12:15:57 2007
@@ -8,114 +8,69 @@
 
 =head1 SYNOPSIS
 
-  #!/usr/bin/perl
-  use warnings;
-  use strict;
-  use Test::More qw/no_plan/;
-  
-  # this synopsis is presented as a test file
-
   use Net::Amazon::S3;
-  
-  
-  use vars qw/$OWNER_ID $OWNER_DISPLAYNAME/;
-  
-  my $aws_access_key_id     = "Fill me in!";
-  my $aws_secret_access_key = "Fill me in too!";
-  
+  my $aws_access_key_id     = 'fill me in';
+  my $aws_secret_access_key = 'fill me in too';
+
   my $s3 = Net::Amazon::S3->new(
       {   aws_access_key_id     => $aws_access_key_id,
-          aws_secret_access_key => $aws_secret_access_key
+          aws_secret_access_key => $aws_secret_access_key,
       }
   );
-  
-  # you can also pass a timeout in seconds
-  
+
+  # a bucket is a globally-unique directory
   # list all buckets that i own
   my $response = $s3->buckets;
-  
-  TODO: {
-      local $TODO = "These tests only work if you're leon";
-      $OWNER_ID          = $response->{owner_id};
-      $OWNER_DISPLAYNAME = $response->{owner_displayname};
-  
-      is( $response->{owner_id},          '46a801915a1711f...' );
-      is( $response->{owner_displayname}, '_acme_' );
-      is_deeply( $response->{buckets}, [] );
+  foreach my $bucket ( @{ $response->{buckets} } ) {
+      print "You have a bucket: " . $bucket->bucket . "\n";
   }
-  
-  # create a bucket
-  my $bucketname = $aws_access_key_id . '-net-amazon-s3-test';
-  my $bucket_obj = $s3->add_bucket( { bucket => $bucketname } )
+
+  # create a new bucket
+  my $bucketname = 'acmes_photo_backups';
+  my $bucket = $s3->add_bucket( { bucket => $bucketname } )
       or die $s3->err . ": " . $s3->errstr;
-  is( ref $bucket_obj, "Net::Amazon::S3::Bucket" );
-  
-  # another way to get a bucket object (does no network I/O,
-  # assumes it already exists).  Read Net::Amazon::S3::Bucket.
-  $bucket_obj = $s3->bucket($bucketname);
-  is( ref $bucket_obj, "Net::Amazon::S3::Bucket" );
-  
-  # fetch contents of the bucket
-  # note prefix, marker, max_keys options can be passed in
-  $response = $bucket_obj->list
+
+  # or use an existing bucket
+  $bucket = $s3->bucket($bucketname);
+
+  # store a file in the bucket
+  $bucket->add_key_filename( '1.JPG', 'DSC06256.JPG',
+      { content_type => 'image/jpeg', },
+  ) or die $s3->err . ": " . $s3->errstr;
+
+  # store a value in the bucket
+  $bucket->add_key( 'reminder.txt', 'this is where my photos are backed up' )
       or die $s3->err . ": " . $s3->errstr;
-  is( $response->{bucket},       $bucketname );
-  is( $response->{prefix},       '' );
-  is( $response->{marker},       '' );
-  is( $response->{max_keys},     1_000 );
-  is( $response->{is_truncated}, 0 );
-  is_deeply( $response->{keys}, [] );
-  
-  # store a key with a content-type and some optional metadata
-  my $keyname = 'testing.txt';
-  my $value   = 'T';
-  $bucket_obj->add_key(
-      $keyname, $value,
-      {   content_type        => 'text/plain',
-          'x-amz-meta-colour' => 'orange',
-      }
-  );
-  
-  # list keys in the bucket
-  $response = $bucket_obj->list
+
+  # list files in the bucket
+  $response = $bucket->list_all
       or die $s3->err . ": " . $s3->errstr;
-  is( $response->{bucket},       $bucketname );
-  is( $response->{prefix},       '' );
-  is( $response->{marker},       '' );
-  is( $response->{max_keys},     1_000 );
-  is( $response->{is_truncated}, 0 );
-  my @keys = @{ $response->{keys} };
-  is( @keys, 1 );
-  my $key = $keys[0];
-  is( $key->{key}, $keyname );
-  
-  # the etag is the MD5 of the value
-  is( $key->{etag}, 'b9ece18c950afbfa6b0fdbfa4ff731d3' );
-  is( $key->{size}, 1 );
-  
-  is( $key->{owner_id},          $OWNER_ID );
-  is( $key->{owner_displayname}, $OWNER_DISPLAYNAME );
-  
-  # You can't delete a bucket with things in it
-  ok( !$bucket_obj->delete_bucket() );
-  
-  $bucket_obj->delete_key($keyname);
-  
-  # fetch contents of the bucket
-  # note prefix, marker, max_keys options can be passed in
-  $response = $bucket_obj->list
+  foreach my $key ( @{ $response->{keys} } ) {
+      my $key_name = $key->{key};
+      my $key_size = $key->{size};
+      print "Bucket contains key '$key_name' of size $key_size\n";
+  }
+
+  # fetch file from the bucket
+  $response = $bucket->get_key_filename( '1.JPG', 'GET', 'backup.jpg' )
       or die $s3->err . ": " . $s3->errstr;
-  is( $response->{bucket},       $bucketname );
-  is( $response->{prefix},       '' );
-  is( $response->{marker},       '' );
-  is( $response->{max_keys},     1_000 );
-  is( $response->{is_truncated}, 0 );
-  is_deeply( $response->{keys}, [] );
-  
-  ok( $bucket_obj->delete_bucket() );
-  
-  # see more docs in Net::Amazon::S3::Bucket
-  
+
+  # fetch value from the bucket
+  $response = $bucket->get_key('reminder.txt')
+      or die $s3->err . ": " . $s3->errstr;
+  print "reminder.txt:\n";
+  print "  content length: " . $response->{content_length} . "\n";
+  print "    content type: " . $response->{content_type} . "\n";
+  print "            etag: " . $response->{content_type} . "\n";
+  print "         content: " . $response->{value} . "\n";
+
+  # delete keys
+  $bucket->delete_key('reminder.txt') or die $s3->err . ": " . $s3->errstr;
+  $bucket->delete_key('1.JPG')        or die $s3->err . ": " . $s3->errstr;
+
+  # and finally delete the bucket
+  $bucket->delete_bucket or die $s3->err . ": " . $s3->errstr;
+
 =head1 DESCRIPTION
 
 This module provides a Perlish interface to Amazon S3. From the
@@ -140,8 +95,6 @@
 stored in values. Values are referenced by keys, and keys are stored
 in buckets. Bucket names are global.
 
-Some features, such as ACLs, are not yet implemented. Patches welcome!
-
 =cut
 
 use Carp;
@@ -158,7 +111,7 @@
 __PACKAGE__->mk_accessors(
     qw(libxml aws_access_key_id aws_secret_access_key secure ua err errstr timeout)
 );
-our $VERSION = '0.39';
+our $VERSION = '0.40';
 
 my $AMAZON_HEADER_PREFIX = 'x-amz-';
 my $METADATA_PREFIX      = 'x-amz-meta-';
@@ -386,11 +339,6 @@
 request, keys in the result set will not be rolled-up and neither
 the CommonPrefixes collection nor the NextMarker element will be
 present in the response.
-
-NOTE (TODO): CommonPrefixes isn't currently supported by Net::Amazon::S3. 
-Patches welcome
-
-
 
 =item max-keys 
 
@@ -427,19 +375,25 @@
 The hashref looks like this:
 
   {
-        bucket       => $bucket_name,
-        prefix       => $bucket_prefix, 
-        marker       => $bucket_marker, 
-        next_marker  => $bucket_next_available_marker,
-        max_keys     => $bucket_max_keys,
-        is_truncated => $bucket_is_truncated_boolean
-        keys          => [$key1,$key2,...]
+        bucket          => $bucket_name,
+        prefix          => $bucket_prefix, 
+        common_prefixes => [$prefix1,$prefix2,...]
+        marker          => $bucket_marker, 
+        next_marker     => $bucket_next_available_marker,
+        max_keys        => $bucket_max_keys,
+        is_truncated    => $bucket_is_truncated_boolean
+        keys            => [$key1,$key2,...]
    }
 
 Explanation of bits of that:
 
 =over
 
+=item common_prefixes
+
+If list_bucket was requested with a delimiter, common_prefixes will
+contain a list of prefixes matching that delimiter.  Drill down into
+these prefixes by making another request with the prefix parameter.
 
 =item is_truncated
 
@@ -460,8 +414,6 @@
 sent with the request.
 
 =back
-
-
 
 Each key is a hashref that looks like this:
 
@@ -526,6 +478,22 @@
             };
     }
     $return->{keys} = \@keys;
+
+    if ( $conf->{delimiter} ) {
+        my @common_prefixes;
+        my $strip_delim = qr/$conf->{delimiter}$/;
+
+        foreach my $node ( $xpc->findnodes(".//s3:CommonPrefixes") ) {
+            my $prefix = $xpc->findvalue( ".//s3:Prefix", $node );
+
+            # strip delimiter from end of prefix
+            $prefix =~ s/$strip_delim//;
+
+            push @common_prefixes, $prefix;
+        }
+        $return->{common_prefixes} = \@common_prefixes;
+    }
+
     return $return;
 }
 

Modified: branches/upstream/libnet-amazon-s3-perl/current/lib/Net/Amazon/S3/Bucket.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libnet-amazon-s3-perl/current/lib/Net/Amazon/S3/Bucket.pm?rev=8736&op=diff
==============================================================================
--- branches/upstream/libnet-amazon-s3-perl/current/lib/Net/Amazon/S3/Bucket.pm (original)
+++ branches/upstream/libnet-amazon-s3-perl/current/lib/Net/Amazon/S3/Bucket.pm Thu Nov  1 12:15:57 2007
@@ -6,6 +6,57 @@
 use base qw(Class::Accessor::Fast);
 __PACKAGE__->mk_accessors(qw(bucket creation_date account));
 
+=head1 NAME
+
+Net::Amazon::S3::Bucket - convenience object for working with Amazon S3 buckets
+
+=head1 SYNOPSIS
+
+  use Net::Amazon::S3;
+
+  my $bucket = $s3->bucket("foo");
+
+  ok($bucket->add_key("key", "data"));
+  ok($bucket->add_key("key", "data", {
+     content_type => "text/html",
+    'x-amz-meta-colour' => 'orange',
+  });
+
+  # the err and errstr methods just proxy up to the Net::Amazon::S3's
+  # objects err/errstr methods.
+  $bucket->add_key("bar", "baz") or
+      die $bucket->err . $bucket->errstr;
+
+  # fetch a key
+  $val = $bucket->get_key("key");
+  is( $val->{value},               'data' );
+  is( $val->{content_type},        'text/html' );
+  is( $val->{etag},                'b9ece18c950afbfa6b0fdbfa4ff731d3' );
+  is( $val->{'x-amz-meta-colour'}, 'orange' );
+
+  # returns undef on missing or on error (check $bucket->err)
+  is(undef, $bucket->get_key("non-existing-key"));
+  die $bucket->errstr if $bucket->err;
+
+  # fetch a key's metadata
+  $val = $bucket->head_key("key");
+  is( $val->{value},               '' );
+  is( $val->{content_type},        'text/html' );
+  is( $val->{etag},                'b9ece18c950afbfa6b0fdbfa4ff731d3' );
+  is( $val->{'x-amz-meta-colour'}, 'orange' );
+
+  # delete a key
+  ok($bucket->delete_key($key_name));
+  ok(! $bucket->delete_key("non-exist-key"));
+
+  # delete the entire bucket (Amazon requires it first be empty)
+  $bucket->delete_bucket;
+ 
+=head1 DESCRIPTION
+
+This module represents an S3 bucket.  You get a bucket object
+from the Net::Amazon::S3 object.
+
 =head1 METHODS
 
 =head2 new
@@ -71,6 +122,8 @@
     if ( ref($value) eq 'SCALAR' ) {
         $conf->{'Content-Length'} ||= -s $$value;
         $value = _content_sub($$value);
+    } else {
+        $conf->{'Content-Length'} ||= length $value;
     }
 
     return $self->account->_send_request_expect_nothing( 'PUT',
@@ -96,9 +149,10 @@
 Returns a boolean.
 
 =cut
+
 sub add_key_filename {
     my ( $self, $key, $value, $conf ) = @_;
-    return $self->add_key($key, \$value, $conf);
+    return $self->add_key( $key, \$value, $conf );
 }
 
 =head2 head_key KEY
@@ -149,9 +203,10 @@
     }
 
     my $return = {
-        content_type => $response->content_type,
-        etag         => $etag,
-        value        => $response->content,
+        content_length => $response->content_length || 0,
+        content_type   => $response->content_type,
+        etag           => $etag,
+        value          => $response->content,
     };
 
     foreach my $header ( $response->headers->header_field_names ) {
@@ -181,7 +236,7 @@
 
 sub get_key_filename {
     my ( $self, $key, $method, $filename ) = @_;
-    return $self->get_key($key, $method, \$filename);
+    return $self->get_key( $key, $method, \$filename );
 }
 
 =head2 delete_key $key_name
@@ -403,57 +458,6 @@
 
 __END__
 
-=head1 NAME
-
-Net::Amazon::S3::Bucket - convenience object for working with Amazon S3 buckets
-
-=head1 SYNOPSIS
-
-  use Net::Amazon::S3;
-
-  my $bucket = $s3->bucket("foo");
-
-  ok($bucket->add_key("key", "data"));
-  ok($bucket->add_key("key", "data", {
-     content_type => "text/html",
-    'x-amz-meta-colour' => 'orange',
-  });
-
-  # the err and errstr methods just proxy up to the Net::Amazon::S3's
-  # objects err/errstr methods.
-  $bucket->add_key("bar", "baz") or
-      die $bucket->err . $bucket->errstr;
-
-  # fetch a key
-  $val = $bucket->get_key("key");
-  is( $val->{value},               'data' );
-  is( $val->{content_type},        'text/html' );
-  is( $val->{etag},                'b9ece18c950afbfa6b0fdbfa4ff731d3' );
-  is( $val->{'x-amz-meta-colour'}, 'orange' );
-
-  # returns undef on missing or on error (check $bucket->err)
-  is(undef, $bucket->get_key("non-existing-key"));
-  die $bucket->errstr if $bucket->err;
-
-  # fetch a key's metadata
-  $val = $bucket->head_key("key");
-  is( $val->{value},               '' );
-  is( $val->{content_type},        'text/html' );
-  is( $val->{etag},                'b9ece18c950afbfa6b0fdbfa4ff731d3' );
-  is( $val->{'x-amz-meta-colour'}, 'orange' );
-
-  # delete a key
-  ok($bucket->delete_key($key_name));
-  ok(! $bucket->delete_key("non-exist-key"));
-
-  # delete the entire bucket (Amazon requires it first be empty)
-  $bucket->delete_bucket;
- 
-=head1 DESCRIPTION
-
-This module represents an S3 bucket.  You get a bucket object
-from the Net::Amazon::S3 object.
-
 =head1 SEE ALSO
 
 L<Net::Amazon::S3>

Modified: branches/upstream/libnet-amazon-s3-perl/current/t/01api.t
URL: http://svn.debian.org/wsvn/branches/upstream/libnet-amazon-s3-perl/current/t/01api.t?rev=8736&op=diff
==============================================================================
--- branches/upstream/libnet-amazon-s3-perl/current/t/01api.t (original)
+++ branches/upstream/libnet-amazon-s3-perl/current/t/01api.t Thu Nov  1 12:15:57 2007
@@ -9,7 +9,7 @@
 unless ( $ENV{'AMAZON_S3_EXPENSIVE_TESTS'} ) {
     plan skip_all => 'Testing this module for real costs money.';
 } else {
-    plan tests => 60;
+    plan tests => 66;
 }
 
 use_ok('Net::Amazon::S3');
@@ -195,8 +195,9 @@
 $response = $bucket_obj->get_key($keyname);
 is( $response->{content_type}, 'text/plain' );
 like( $response->{value}, qr/and unknown Amazon/ );
-is( $response->{etag}, '7ad9ac8f950a8e29d7f83c4bff903f08' );
+is( $response->{etag},                '7ad9ac8f950a8e29d7f83c4bff903f08' );
 is( $response->{'x-amz-meta-colour'}, 'orangy' );
+is( $response->{content_length},      13_396 );
 
 unlink('t/README');
 $response = $bucket_obj->get_key_filename( $keyname, undef, 't/README' );
@@ -205,7 +206,18 @@
 is( $response->{etag},                '7ad9ac8f950a8e29d7f83c4bff903f08' );
 is( file_md5_hex('t/README'),         '7ad9ac8f950a8e29d7f83c4bff903f08' );
 is( $response->{'x-amz-meta-colour'}, 'orangy' );
-
+is( $response->{content_length},      13_396 );
+
+$bucket_obj->delete_key($keyname);
+
+# try empty files
+$keyname .= "3";
+$bucket_obj->add_key( $keyname, '' );
+$response = $bucket_obj->get_key($keyname);
+is( $response->{value},          '' );
+is( $response->{etag},           'd41d8cd98f00b204e9800998ecf8427e' );
+is( $response->{content_type},   'binary/octet-stream' );
+is( $response->{content_length}, 0 );
 $bucket_obj->delete_key($keyname);
 
 # fetch contents of the bucket
@@ -288,3 +300,4 @@
         </AccessControlList>
     </AccessControlPolicy>~;
 }
+




More information about the Pkg-perl-cvs-commits mailing list