AWS-CloudFront

 view release on metacpan or  search on metacpan

META.yml  view on Meta::CPAN

--- #YAML:1.0
name:               AWS-CloudFront
version:            0.003
abstract:           Lightweight interface to Amazon CloudFront CDN
author:
    - John Drago <jdrago_999@yahoo.com>
license:            perl
distribution_type:  module
test_requires:
    Test::More:       0
requires:
    AWS::S3:                  0.023
    Carp:                     0
    LWP::UserAgent:           0
    Digest::HMAC_SHA1:        0
    MIME::Base64:             0
    URI::Escape:              0
    VSO:                      0.003

inc/Module/Install/Metadata.pm  view on Meta::CPAN

	$ISCORE  = 1;
	@ISA     = qw{Module::Install::Base};
}

my @scalar_keys = qw{
	name
	module_name
	abstract
	author
	version
	distribution_type
	tests
	installdirs
};

my @tuple_keys = qw{
	configure_requires
	build_requires
	requires
	recommends
	bundles

inc/Module/Install/Metadata.pm  view on Meta::CPAN

	while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
		$self->feature( $name, @$mods );
	}
	return $self->{values}{features}
		? @{ $self->{values}{features} }
		: ();
}

sub no_index {
	my $self = shift;
	my $type = shift;
	push @{ $self->{values}{no_index}{$type} }, @_ if $type;
	return $self->{values}{no_index};
}

sub read {
	my $self = shift;
	$self->include_deps( 'YAML::Tiny', 0 );

	require YAML::Tiny;
	my $data = YAML::Tiny::LoadFile('META.yml');

lib/AWS/CloudFront.pm  view on Meta::CPAN

  is        => 'ro',
  isa       => 'LWP::UserAgent',
  lazy      => 1,
  required  => 0,
  default => sub { LWP::UserAgent->new( agent => 'foo/bar v1.2' ) }
);


sub request
{
  my ($s, $type, %args) = @_;
  
  my $class = "AWS::CloudFront::Request::$type";
  load_class($class);
  return $class->new( %args, cf => $s, type => $type );
}# end request()


sub distribution
{
  my ($s, %args) = @_;
  
  my $type = 'GetDistribution';
  my $response = $s->request( $type, %args )->request();
  my $xpc = $response->xpc;
  
  if( my ($node) = $xpc->findnodes('.//cf:Distribution') )
  {
    my $origin;
    if( my ($origin_s3) = $xpc->findnodes('.//cf:S3Origin', $node) )
    {
      $origin = AWS::CloudFront::S3Origin->new(
        OriginAccessIdentity  => $xpc->findvalue('.//cf:OriginAccessIdentity', $origin_s3),
        DNSName               => $xpc->findvalue('.//cf:DNSName', $origin_s3),

lib/AWS/CloudFront.pm  view on Meta::CPAN

    );
    return $dist;
  }# end if()
}# end distribution()


sub add_distribution
{
  my ($s, %args) = @_;
  
  my $type = 'CreateDistribution';
  my $response = $s->request( $type, %args )->request();
  my $xpc = $response->xpc;

  if( my ($node) = $xpc->findnodes('.//cf:Distribution') )
  {
    my $origin;
    if( my ($origin_s3) = $xpc->findnodes('.//cf:S3Origin', $node) )
    {
      $origin = AWS::CloudFront::S3Origin->new(
        OriginAccessIdentity  => $xpc->findvalue('.//cf:OriginAccessIdentity', $origin_s3),
        DNSName               => $xpc->findvalue('.//cf:DNSName', $origin_s3),

lib/AWS/CloudFront.pm  view on Meta::CPAN

    );
    return $dist;
  }# end if()
}# end add_distribution()


sub distributions
{
  my ($s) = @_;
  
  my $type = 'GetDistributionList';
  my $response = $s->request( $type )->request();
  
  my $xpc = $response->xpc;
  my @dists = ( );
  foreach my $node ( $xpc->findnodes('.//cf:DistributionSummary') )
  {
    my $origin;
    if( my ($origin_s3) = $xpc->findnodes('.//cf:S3Origin', $node) )
    {
      $origin = AWS::CloudFront::S3Origin->new(
        OriginAccessIdentity  => $xpc->findvalue('.//cf:OriginAccessIdentity', $origin_s3),

lib/AWS/CloudFront/Distribution.pm  view on Meta::CPAN

    
    }# end foreach()
  }
);


sub update
{
  my $s = shift;
  
  my $type = 'UpdateDistribution';
  my $response = $s->cf->request( $type, Distribution => $s )->request();
  
  if( $response->error_code )
  {
    die $response->msg;
  }# end if()
}# end update()


sub delete
{
  my $s = shift;
  
  my $type = 'DeleteDistribution';
  my $response = $s->cf->request( $type, Id => $s->Id )->request();
  
  if( $response->error_code )
  {
    die $response->msg;
  }# end if()
}# end delete()


sub create_origin_access_identity
{
  my ($s, %args) = @_;
  
  my $type = 'CreateOriginAccessIdentity';
  my $response = $s->cf->request( $type,
    CallerReference => $s->CallerReference,
    Comment         => $args{Comment}
  )->request();
  
  if( $response->error_code )
  {
    die $response->msg;
  }# end if()
  
  my $xpc = $response->xpc;

lib/AWS/CloudFront/Logging.pm  view on Meta::CPAN


package AWS::CloudFront::Logging;

use VSO;

subtype 'AWS::CloudFront::Logging::Prefix'
  => as       'Str'
  => where    { length($_) <= 256 && $_ !~ m{^/} && $_ =~ m{/$} }
  => message  { "length <= 256, can't start with '/' and must end with '/'" }

has 'Bucket' => (
  is        => 'ro',
  isa       => 'Str',
  required  => 1,
);

lib/AWS/CloudFront/Request.pm  view on Meta::CPAN

use VSO;
use HTTP::Request;
use AWS::CloudFront::ResponseParser;

has 'cf' => (
  is        => 'ro',
  isa       => 'AWS::CloudFront',
  required  => 1,
);

has 'type' => (
  is        => 'ro',
  isa       => 'Str',
  required  => 1,
);

has 'protocol' => (
  is        => 'ro',
  isa       => 'Str',
  lazy      => 1,
  default   => sub { 'https' }

lib/AWS/CloudFront/Request/CreateDistribution.pm  view on Meta::CPAN

  }, $xml);
}# end request()

sub parse_response
{
  my ($s, $res) = @_;
  
  AWS::CloudFront::ResponseParser->new(
    response        => $res,
    expect_nothing  => 0,
    type            => $s->type,
  );
}# end http_request()


sub _origin_xml
{
  my $s = shift;
  
  my $type = ref($s->Origin);
  if( $type->isa('AWS::CloudFront::S3Origin') )
  {
    return <<"XML";
   <S3Origin>
      <DNSName>@{[ $s->Origin->DNSName ]}</DNSName>
   </S3Origin>
XML
  }
  elsif( $type->isa('AWS::CloudFront::CustomOrigin') )
  {
    return <<"XML";
   <CustomOrigin>
      <DNSName>@{[ $s->Origin->DNSName ]}</DNSName>
      <HTTPPort>@{[ $s->Origin->HTTPPort ]}</HTTPPort>
      <OriginProtocolPolicy>@{[ $s->Origin->OriginProtocolPolicy ]}</OriginProtocolPolicy>
   </CustomOrigin>
XML
  }# end if()
}# end _origin_xml()

lib/AWS/CloudFront/Request/CreateOriginAccessIdentity.pm  view on Meta::CPAN

  }, $xml);
}# end request()

sub parse_response
{
  my ($s, $res) = @_;
  
  AWS::CloudFront::ResponseParser->new(
    response        => $res,
    expect_nothing  => 0,
    type            => $s->type,
  );
}# end http_request()

1;# return true:

lib/AWS/CloudFront/Request/DeleteDistribution.pm  view on Meta::CPAN

  });
}# end request()

