line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MetaCPAN::Role::Fastly; |
2
|
|
|
|
|
|
|
$MetaCPAN::Role::Fastly::VERSION = '0.06'; |
3
|
|
|
|
|
|
|
# COPY BELOW HERE INTO MetaCPAN::Role::Fastly |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
889
|
use Moose::Role; |
|
1
|
|
|
|
|
353167
|
|
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
4932
|
use Net::Fastly 1.05; |
|
1
|
|
|
|
|
148932
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
9
|
use Carp; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
59
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# For dzil [AutoPreq] |
10
|
1
|
|
|
1
|
|
494
|
use MooseX::Fastly::Role 0.01; |
|
1
|
|
|
|
|
15621
|
|
|
1
|
|
|
|
|
448
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'MooseX::Fastly::Role'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
MetaCPAN::Role::Fastly - Methods for fastly API intergration |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use MetaCPAN::Role::Fastly; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This role includes L<MooseX::Fastly::Role>. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
It also adds some purge related methods, you need to call |
27
|
|
|
|
|
|
|
L</perform_purge> to actually do the purges. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 $self->purge_surrogate_key('BAR'); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Try to use on of the more specific methods below if possible. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 $self->purge_author_key('Ether'); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub purge_author_key { |
42
|
0
|
|
|
0
|
1
|
|
my ( $self, @authors ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
for my $author (@authors) { |
45
|
0
|
|
|
|
|
|
$self->purge_surrogate_key( $self->_format_auth_key($author) ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 $self->purge_dist_key('Moose'); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub purge_dist_key { |
54
|
0
|
|
|
0
|
1
|
|
my ( $self, @dists ) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
for my $dist (@dists) { |
57
|
0
|
|
|
|
|
|
$self->purge_surrogate_key( $self->_format_dist_key($dist) ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 $self->purge_cpan_distnameinfos(\@list_of_distnameinfo_objects); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Using this array reference of L<CPAN::DistnameInfo> objects, |
64
|
|
|
|
|
|
|
the cpanid and dist name are extracted and used to build a list |
65
|
|
|
|
|
|
|
of keys to purge, the purge happens from within this method. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
An purge of B<DIST_UPDATES> also happens when this method is called. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
All other purging requires `finalize` to be implimented so it |
70
|
|
|
|
|
|
|
can be wrapped with a I<before> and called. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#cdn_purge_cpan_distnameinfos |
75
|
|
|
|
|
|
|
sub purge_cpan_distnameinfos { |
76
|
0
|
|
|
0
|
1
|
|
my ( $self, $dist_list ) = @_; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my %purge_keys; |
79
|
0
|
|
|
|
|
|
foreach my $dist ( @{$dist_list} ) { |
|
0
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
croak "Must be CPAN::DistnameInfo" |
82
|
|
|
|
|
|
|
unless $dist->isa('CPAN::DistnameInfo'); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$purge_keys{ $self->_format_auth_key( $dist->cpanid ) } = 1; # "GBARR" |
85
|
0
|
|
|
|
|
|
$purge_keys{ $self->_format_dist_key( $dist->dist ) } |
86
|
|
|
|
|
|
|
= 1; # "CPAN-DistnameInfo" |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my @unique_to_purge = keys %purge_keys; |
91
|
0
|
|
|
|
|
|
push @unique_to_purge, 'DIST_UPDATES'; # as we have updates some dists! |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$self->purge_surrogate_key(@unique_to_purge); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
$self->perform_purges; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
has _surrogate_keys_to_purge => ( |
100
|
|
|
|
|
|
|
traits => ['Array'], |
101
|
|
|
|
|
|
|
is => 'ro', |
102
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
103
|
|
|
|
|
|
|
default => sub { [] }, |
104
|
|
|
|
|
|
|
handles => { |
105
|
|
|
|
|
|
|
purge_surrogate_key => 'push', |
106
|
|
|
|
|
|
|
has_surrogate_keys_to_purge => 'count', |
107
|
|
|
|
|
|
|
surrogate_keys_to_purge => 'elements', |
108
|
|
|
|
|
|
|
join_surrogate_keys_to_purge => 'join', |
109
|
|
|
|
|
|
|
reset_surrogate_keys => 'clear', |
110
|
|
|
|
|
|
|
}, |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub perform_purges { |
114
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Some action must have triggered a purge |
117
|
0
|
0
|
|
|
|
|
if ( $self->has_surrogate_keys_to_purge ) { |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Something changed, means we need to purge some keys |
120
|
0
|
|
|
|
|
|
my @keys = $self->surrogate_keys_to_purge(); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$self->cdn_purge_now( { keys => \@keys, } ); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Rest |
125
|
0
|
|
|
|
|
|
$self->reset_surrogate_keys(); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Needed for MC tests! |
129
|
0
|
|
|
|
|
|
return 1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 datacenters() |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub datacenters { |
138
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
139
|
0
|
|
|
|
|
|
my $net_fastly = $self->cdn_api(); |
140
|
0
|
0
|
|
|
|
|
return unless $net_fastly; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Uses the private interface as fastly client doesn't |
143
|
|
|
|
|
|
|
# have this end point yet |
144
|
0
|
|
|
|
|
|
my $datacenters = $net_fastly->client->_get('/datacenters'); |
145
|
0
|
|
|
|
|
|
return $datacenters; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub _format_dist_key { |
149
|
0
|
|
|
0
|
|
|
my ( $self, $dist ) = @_; |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
$dist = uc($dist); |
152
|
0
|
|
|
|
|
|
$dist =~ s/:/-/g; # |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
return 'dist=' . $dist; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub _format_auth_key { |
158
|
0
|
|
|
0
|
|
|
my ( $self, $author ) = @_; |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
$author = uc($author); |
161
|
0
|
|
|
|
|
|
return 'author=' . $author; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |