blib/lib/Group/Git/Cmd/SinceRelease.pm

filter: Statementstmt 40.0% 30 / 75 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 9 / 12 Podpod 100% 2 / 2 totaltotal 30.6% 41 / 134 CC 23 SCAR 47.8
CC
23
Cov
25%
since_release
210.0
_num_sort
110.0
since_release_start
2.0
CRAP 119.1
↑ Summary
1 package Group::Git::Cmd::SinceRelease;
2  
3 # Created on: 2013-05-20 09:03:03
4 # Create by: Ivan Wills
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Data::Dumper qw/Dumper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use File::chdir;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Getopt::Alt;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our $VERSION = version->new('0.0.12');
20  
21 1 my $opt = Getopt::Alt->new(
22 {
23 helper => 1,
24 help => __PACKAGE__,
25 default => {
26 min => 1,
27 },
28 },
29 [
30 'min|min-commits|m=i',
31 'name|n',
32 'no_release|no-release',
33 'latest|latest-tag',
34 'released|r',
35 'verbose|v+',
36 'quiet|q!',
37 ]
38 );
39  
40 0 ▶sub _num_sort {
Subroutine _num_sort: not called CC=10 SCAR=47.0
41 0 my $A = $a;
42 0 $A =~ s/^v(\d)/$1/;
43 0 my $B = $b;
44 0 $B =~ s/^v(\d)/$1/;
45  
46 0 ▶ if ( $A =~ /^\d+[.]\d+[.]\d+$/ && $B =~ /^\d+[.]\d+[.]\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($A =~ /^\d+[.]\d+[.]\d+$/ and $B =~ /^\d+[.]\d+[.]\d+$/) 0 0 0
Condition0%0/3
$A =~ /^\d+[.]\d+[.]\d+$/ and $B =~ /^\d+[.]\d+[.]\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$A =~ /^\d+[.]\d+[.]\d+$/ and $B =~ /^\d+[.]\d+[.]\d+$/
$A =~ /^\d+[.]\d+[.]\d+$/ $B =~ /^\d+[.]\d+[.]\d+$/
Truth table0%0/3
A and B
A= $A =~ /^\d+[.]\d+[.]\d+$/B= $B =~ /^\d+[.]\d+[.]\d+$/
ABresult
0X0
100
111
47 0 my @A = split /[.]/, $A;
48 0 my @B = split /[.]/, $B;
49 0 ▶ my $max = @A > @B ? @A : @B;
Branch: 1 branch
BranchTrueFalseTotal
@A > @B ? : 0 0 0
50  
51 0 for my $i ( 0 .. $max - 1 ) {
52 0 ▶ return $A[$i] <=> $B[$i] if $A[$i] <=> $B[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $A[$i] <=> $B[$i] 0 0 0
53 }
54 0 return 0;
55 }
56  
57 0 ▶ $A =~ s/((0+)\d+)/sprintf "%03d", $2 eq '00' ? $1 : $2 eq '0' ? $1 * 10 : $1 * 100/egxms;
Branch: 2 branches
BranchTrueFalseTotal
$2 eq '00' ? : 0 0 0
$2 eq '0' ? : 0 0 0
58 0 ▶ $B =~ s/((0+)\d+)/sprintf "%03d", $2 eq '00' ? $1 : $2 eq '0' ? $1 * 10 : $1 * 100/egxms;
Branch: 2 branches
BranchTrueFalseTotal
$2 eq '00' ? : 0 0 0
$2 eq '0' ? : 0 0 0
59 0 $A cmp $B;
60 }
61  
62 0 ▶sub since_release_start {
Subroutine since_release_start: not called CC=1 SCAR=6.9
Pod documented
63 0 $opt->process;
64 0 return;
65 }
66  
67 0 ▶sub since_release {
Subroutine since_release: not called CC=14 SCAR=53.5
Pod documented
68 0 my ($self, $name) = @_;
69  
70 0 ▶ return unless -d $name;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $name 0 0 0
71  
72 0 local $CWD = $name;
73  
74 # find the newest tag and count newer commits
75 0 my @tags = sort _num_sort grep {/^v?\d+(?:[.]\d+)*$/} map {/(.*)$/; $1} `git tag | sort -n`;
76 0 ▶ if ($opt->opt->no_release) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt->opt->no_release) { } 0 0 0
elsif (not @tags) { } 0 0 0
77 0 ▶ return "Never released" if !@tags;
Branch: 1 branch
BranchTrueFalseTotal
unless @tags 0 0 0
78 0 return;
79 }
80 elsif (!@tags) {
81 0 return;
82 }
83  
84 0 ▶ if ( $opt->opt->latest ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->opt->latest) 0 0 0
85 0 return $tags[-1];
86 }
87  
88 0 my ($sha, $time, @rest) = split /\s+/, `git log -n 1 --format=format:'%H %at' $tags[-1]`;
89  
90 0 ▶ if (!$sha) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sha) 0 0 0
91 0 warn "$name\ngit log -n 1 --format=format:'%H %at' $tags[-1]\n\n";
92 0 warn join ' ', $sha, $time, @rest;
93 0 return;
94 }
95  
96 0 ▶ my $format = @ARGV ? join(' ', @ARGV) : '--format=format:" %s"';
Branch: 1 branch
BranchTrueFalseTotal
@ARGV ? : 0 0 0
97 0 my @logged = `git log -n 100 $format $sha..HEAD`;
98  
99 0 ▶ if ($opt->opt->released) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->opt->released) 0 0 0
100 0 ▶ return "Released!" if !@logged;
Branch: 1 branch
BranchTrueFalseTotal
unless @logged 0 0 0
101 0 return;
102 }
103  
104 0 ▶ return if @logged < $opt->opt->min;
Branch: 1 branch
BranchTrueFalseTotal
if @logged < $opt->opt->min 0 0 0
105 0 ▶ my $text = $opt->opt->quiet ? '' : "Commits since last release ($tags[-1])";
Branch: 1 branch
BranchTrueFalseTotal
$opt->opt->quiet ? : 0 0 0
106 0 ▶ $text .= $opt->opt->name ? " ($tags[-1]): " : ': ';
Branch: 1 branch
BranchTrueFalseTotal
$opt->opt->name ? : 0 0 0
107  
108 0 ▶ return $text . ($opt->opt->verbose ? "\n" . join '', @logged : scalar @logged);
Branch: 1 branch
BranchTrueFalseTotal
$opt->opt->verbose ? : 0 0 0
109 }
110  
111 1 1;
112  
113 __END__
↑ Summary