sub parse_response
{
  my ($s, $res) = @_;
  
  AWS::CloudFront::ResponseParser->new(
    response        => $res,
    expect_nothing  => 1,
    type            => $s->type,
  );
}# end http_request();

1;# return true:

lib/AWS/CloudFront/Request/GetDistribution.pm  view on Meta::CPAN

  });
}# end request()

sub parse_response
{
  my ($s, $res) = @_;
  
  AWS::CloudFront::ResponseParser->new(
    response        => $res,
    expect_nothing  => 0,
    type            => $s->type,
  );
}# end http_request()

1;# return true:

lib/AWS/CloudFront/Request/GetDistributionList.pm  view on Meta::CPAN

  });
}# end request()

sub parse_response
{
  my ($s, $res) = @_;
  
  AWS::CloudFront::ResponseParser->new(
    response        => $res,
    expect_nothing  => 0,
    type            => $s->type,
  );
}# end http_request()

1;# return true:

lib/AWS/CloudFront/Request/GetOriginAccessIdentity.pm  view on Meta::CPAN

  });
}# end request()

sub parse_response
{
  my ($s, $res) = @_;
  
  AWS::CloudFront::ResponseParser->new(
    response        => $res,
    expect_nothing  => 0,
    type            => $s->type,
  );
}# end http_request()

1;# return true:

lib/AWS/CloudFront/Request/GetOriginAccessIdentityList.pm  view on Meta::CPAN

  });
}# end request()

sub parse_response
{
  my ($s, $res) = @_;
  
  AWS::CloudFront::ResponseParser->new(
    response        => $res,
    expect_nothing  => 0,
    type            => $s->type,
  );
}# end http_request()

1;# return true:

lib/AWS/CloudFront/Request/UpdateDistribution.pm  view on Meta::CPAN

  }, $xml);
}# end request()

sub parse_response
{
  my ($s, $res) = @_;
  
  AWS::CloudFront::ResponseParser->new(
    response        => $res,
    expect_nothing  => 0,
    type            => $s->type,
  );
}# end http_request()


sub _origin_xml
{
  my $s = shift;
  
  my $type = ref($s->d->Origin);
  if( $type->isa('AWS::CloudFront::S3Origin') )
  {
    return <<"XML";
   <S3Origin>
      <DNSName>@{[ $s->d->Origin->DNSName ]}</DNSName>
   </S3Origin>
XML
  }
  elsif( $type->isa('AWS::CloudFront::CustomOrigin') )
  {
    return <<"XML";
   <CustomOrigin>
      <DNSName>@{[ $s->d->Origin->DNSName ]}</DNSName>
      <HTTPPort>@{[ $s->d->Origin->HTTPPort ]}</HTTPPort>
      <OriginProtocolPolicy>@{[ $s->Origin->OriginProtocolPolicy ]}</OriginProtocolPolicy>
   </CustomOrigin>
XML
  }# end if()
}# end _origin_xml()

lib/AWS/CloudFront/ResponseParser.pm  view on Meta::CPAN

  required  => 1,
  default   => sub { 0 }
);

has 'response'  => (
  is        => 'ro',
  isa       => 'HTTP::Response',
  required  => 1,
);

has 'type'  => (
  is        => 'ro',
  isa       => 'Str',
  required  => 1,
);

has 'libxml'  => (
  is        => 'ro',
  isa       => 'XML::LibXML',
  required  => 1,
  default   => sub { XML::LibXML->new() },

lib/AWS/CloudFront/ResponseParser.pm  view on Meta::CPAN

  required  => 0,
);

has 'friendly_error' => (
  is        => 'ro',
  isa       => 'Str',
  required  => 0,
  default   => sub {
    my $s = shift;
    return unless $s->error_code || $s->error_message;
    $s->type . " call had errors: [" . $s->error_code . "] " . $s->error_message;
  }
);


sub BUILD
{
  my $s = shift;
  
  my $code = $s->response->code;
  



( run in 1.132 second using v1.01-cache-2.11-cpan-d7f47b0818f )