line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::Repository::Plugin::Blame::Cache; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
23451
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
202
|
|
4
|
6
|
|
|
6
|
|
28
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
140
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
29
|
use Carp; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
344
|
|
7
|
6
|
|
|
6
|
|
3298
|
use Data::Validate::Type; |
|
6
|
|
|
|
|
50395
|
|
|
6
|
|
|
|
|
2239
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Git::Repository::Plugin::Blame::Cache - Cache the output of C<< Git::Repository->blame() >>. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 1.2.3 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '1.2.3'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $CACHE = {}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Git::Repository::Plugin::Blame::Cache; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Instantiate the cache for a given repository. |
31
|
|
|
|
|
|
|
my $cache = Git::Repository::Plugin::Blame::Cache->new( |
32
|
|
|
|
|
|
|
repository => $repository, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $repository = $cache->get_repository(); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Cache blame lines. |
38
|
|
|
|
|
|
|
$cache->set_blame_lines( |
39
|
|
|
|
|
|
|
file => $file, |
40
|
|
|
|
|
|
|
blame_lines => $blame_lines, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Retrieve blame lines from the cache. |
44
|
|
|
|
|
|
|
my $blame_lines = $cache->get_blame_lines( |
45
|
|
|
|
|
|
|
file => $file, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 DESCRIPTION |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Cache the output of C<< Git::Repository::Plugin::Blame->blame() >> and |
52
|
|
|
|
|
|
|
C<< Git::Repository->blame() >> by extension. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 METHODS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 new() |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Return a cache object for the specified repository. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $cache = Git::Repository::Plugin::Blame::Cache->new( |
62
|
|
|
|
|
|
|
repository => $repository, |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Arguments: |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=over 4 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item * repository (mandatory) |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
A unique way to identify a repository. Typically, the root path of the |
72
|
|
|
|
|
|
|
repository. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=back |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub new |
79
|
|
|
|
|
|
|
{ |
80
|
8
|
|
|
8
|
1
|
4303
|
my ( $class, %args ) = @_; |
81
|
8
|
|
|
|
|
22
|
my $repository = delete( $args{'repository'} ); |
82
|
8
|
50
|
|
|
|
37
|
croak 'The following arguments are not valid: ' . join( ',', keys %args ) |
83
|
|
|
|
|
|
|
if scalar( keys %args ) != 0; |
84
|
|
|
|
|
|
|
|
85
|
8
|
100
|
66
|
|
|
78
|
croak 'The "repository" argument is mandatory' |
86
|
|
|
|
|
|
|
if !defined( $repository ) || $repository eq ''; |
87
|
|
|
|
|
|
|
|
88
|
7
|
100
|
|
|
|
24
|
if ( !defined( $CACHE->{ $repository } ) ) |
89
|
|
|
|
|
|
|
{ |
90
|
6
|
|
|
|
|
34
|
$CACHE->{ $repository } = bless( |
91
|
|
|
|
|
|
|
{ |
92
|
|
|
|
|
|
|
repository => $repository, |
93
|
|
|
|
|
|
|
files => {}, |
94
|
|
|
|
|
|
|
}, |
95
|
|
|
|
|
|
|
$class, |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
7
|
|
|
|
|
42
|
return $CACHE->{ $repository }; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 get_repository() |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Return the unique identifier for the repository. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $repository = $cache->get_repository(); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub get_repository |
112
|
|
|
|
|
|
|
{ |
113
|
1
|
|
|
1
|
1
|
2
|
my ( $self ) = @_; |
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
|
|
5
|
return $self->{'repository'}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 get_blame_lines() |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Retrieve git blame lines from the cache (if they exist) for a given file. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $blame_lines = $cache->get_blame_lines( |
124
|
|
|
|
|
|
|
file => $file, |
125
|
|
|
|
|
|
|
); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Arguments: |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=over 4 |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item * file (mandatory) |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
The file for which you want the cached C output. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=back |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub get_blame_lines |
140
|
|
|
|
|
|
|
{ |
141
|
5
|
|
|
5
|
1
|
421
|
my ( $self, %args ) = @_; |
142
|
5
|
|
|
|
|
12
|
my $file = delete( $args{'file'} ); |
143
|
5
|
50
|
|
|
|
16
|
croak 'The following arguments are not valid: ' . join( ',', keys %args ) |
144
|
|
|
|
|
|
|
if scalar( keys %args ) != 0; |
145
|
|
|
|
|
|
|
|
146
|
5
|
100
|
66
|
|
|
47
|
croak 'The "file" argument is mandatory' |
147
|
|
|
|
|
|
|
if !defined( $file ) || ( $file eq '' ); |
148
|
|
|
|
|
|
|
|
149
|
4
|
|
|
|
|
31
|
return $self->{'files'}->{ $file }; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 set_blame_lines() |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Store in the cache the output of C for a given file. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
$cache->set_blame_lines( |
158
|
|
|
|
|
|
|
file => $file, |
159
|
|
|
|
|
|
|
blame_lines => $blame_lines, |
160
|
|
|
|
|
|
|
); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Arguments: |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=over 4 |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * file (mandatory) |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
The file for which you are caching the C output. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * blame_lines (mandatory) |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
The output of C<< Git::Repository::Plugin::Blame->blame() >>. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=back |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub set_blame_lines |
179
|
|
|
|
|
|
|
{ |
180
|
6
|
|
|
6
|
1
|
166
|
my ( $self, %args ) = @_; |
181
|
6
|
|
|
|
|
14
|
my $file = delete( $args{'file'} ); |
182
|
6
|
|
|
|
|
12
|
my $blame_lines = delete( $args{'blame_lines'} ); |
183
|
6
|
50
|
|
|
|
20
|
croak 'The following arguments are not valid: ' . join( ',', keys %args ) |
184
|
|
|
|
|
|
|
if scalar( keys %args ) != 0; |
185
|
|
|
|
|
|
|
|
186
|
6
|
100
|
66
|
|
|
88
|
croak 'The "file" argument is mandatory' |
187
|
|
|
|
|
|
|
if !defined( $file ) || $file eq ''; |
188
|
5
|
100
|
|
|
|
20
|
croak 'The "blame_lines" argument is mandatory' |
189
|
|
|
|
|
|
|
if !defined( $blame_lines ); |
190
|
4
|
100
|
|
|
|
23
|
croak 'The "blame_lines" argument must be an arrayref' |
191
|
|
|
|
|
|
|
if !Data::Validate::Type::is_arrayref( $blame_lines ); |
192
|
|
|
|
|
|
|
|
193
|
3
|
|
|
|
|
80
|
$self->{'files'}->{ $file } = $blame_lines; |
194
|
|
|
|
|
|
|
|
195
|
3
|
|
|
|
|
12
|
return; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 BUGS |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
202
|
|
|
|
|
|
|
L. |
203
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
204
|
|
|
|
|
|
|
your bug as I make changes. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 SUPPORT |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
perldoc Git::Repository::Plugin::Blame |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
You can also look for information at: |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=over 4 |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * GitHub (report bugs there) |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
L |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
L |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item * CPAN Ratings |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
L |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item * MetaCPAN |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
L |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=back |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 AUTHOR |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
L, |
240
|
|
|
|
|
|
|
C<< >>. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Copyright 2012-2014 Guillaume Aubert. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it under |
248
|
|
|
|
|
|
|
the terms of the GNU General Public License version 3 as published by the Free |
249
|
|
|
|
|
|
|
Software Foundation. |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY |
252
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
253
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the GNU General Public License for more details. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with |
256
|
|
|
|
|
|
|
this program. If not, see http://www.gnu.org/licenses/ |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=cut |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
1; |