| 1 | package Git::Repository::Plugin::Blame::Cache; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Data::Validate::Type; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | 6 | our $VERSION = '1.2.3'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 6 | 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 | ▶ | my ( $class, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 8 | my $repository = delete( $args{'repository'} ); | |||||||||||||||||||||||||||
| 82 | 8 | ▶ | croak 'The following arguments are not valid: ' . join( ',', keys %args ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | if scalar( keys %args ) != 0; | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 8 | ▶ | croak 'The "repository" argument is mandatory' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $repository or $repository eq ""
MC/DC50%1/2
not defined $repository or $repository eq ""
not defined $repository
$repository eq ""
Truth table66%2/3
not(A) or B
A= not defined $repositoryB= $repository eq ""
| |||||||||||||||||||||||||||||
| 86 | if !defined( $repository ) || $repository eq ''; | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 7 | ▶ | if ( !defined( $CACHE->{ $repository } ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||
| 90 | 6 | $CACHE->{ $repository } = bless( | |||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||
| 92 | repository => $repository, | ||||||||||||||||||||||||||||
| 93 | files => {}, | ||||||||||||||||||||||||||||
| 94 | }, | ||||||||||||||||||||||||||||
| 95 | $class, | ||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 7 | 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 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_repository: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 1 | 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<git blame> output. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =back | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =cut | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | sub get_blame_lines | ||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||
| 141 | 5 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_blame_lines: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 5 | my $file = delete( $args{'file'} ); | |||||||||||||||||||||||||||
| 143 | 5 | ▶ | croak 'The following arguments are not valid: ' . join( ',', keys %args ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | if scalar( keys %args ) != 0; | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 5 | ▶ | croak 'The "file" argument is mandatory' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $file or $file eq ""
MC/DC50%1/2
not defined $file or $file eq ""
not defined $file
$file eq ""
Truth table66%2/3
not(A) or B
A= not defined $fileB= $file eq ""
| |||||||||||||||||||||||||||||
| 147 | if !defined( $file ) || ( $file eq '' ); | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 4 | return $self->{'files'}->{ $file }; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head2 set_blame_lines() | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Store in the cache the output of C<git blame> 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<git blame> 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 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set_blame_lines: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 181 | 6 | my $file = delete( $args{'file'} ); | |||||||||||||||||||||||||||
| 182 | 6 | my $blame_lines = delete( $args{'blame_lines'} ); | |||||||||||||||||||||||||||
| 183 | 6 | ▶ | croak 'The following arguments are not valid: ' . join( ',', keys %args ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | if scalar( keys %args ) != 0; | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 6 | ▶ | croak 'The "file" argument is mandatory' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $file or $file eq ""
MC/DC50%1/2
not defined $file or $file eq ""
not defined $file
$file eq ""
Truth table66%2/3
not(A) or B
A= not defined $fileB= $file eq ""
| |||||||||||||||||||||||||||||
| 187 | if !defined( $file ) || $file eq ''; | ||||||||||||||||||||||||||||
| 188 | 5 | ▶ | croak 'The "blame_lines" argument is mandatory' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | if !defined( $blame_lines ); | ||||||||||||||||||||||||||||
| 190 | 4 | ▶ | croak 'The "blame_lines" argument must be an arrayref' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | if !Data::Validate::Type::is_arrayref( $blame_lines ); | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 3 | $self->{'files'}->{ $file } = $blame_lines; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 3 | return; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =head1 BUGS | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | Please report any bugs or feature requests through the web interface at | ||||||||||||||||||||||||||||
| 202 | L<https://github.com/guillaumeaubert/Git-Repository-Plugin-Blame/issues>. | ||||||||||||||||||||||||||||
| 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<https://github.com/guillaumeaubert/Git-Repository-Plugin-Blame/issues> | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | L<http://annocpan.org/dist/Git-Repository-Plugin-Blame> | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | L<http://cpanratings.perl.org/d/Git-Repository-Plugin-Blame> | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | =item * MetaCPAN | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | L<https://metacpan.org/release/Git-Repository-Plugin-Blame> | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | =back | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>, | ||||||||||||||||||||||||||||
| 240 | C<< <aubertg at cpan.org> >>. | ||||||||||||||||||||||||||||
| 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 | 6 | 1; | |||||||||||||||||||||||||||