blib/lib/Net/Fastly/Service.pm

filter: Statementstmt 17.7% 8 / 45 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 20.0% 2 / 10 Podpod 100% 7 / 7 totaltotal 21.7% 17 / 78 CC 7 SCAR 18.9
CC
7
Cov
14%
stats
12.0
invoice
12.0
versions
6.0
CRAP 6.6
« blib/lib/Net/Fastly/Invoice.pm ↑ Summary Build »
1 package Net::Fastly::Service;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw(Net::Fastly::Model);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 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'
l!l
00
MC/DC0%0/1
shift() || 'all'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
59 0 my %opts = @_;
60 0 ▶ die "Unknown stats type $type" unless grep { $_ eq $type } qw(minutely hourly daily all);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $type;} "minutely", "hourly", "daily", "all" 0 0 0
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
BranchTrueFalseTotal
if ($year and $month) 0 0 0
Condition0%0/3
$year and $month
!ll&&!rl&&r
000
MC/DC0%0/2
$year and $month
$year $month
Truth table0%0/3
A and B
A= $yearB= $month
ABresult
0X0
100
111
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.
99  
100 =cut
101 sub purge_by_key {
102 0 ▶ my $self = shift;
Subroutine purge_by_key: not called CC=1 SCAR=6.9
Pod documented
103 0 my $key = shift;
104 0 return $self->_fetcher->client->_post($self->_get_path($self->id)."/purge/$key");
105 }
106  
107 =head2 versions
108  
109 Get a sorted array of all the versions that this service has had.
110  
111 =cut
112 sub versions {
113 0 ▶ my $self = shift;
Subroutine versions: not called CC=2 SCAR=17.9
Pod documented
114 0 my $fetcher = $self->_fetcher;
115 0 ▶ my @versions = map { Net::Fastly::Version->new($fetcher, %$_) } @{$self->{versions}||{}};
Branch: 1 branch
BranchTrueFalseTotal
$self->{"versions"} or {} 0 0 0
116 0 return sort { $a->number <=> $b->number } @versions;
117 }
118  
119 =head2 version
120  
121 Get the current version of this service.
122  
123 =cut
124 sub version {
125 0 ▶ my $self = shift;
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
126 0 my @list = $self->versions;
127 0 return $list[-1];
128 }
129  
130 =head2 details
131  
132 A deep hash of nested details
133  
134 =cut
135 sub details {
136 0 ▶ my $self = shift;
Subroutine details: not called CC=1 SCAR=6.9
Pod documented
137 0 $self->_fetcher->client->_get($self->_get_path($self->id)."/details", @_);
138 }
139  
140  
141 package Net::Fastly;
142  
143 sub search_services {
144 0 ▶ my $self = shift;
Subroutine search_services: not called CC=2 SCAR=17.9
145 0 my %opts = @_;
146 0 my $class = "Net::Fastly::Service";
147 0 my $hash = $self->client->_get($class->_post_path."/search", %opts);
148 0 ▶ return undef unless $hash;
Branch: 1 branch
BranchTrueFalseTotal
unless $hash 0 0 0
149 0 return $class->new($self, %$hash);
150 }
151 1 1;
« blib/lib/Net/Fastly/Invoice.pm ↑ Summary Build »