blib/lib/Git/Repo/Commits.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 53 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
commits
2.0
hashes
2.0
CRAP 2.0
1 package Git::Repo::Commits;
2  
3 use warnings;
4 use strict;
5 use Carp;
6 use Git;
7  
8 use version; our $VERSION = qv('0.0.5');
9  
10 # Other recommended modules (uncomment to use):
11 # use IO::Prompt;
12 # use Perl6::Export;
13 # use Perl6::Slurp;
14 # use Perl6::Say;
15  
16  
17 # Module implementation here
18 sub new {
19 my $class = shift;
20 my $dir = shift || croak "Need a repo directory";
21 my ($repo_name) = ($dir =~ m{/([^/]+)/?$} );
22 my $repo = Git->repository (Directory => $dir);
23 my @these_revs = `cd $dir; git rev-list --all`;
24 my @commit_info;
25 for my $commit ( reverse @these_revs ) {
26 chop $commit;
27 my $commit_info = $repo->command('show', '--pretty=fuller', $commit);
28 my @files = ($commit_info =~ /\+\+\+\s+b\/(.+)/g);
29 my ($author) = ($commit_info =~ /Author:\s+(.+)/);
30 my ($commit) = ($commit_info =~ /Commit:\s+(.+)/);
31 push @commit_info, { files => \@files,
32 author => $author,
33 commit => $commit};
34 }
35 my $commits = { _repo => $dir,
36 _name => $repo_name,
37 _commits => \@commit_info,
38 _hashes => \@these_revs};
39 return bless $commits, $class;
40  
41 }
42  
43 sub commits {
44 my $self = shift;
45 return $self->{'_commits'};
46 }
47  
48 sub hashes {
49 my $self = shift;
50 return $self->{'_hashes'};
51 }
52  
53 sub name {
54 my $self = shift;
55 return $self->{'_name'};
56 }
57
58  
59 1; # Magic true value required at end of module
60 __END__
61  
62 =head1 NAME
63  
64 Git::Repo::Commits - Get all commits in a repository
65  
66  
67 =head1 VERSION
68  
69 This document describes Git::Repo::Commits version 0.0.3
70  
71  
72 =head1 SYNOPSIS
73  
74 use Git::Repo::Commits;
75  
76 my $commits = new Git::Repo::Commits /home/is/where/the/repo/is
77  
78
79 =head1 DESCRIPTION
80  
81 =head2 new $repository
82  
83 Creates an object with information about all commits
84  
85 =head2 commits
86  
87 Returns an array with commit information, an array item per commit, in
88 the shape
89  
90 { author => $author,
91 committer => $committer,
92 files => \@files }
93  
94 =head2 hashes
95  
96 Returns an array with the hashes of all commits in the repo.
97  
98 =head2 name
99  
100 Returns the name of the directory, which usually is also the name of the repo.
101  
102  
103 =head1 CONFIGURATION AND ENVIRONMENT
104  
105 Git::Repo::Commits requires no configuration files or environment
106 variables. It might be the case that git is not installed and this
107 fails, but probably not.
108  
109  
110 =head1 DEPENDENCIES
111  
112 Depends on L<Git>, which should be available either from your git
113 installation or from CPAN.
114  
115  
116  
117  
118 =head1 BUGS AND LIMITATIONS
119  
120 No bugs have been reported.
121  
122 Please report any bugs or feature requests to
123 C<bug-git-repo-commits@rt.cpan.org>, or through the web interface at
124 L<http://rt.cpan.org>, or, even better, at the
125 L<https://github.com/JJ/perl-git-commit/issues> in GitHub.
126  
127  
128 =head1 AUTHOR
129  
130 JJ C<< <JMERELO@cpan.org> >>
131  
132  
133 =head1 LICENCE AND COPYRIGHT
134  
135 Copyright (c) 2017, JJ C<< <JMERELO@cpan.org> >>. All rights reserved.
136  
137 This module is free software; you can redistribute it and/or
138 modify it under the same terms as Perl itself. See L<perlartistic>.
139  
140  
141 =head1 DISCLAIMER OF WARRANTY
142  
143 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
144 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
145 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
146 PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
147 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
148 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
149 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
150 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
151 NECESSARY SERVICING, REPAIR, OR CORRECTION.
152  
153 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
154 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
155 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
156 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
157 OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
158 THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
159 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
160 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
161 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
162 SUCH DAMAGES.