Skip to content

Add Fastly CDN related to your Moose package, based on config

Notifications You must be signed in to change notification settings

manwar/p5-moosex-fastly-role

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

MooseX::Fastly::Role - Fastly api from config, and purge methods

SYSOPSIS

package My::App::CDN::Manager;

use Moose;

has config => (
  is      => 'ro',
  isa     => 'HashRef',
  lazy    => 1,
  default => sub {
      {
            fastly_api_key => 'XXXXX',
            fastly_service_id => 'YYYYY',
      };
  },
);

with 'MooseX::Fastly::Role';

$self->cdn_purge_now({
  keys => [ 'foo', 'bar' ],
  soft_purge => 1,
});

$self->cdn_purge_all();

my $fastly = $self->cdn_api();
my $services = $self->cdn_services();

DESCRIPTION

Fastly is a global CDN (Content Delivery Network), used by many companies. This module requires a config method to return a hashref. This packages uses HTTP::Tiny for most calls (so that you can use Fastly's token authentication for purging keys), but also provides accessors to Net::Fastly for convenience.

METHODS

cdn_purge_now

$self->cdn_purge_now({
  keys => [ 'foo', 'bar' ],
  soft_purge => 1,
});

Purge is called on all services, for each key.

cdn_purge_all

$self->cdn_purge_all();

Purge all is called on all services

Net::Fastly

Methods below return objects from Net::Fastly.

cdn_api

my $cdn_api = $self->cdn_api();

If there is a fastly_api_key in config a Net::Fastly instance is created and returned. Otherwise undef is returned (so you can develope safely if you do not set fastly_api_key in the config).

cdn_services

my $services = $self->cdn_services();

An array reference of Net::Fastly::Service objects, based on the fastly_service_id id(s) set in config.

The array reference will be empty if fastly_service_id is not found in config.

AUTHOR

Leo Lapworth LLAP@cpan.org

About

Add Fastly CDN related to your Moose package, based on config

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Perl 100.0%