| 1 | package Git::Repository::Plugin::Blame::Line; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Git::Repository::Plugin::Blame::Line - Store the git blame information for a line of code. | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 VERSION | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | Version 1.3.0 | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 9 | our $VERSION = '1.3.0'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | use Git::Repository::Plugin::Blame::Line; | ||||||||||||||||||||||||||||
| 27 | my $line = Git::Repository::Plugin::Blame::Line->new( | ||||||||||||||||||||||||||||
| 28 | line_number => $line_number, | ||||||||||||||||||||||||||||
| 29 | line => $line, | ||||||||||||||||||||||||||||
| 30 | commit_attributes => \%commit_attributes, | ||||||||||||||||||||||||||||
| 31 | commit_id => $commit_id, | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | print "The line number is " . $line->get_line_number() . "\n"; | ||||||||||||||||||||||||||||
| 35 | print "The line is " . $line->get_line() . "\n"; | ||||||||||||||||||||||||||||
| 36 | print "The commit ID is " . $line->get_commit_id() . "\n"; | ||||||||||||||||||||||||||||
| 37 | print "The commit attributes are: \n"; | ||||||||||||||||||||||||||||
| 38 | while ( my ( $name, $value ) = each( %{ $line->get_commit_attributes() } ) ) | ||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | print " - $name: $value\n"; | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | This module stores the git blame information for a line of code. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head1 METHODS | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head2 new() | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | Create a new Git::Repository::Plugin::Blame::Line object. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | my $line = Git::Repository::Plugin::Blame::Line->new( | ||||||||||||||||||||||||||||
| 56 | line_number => $line_number, | ||||||||||||||||||||||||||||
| 57 | line => $line, | ||||||||||||||||||||||||||||
| 58 | commit_attributes => \%commit_attributes, | ||||||||||||||||||||||||||||
| 59 | commit_id => $commit_id, | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | All parameters are mandatory: | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =over 4 | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =item * 'line_number' | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | The number of this line in the file that git blame was applied to. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =item * 'line' | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | The text/code of this line in the file that git blame was applied to. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =item * 'commit_attributes' | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | A hashref of attributes for the last commit that modified this line. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =item * 'commit_id' | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | The ID of the last commit that modified this line. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =back | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub new | ||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||
| 88 | 32 | ▶ | my ( $class, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # Verify parameters. | ||||||||||||||||||||||||||||
| 91 | 32 | foreach my $arg ( qw( line_number commit_id ) ) | |||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | croak "The argument '$arg' must be defined to create a Git::Repository::Plugin::Blame::Line object" | ||||||||||||||||||||||||||||
| 94 | 63 | ▶ | if !defined( $args{$arg} ) || ( $args{$arg} eq '' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $args{$arg} or $args{$arg} eq ""
MC/DC50%1/2
not defined $args{$arg} or $args{$arg} eq ""
not defined $args{$arg}
$args{$arg} eq ""
Truth table66%2/3
not(A) or B
A= not defined $args{$arg}B= $args{$arg} eq ""
| |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | croak "The argument 'line' must be defined to create a Git::Repository::Plugin::Blame::Line object" | ||||||||||||||||||||||||||||
| 97 | 30 | ▶ | if !defined( $args{'line'} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | croak "The argument 'line_number' must be a strictly positive integer" | ||||||||||||||||||||||||||||
| 100 | 29 | ▶ | if $args{'line_number'} !~ /^\d+$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 28 | my $commit_attributes = $args{'commit_attributes'}; | |||||||||||||||||||||||||||
| 103 | 28 | ▶ | croak "The argument 'commit_attributes' must be a hashref to create a Git::Repository::Plugin::Blame::Line object" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $commit_attributes or ref $commit_attributes ne "HASH"
MC/DC50%1/2
not defined $commit_attributes or ref $commit_attributes ne "HASH"
not defined $commit_attributes
ref $commit_attributes ne "HASH"
Truth table66%2/3
not(A) or B
A= not defined $commit_attributesB= ref $commit_attributes ne "HASH"
| |||||||||||||||||||||||||||||
| 104 | if !defined( $commit_attributes ) || ( ref( $commit_attributes ) ne 'HASH' ); | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # Clean emails in commit attributes. | ||||||||||||||||||||||||||||
| 107 | 27 | foreach my $name ( keys %$commit_attributes ) | |||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||
| 109 | 232 | ▶ | next unless $name =~ /^(?:author|committer)-mail$/x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 43 | $commit_attributes->{ $name } =~ s/^<//; | |||||||||||||||||||||||||||
| 111 | 43 | $commit_attributes->{ $name } =~ s/>$//; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # Create and return the object. | ||||||||||||||||||||||||||||
| 115 | return bless( | ||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||
| 117 | line_number => $args{'line_number'}, | ||||||||||||||||||||||||||||
| 118 | line => $args{'line'}, | ||||||||||||||||||||||||||||
| 119 | commit_attributes => $args{'commit_attributes'}, | ||||||||||||||||||||||||||||
| 120 | 27 | commit_id => $args{'commit_id'}, | |||||||||||||||||||||||||||
| 121 | }, | ||||||||||||||||||||||||||||
| 122 | $class | ||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head2 get_line_number() | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | Return the number of this line in the file that git blame was applied to. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | my $line_number = $line->get_line_number(); | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =cut | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | sub get_line_number | ||||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||
| 137 | 5 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_line_number: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 5 | return $self->{'line_number'}; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =head2 get_line() | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | Return the text/code of this line in the file that git blame was applied to. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | my $line = $line->get_line(); | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | sub get_line | ||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||
| 153 | 1 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_line: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 1 | return $self->{'line'}; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head2 get_commit_id() | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Return the SHA-1 of the last commit that modified this line. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | my $commit_id = $line->get_commit_id(); | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | sub get_commit_id | ||||||||||||||||||||||||||||
| 168 | { | ||||||||||||||||||||||||||||
| 169 | 5 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_commit_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 5 | return $self->{'commit_id'}; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =head2 get_commit_attributes() | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | Return the hashref of attributes for the last commit that modified this line. | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | my $commit_attributes = $line->get_commit_attributes(); | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =cut | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | sub get_commit_attributes | ||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||
| 185 | 14 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_commit_attributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 14 | return $self->{'commit_attributes'}; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =head1 BUGS | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | Please report any bugs or feature requests through the web interface at | ||||||||||||||||||||||||||||
| 194 | L<https://github.com/guillaumeaubert/Git-Repository-Plugin-Blame/issues>. | ||||||||||||||||||||||||||||
| 195 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 196 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | perldoc Git::Repository::Plugin::Blame::Line | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | You can also look for information at: | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =over 4 | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =item * GitHub (report bugs there) | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | L<https://github.com/guillaumeaubert/Git-Repository-Plugin-Blame/issues> | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | L<http://annocpan.org/dist/Git-Repository-Plugin-Blame> | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | L<http://cpanratings.perl.org/d/Git-Repository-Plugin-Blame> | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =item * MetaCPAN | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | L<https://metacpan.org/release/Git-Repository-Plugin-Blame> | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =back | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>, | ||||||||||||||||||||||||||||
| 232 | C<< <aubertg at cpan.org> >>. | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | Copyright 2012-2015 Guillaume Aubert. | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | This program is free software: you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 240 | the terms of the GNU General Public License version 3 as published by the Free | ||||||||||||||||||||||||||||
| 241 | Software Foundation. | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||||||||||||||||||||||||||||
| 244 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||||||||||||||||||||
| 245 | PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | You should have received a copy of the GNU General Public License along with | ||||||||||||||||||||||||||||
| 248 | this program. If not, see http://www.gnu.org/licenses/ | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | =cut | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 9 | 1; | |||||||||||||||||||||||||||