blib/lib/Git/PunchCard.pm

filter: Statementstmt 33.3% 16 / 48 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 33.3% 1 / 3 totaltotal 28.2% 22 / 78 SCAR 39.7
CC
10
Cov
25%
dir
90.0
get_card
6.0
new
2.0
CRAP 52.8
↑ Summary
1 package Git::PunchCard;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base 'Error::Helper';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Git::PunchCard - Gathers info for making punchcard style graphs for git.
12  
13 =head1 VERSION
14  
15 Version 0.0.1
16  
17 =cut
18  
19 1 our $VERSION = '0.0.1';
20  
21  
22 =head1 SYNOPSIS
23  
24 Quick summary of what the module does.
25  
26 Perhaps a little code snippet.
27  
28 use Git::PunchCard;
29 use Data::Dumper;
30 use Text::Table;
31
32 my $gpc = Git::PunchCard->new();
33
34 $gpc->dir($some_git_repo_dir);
35 if ( $gpc->error ){
36 print "Could not process the directory.\n";
37 }
38
39 my $card=$gpc->get_card;
40
41 print Dumper( $card );
42
43 # The various keys for the hashes.
44 my @days=('Sun','Mon','Tue','Wed','Thu','Fri','Sat', );
45 my @hours=('00','01','02','03','04','05','06','07','08','09','10', '11','12','13','14','15','16','17','18','19','20','21','22','23');
46
47 # Stores the lines to for the table.
48 my @data;
49  
50 # Process each day hash in $card.
51 foreach my $day ( @days ){
52 my @line;
53
54 # Add the day coloumn to the current line of the table.
55 push( @line, $day );
56
57 # Add each hour entry to the current line of the table.
58 foreach my $hour ( @hours ){
59 push( @line, $card->{$day}{$hour} );
60 }
61
62 # Finally add the total number of entries for that day.
63 push( @line, $card->{$day}{total}.color('WHITE') );
64
65 # add the new line to the table data
66 push( @data, \@line );
67 }
68
69 # Init the Text::Table object and add our headers.
70 my $table=Text::Table->new('','00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','Total');
71  
72 # Loads the data into the table
73 $table->load( @data );
74
75 # produce some useful? output
76 print $table."\nTotal: ".$card->{total}."\n";
77  
78 =head1 METHODS
79  
80 =head2 new
81  
82 Inits the object.
83  
84 my $gpc->new;
85  
86 =cut
87  
88 sub new {
89 0 ▶ my $self={
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
90 perror=>undef,
91 error=>undef,
92 errorString=>'',
93 errorExtra=>{
94 flags=>{
95 1=>'gitError',
96 },
97 },
98 card=>{
99 total=>0,
100 max=>0,
101 Sun=>{
102 total=>0,
103 max=>0,
104 '00'=>0,
105 '01'=>0,
106 '02'=>0,
107 '03'=>0,
108 '04'=>0,
109 '05'=>0,
110 '06'=>0,
111 '07'=>0,
112 '08'=>0,
113 '09'=>0,
114 '10'=>0,
115 '11'=>0,
116 '12'=>0,
117 '13'=>0,
118 '14'=>0,
119 '15'=>0,
120 '16'=>0,
121 '17'=>0,
122 '18'=>0,
123 '19'=>0,
124 '20'=>0,
125 '21'=>0,
126 '22'=>0,
127 '23'=>0,
128 },
129 Mon=>{
130 total=>0,
131 max=>0,
132 '00'=>0,
133 '01'=>0,
134 '02'=>0,
135 '03'=>0,
136 '04'=>0,
137 '05'=>0,
138 '06'=>0,
139 '07'=>0,
140 '08'=>0,
141 '09'=>0,
142 '10'=>0,
143 '11'=>0,
144 '12'=>0,
145 '13'=>0,
146 '14'=>0,
147 '15'=>0,
148 '16'=>0,
149 '17'=>0,
150 '18'=>0,
151 '19'=>0,
152 '20'=>0,
153 '21'=>0,
154 '22'=>0,
155 '23'=>0,
156 },
157 Tue=>{
158 total=>0,
159 max=>0,
160 '00'=>0,
161 '01'=>0,
162 '02'=>0,
163 '03'=>0,
164 '04'=>0,
165 '05'=>0,
166 '06'=>0,
167 '07'=>0,
168 '08'=>0,
169 '09'=>0,
170 '10'=>0,
171 '11'=>0,
172 '12'=>0,
173 '13'=>0,
174 '14'=>0,
175 '15'=>0,
176 '16'=>0,
177 '17'=>0,
178 '18'=>0,
179 '19'=>0,
180 '20'=>0,
181 '21'=>0,
182 '22'=>0,
183 '23'=>0,
184 },
185 Wed=>{
186 total=>0,
187 max=>0,
188 '00'=>0,
189 '01'=>0,
190 '02'=>0,
191 '03'=>0,
192 '04'=>0,
193 '05'=>0,
194 '06'=>0,
195 '07'=>0,
196 '08'=>0,
197 '09'=>0,
198 '10'=>0,
199 '11'=>0,
200 '12'=>0,
201 '13'=>0,
202 '14'=>0,
203 '15'=>0,
204 '16'=>0,
205 '17'=>0,
206 '18'=>0,
207 '19'=>0,
208 '20'=>0,
209 '21'=>0,
210 '22'=>0,
211 '23'=>0,
212 },
213 Thu=>{
214 total=>0,
215 max=>0,
216 '00'=>0,
217 '01'=>0,
218 '02'=>0,
219 '03'=>0,
220 '04'=>0,
221 '05'=>0,
222 '06'=>0,
223 '07'=>0,
224 '08'=>0,
225 '09'=>0,
226 '10'=>0,
227 '11'=>0,
228 '12'=>0,
229 '13'=>0,
230 '14'=>0,
231 '15'=>0,
232 '16'=>0,
233 '17'=>0,
234 '18'=>0,
235 '19'=>0,
236 '20'=>0,
237 '21'=>0,
238 '22'=>0,
239 '23'=>0,
240 },
241 Fri=>{
242 total=>0,
243 max=>0,
244 '00'=>0,
245 '01'=>0,
246 '02'=>0,
247 '03'=>0,
248 '04'=>0,
249 '05'=>0,
250 '06'=>0,
251 '07'=>0,
252 '08'=>0,
253 '09'=>0,
254 '10'=>0,
255 '11'=>0,
256 '12'=>0,
257 '13'=>0,
258 '14'=>0,
259 '15'=>0,
260 '16'=>0,
261 '17'=>0,
262 '18'=>0,
263 '19'=>0,
264 '20'=>0,
265 '21'=>0,
266 '22'=>0,
267 '23'=>0,
268 },
269 Sat=>{
270 total=>0,
271 max=>0,
272 '00'=>0,
273 '01'=>0,
274 '02'=>0,
275 '03'=>0,
276 '04'=>0,
277 '05'=>0,
278 '06'=>0,
279 '07'=>0,
280 '08'=>0,
281 '09'=>0,
282 '10'=>0,
283 '11'=>0,
284 '12'=>0,
285 '13'=>0,
286 '14'=>0,
287 '15'=>0,
288 '16'=>0,
289 '17'=>0,
290 '18'=>0,
291 '19'=>0,
292 '20'=>0,
293 '21'=>0,
294 '22'=>0,
295 '23'=>0,
296 },
297 },
298 };
299 0 bless $self;
300  
301 0 return $self;
302 }
303  
304  
305 =head2 card
306  
307 One argument is taken and that is the directory to parse in.
308  
309 If one is not passed, the current directory will be used.
310  
311 IF this is called multiple times, each new instance will be added
312 to the current values.
313  
314 $gpc->dir( $dir )
315 if ( $gpc->error ){
316 print "Errored!\n";
317 }
318  
319 =cut
320  
321 sub dir {
322 0 ▶ my $self=$_[0];
Subroutine dir: not called CC=9 SCAR=45.0
Pod undocumented
323 0 my $dir=$_[1];
324  
325 0 ▶ if( ! $self->errorblank ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
326 0 return undef;
327 }
328  
329 0 ▶ if (! defined( $dir ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dir) 0 0 0
330 0 $dir=getcwd;
331 }
332  
333 0 chdir( $dir );
334  
335 0 my $output=`env LC_ALL=C git log --pretty=format:"%ad" --date=local --date=format:'%a %H'`;
336 0 ▶ if ( $? != 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
337 0 $self->{error}=1;
338 0 $self->{errorString}='"--pretty=format:\"%ad\" --date=local --date=format:\'%a %H\'" exited with a non-zero value';
339 0 $self->warn;
340 }
341  
342 0 my @lines=split(/\n/, $output);
343  
344 0 foreach my $line ( @lines ){
345 0 my ($day, $hour)=split(/\ +/, $line);
346  
347 # Should never be undef, but just make sure.
348 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $day and defined $hour) 0 0 0
Condition0%0/3
defined $day and defined $hour
!ll&&!rl&&r
000
MC/DC0%0/2
defined $day and defined $hour
defined $day defined $hour
Truth table0%0/3
A and B
A= defined $dayB= defined $hour
ABresult
0X0
100
111
349 defined( $day ) &&
350 defined( $hour )
351 ){
352 # increment the one we hit on
353 0 $self->{card}{$day}{$hour}++;
354 0 $self->{card}{$day}{total}++;
355 0 $self->{card}{total}++;
356  
357 0 ▶ if ( $self->{card}{$day}{$hour} > $self->{card}{max}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"card"}{$day}{$hour} > $self->{"card"}{"max"}) 0 0 0
358 0 $self->{card}{max}=$self->{card}{$day}{$hour};
359 }
360 0 ▶ if ( $self->{card}{$day}{$hour} > $self->{card}{$day}{max}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"card"}{$day}{$hour} > $self->{"card"}{$day}{"max"}) 0 0 0
361 0 $self->{card}{$day}{max}=$self->{card}{$day}{$hour};
362 }
363 }
364 }
365  
366 0 return 1;
367 }
368  
369 =head get_card
370  
371 This returns the current card data.
372  
373 The returned value is a hashref.
374  
375 The first level keys are the three letter
376 day names the the second level keys are the
377 two digit hour.
378  
379 There are two special keys 'total' and 'max'.
380  
381 'total' represents the total level of commits. So
382 at the primary level it is all the commits made to that
383 repo while and the secondary level it is all the comits
384 made to that repo on that day of the week.
385  
386 'max' is the largest number of commits made. At the primary
387 level it is any hour on any day of the week while at the secondary
388 level it is the max made during any given hour that day.
389  
390 For examples of making use of this, see the SYNOPSIS or check
391 out the script punchard-git.
392  
393 my $card=$gpc->get_card;
394  
395 =cut
396  
397 sub get_card{
398 0 ▶ my $self=$_[0];
Subroutine get_card: not called CC=2 SCAR=17.9
Pod undocumented
399 0 my $dir=$_[1];
400  
401 0 ▶ if( ! $self->errorblank ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
402 0 return undef;
403 }
404  
405 0 return $self->{card};
406 }
407  
408 =head1 ERROR NUMBERS/FLAGS
409  
410 Error handling is provided by L<Error::Helper>.
411  
412 =head2 1 / gitError
413  
414 Git exited with a non-zero value.
415  
416 =head1 AUTHOR
417  
418 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
419  
420 =head1 BUGS
421  
422 Please report any bugs or feature requests to C<bug-git-punchcard at rt.cpan.org>, or through
423 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Git-PunchCard>. I will be notified, and then you'll
424 automatically be notified of progress on your bug as I make changes.
425  
426  
427  
428  
429 =head1 SUPPORT
430  
431 You can find documentation for this module with the perldoc command.
432  
433 perldoc Git::PunchCard
434  
435  
436 You can also look for information at:
437  
438 =over 4
439  
440 =item * RT: CPAN's request tracker (report bugs here)
441  
442 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Git-PunchCard>
443  
444 =item * AnnoCPAN: Annotated CPAN documentation
445  
446 L<http://annocpan.org/dist/Git-PunchCard>
447  
448 =item * CPAN Ratings
449  
450 L<https://cpanratings.perl.org/d/Git-PunchCard>
451  
452 =item * Search CPAN
453  
454 L<https://metacpan.org/release/Git-PunchCard>
455  
456 =item * Primary Repo
457  
458 L<https://gitea.eesdp.org/vvelox/Git-PunchCard/>
459  
460 =back
461  
462  
463 =head1 ACKNOWLEDGEMENTS
464  
465  
466 =head1 LICENSE AND COPYRIGHT
467  
468 This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
469  
470 This is free software, licensed under:
471  
472 The Artistic License 2.0 (GPL Compatible)
473  
474  
475 =cut
476  
477 1 1; # End of Git::PunchCard
↑ Summary