| 1 | package Net::Fastly::Service; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use base qw(Net::Fastly::Model); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 5 | Net::Fastly::Service->mk_accessors(qw(id customer_id name comment)); | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Net::Fastly::Service - a representation of a Fastly service | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 ACCESSORS | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head2 id | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | The id of the service | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head2 customer | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | The id of the customer this belongs to | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head2 name | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | The name of this service | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head2 comment | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | a free form comment field | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 METHODS | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head2 stats [type] | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | Get an hash ref of stats from different data centers. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | Type can be one of | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =over 4 | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =item minutely | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =item hourly | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =item daily | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =item all (default) | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =back | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub stats { | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
stats: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $type = shift || "all"; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 'all'
MC/DC0%0/1
shift() || 'all'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 59 | 0 | my %opts = @_; | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | die "Unknown stats type $type" unless grep { $_ eq $type } qw(minutely hourly daily all); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | return $self->_fetcher->client->_get($self->_get_path($self->id)."/stats/".$type, %opts); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head2 invoice [<year> <month>] | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | Return a Net::Fastly::Invoice objects representing the invoice for this service | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | If a year and month are passed in returns the invoice for that whole month. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Otherwise it returns the invoice for the current month so far. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||||||||||
| 73 | sub invoice { | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
invoice: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 0 | my $year = shift; | |||||||||||||||||||||||||||
| 76 | 0 | my $month = shift; | |||||||||||||||||||||||||||
| 77 | 0 | my %opts = ( service_id => $self->id ); | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($year && $month) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$year and $month
MC/DC0%0/2
$year and $month
$year
$month
Truth table0%0/3
A and B
A= $yearB= $month
| |||||||||||||||||||||||||||||
| 79 | 0 | $opts{year} = $year; | |||||||||||||||||||||||||||
| 80 | 0 | $opts{month} = $month; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 0 | return $self->_fetcher->_get('Net::Fastly::Invoice', %opts); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head2 purge_all | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Purge all assets from this service. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||||||||||
| 91 | sub purge_all { | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
purge_all: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 0 | return $self->_fetcher->client->_post($self->_get_path($self->id)."/purge_all"); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head2 purge_by_key <key> | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Purge anything with the specific key from the given service. Requires an API key. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | You can optionally pass in a true value to enable "soft" purging e.g | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | $service->purge_by_key($key, 1); | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | See L<https://docs.fastly.com/guides/purging/soft-purges> | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||
| 107 | sub purge_by_key { | ||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
purge_by_key: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | 0 | my $key = shift; | |||||||||||||||||||||||||||
| 110 | 0 | my $soft = shift; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | unless ($self->_fetcher->client->key_authed) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | die ("Purging by key requires API key authentication."); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | return $self->_fetcher->client->_post($self->_get_path($self->id)."/purge/$key", headers => { 'Fastly-Soft-Purge' => $soft }); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head2 versions | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | Get a sorted array of all the versions that this service has had. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||||||||
| 124 | sub versions { | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
versions: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 0 | my $fetcher = $self->_fetcher; | |||||||||||||||||||||||||||
| 127 | 0 | ▶ | my @versions = map { Net::Fastly::Version->new($fetcher, %$_) } @{$self->{versions}||{}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | return sort { $a->number <=> $b->number } @versions; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head2 version | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | Get the current version of this service. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =cut | ||||||||||||||||||||||||||||
| 136 | sub version { | ||||||||||||||||||||||||||||
| 137 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | 0 | my @list = $self->versions; | |||||||||||||||||||||||||||
| 139 | 0 | return $list[-1]; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head2 details | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | A deep hash of nested details | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||
| 147 | sub details { | ||||||||||||||||||||||||||||
| 148 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
details: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 0 | $self->_fetcher->client->_get($self->_get_path($self->id)."/details", @_); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | package Net::Fastly; | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | sub search_services { | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
search_services: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 0 | my %opts = @_; | |||||||||||||||||||||||||||
| 158 | 0 | my $class = "Net::Fastly::Service"; | |||||||||||||||||||||||||||
| 159 | 0 | my $hash = $self->client->_get($class->_post_path."/search", %opts); | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | return undef unless $hash; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | return $class->new($self, %$hash); | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | 5 | 1; | |||||||||||||||||||||||||||