File Coverage

inc/GitVersion.pm
Criterion Covered Total %
statement 9 13 69.2
branch 2 4 50.0
condition 1 6 16.6
subroutine 2 4 50.0
pod 0 3 0.0
total 14 30 46.6


line stmt bran cond sub pod time code
1             #
2             # This file is part of Git-DescribeVersion
3             #
4             # This software is copyright (c) 2010 by Randy Stauner.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9             package # no_index
10             inc::GitVersion;
11              
12             # 1.5 renamed git-repo-config to git-config
13             # 1.5.5 added --match to git-describe
14             our @MIN = qw( 1 5 5 );
15              
16             sub import {
17 0     0   0 shift->require_minimum;
18             }
19              
20             sub check_minimum {
21 6     6 0 1646 my ($class, $version) = @_;
22 6   33     17 $version ||= $class->version;
23              
24 6         65 my @parts = split(/\./, ($version =~ m/(?:git\sversion\s)?(\d+(\.\d+)*)/)[0]);
25              
26 6         23 foreach my $i ( 0 .. $#MIN ){
27             # if not equal
28 14 100       53 if( my $cmp = $parts[$i] <=> $MIN[$i] ){
29             # return true if version is sufficient (greater) false if not (lesser)
30 5         35 return $cmp > 0;
31             }
32             }
33              
34 1         7 return 1; # not less or greater, must be equal
35             }
36              
37             sub require_minimum {
38 0     0 0 0 my ($class, $version) = @_;
39 0   0     0 $version ||= $class->version;
40 0 0       0 $class->check_minimum($version)
41             or die <
42             # Git version 1.5.5+ required.
43             # Found: $version
44             #
45             # If you believe this to be an error please submit a bug report
46             # including the output of `git --version`.
47             MSG
48             }
49              
50             sub version {
51 1     1 0 7055 chomp(my $v = qx/git --version/);
52 1         41 $v;
53             }
54              
55             1;