MooseX::Fastly::Role - Fastly api from config, and purge methods
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();
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.
config
$self->cdn_purge_now({ keys => [ 'foo', 'bar' ], soft_purge => 1, });
Purge is called on all services, for each key.
$self->cdn_purge_all();
Purge all is called on all services
Methods below return objects from Net::Fastly.
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).
Net::Fastly
my $services = $self->cdn_services();
An array reference of Net::Fastly::Service objects, based on the fastly_service_id id(s) set in config.
Net::Fastly::Service
fastly_service_id
The array reference will be empty if fastly_service_id is not found in config.
Leo Lapworth <LLAP@cpan.org>
This program is free software; you can redistribute it and/or modify it under the terms same as Perl 5.
To install MooseX::Fastly::Role, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Fastly::Role
CPAN shell
perl -MCPAN -e shell install MooseX::Fastly::Role
For more information on module installation, please visit the detailed CPAN module installation guide.