line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# vim: set ts=2 sts=2 sw=2 expandtab smarttab: |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This file is part of Git-DescribeVersion |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This software is copyright (c) 2010 by Randy Stauner. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
8
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
9
|
|
|
|
|
|
|
# |
10
|
2
|
|
|
2
|
|
24277
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
68
|
|
11
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
102
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Git::DescribeVersion::App; |
14
|
|
|
|
|
|
|
{ |
15
|
|
|
|
|
|
|
$Git::DescribeVersion::App::VERSION = '1.015'; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
BEGIN { |
18
|
2
|
|
|
2
|
|
33
|
$Git::DescribeVersion::App::AUTHORITY = 'cpan:RWSTAUNER'; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
# ABSTRACT: Run Git::DescribeVersion as one-line script |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
455
|
use Git::DescribeVersion (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
168
|
|
23
|
2
|
|
|
2
|
|
3196
|
use Getopt::Long qw(GetOptions); # core |
|
2
|
|
|
|
|
31030
|
|
|
2
|
|
|
|
|
13
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# for simplicity |
26
|
|
|
|
|
|
|
our %Defaults = %Git::DescribeVersion::Defaults; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my %get_opt_spec = map { |
29
|
|
|
|
|
|
|
my $dash = $_; |
30
|
|
|
|
|
|
|
# accept --opt_name or --opt-name (but store it in the hash as opt_name) |
31
|
|
|
|
|
|
|
# don't duplicate single words ("format=s" rather than "format|format=s") |
32
|
|
|
|
|
|
|
( $dash =~ tr/_/-/ ? "$_|$dash=s" : "$_=s" ) |
33
|
|
|
|
|
|
|
} keys %Defaults; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# simple: enable `perl -MGit::DescribeVersion::App -e run` |
36
|
|
|
|
|
|
|
sub import { |
37
|
2
|
|
|
2
|
|
618
|
no strict 'refs'; ## no critic |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
530
|
|
38
|
1
|
|
|
1
|
|
10
|
*{caller(0) . '::run'} = \&run; |
|
1
|
|
|
|
|
2102
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub options { |
42
|
|
|
|
|
|
|
# allow usage as Git::DescribeVersion::App->run() |
43
|
|
|
|
|
|
|
# (for consistency with other App's) |
44
|
|
|
|
|
|
|
# and simply discard the unused argument |
45
|
1222
|
100
|
100
|
1222
|
0
|
17020
|
shift(@_) if @_ && $_[0] eq __PACKAGE__; |
46
|
|
|
|
|
|
|
|
47
|
1222
|
|
|
|
|
1985
|
my %env; |
48
|
1222
|
|
|
|
|
4331
|
foreach my $opt ( keys %Defaults ){ |
49
|
|
|
|
|
|
|
# look for $ENV{GIT_DV_OPTION} |
50
|
4888
|
|
|
|
|
9020
|
my $eopt = "\UGIT_DV_$opt"; |
51
|
4888
|
100
|
|
|
|
14410
|
$env{$opt} = $ENV{$eopt} if exists($ENV{$eopt}); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
1222
|
|
|
|
|
2599
|
my %argv; |
55
|
1222
|
50
|
|
|
|
7102
|
GetOptions(\%argv, 'help' => \&usage, %get_opt_spec) |
56
|
|
|
|
|
|
|
or usage(); |
57
|
|
|
|
|
|
|
|
58
|
1222
|
100
|
|
|
|
462299
|
my %args = ref($_[0]) ? %{$_[0]} : @_; |
|
1200
|
|
|
|
|
6203
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# order of importance: %ENV, @ARGV, @_ |
61
|
1222
|
|
|
|
|
13461
|
return {%env, %argv, %args}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub run { |
65
|
1200
|
|
|
1200
|
1
|
2343481
|
print Git::DescribeVersion->new(options(@_))->version, "\n"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub usage { |
69
|
2
|
|
|
2
|
|
15
|
no warnings 'uninitialized'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
409
|
|
70
|
|
|
|
|
|
|
# show package name if script name is "-" or "-e" |
71
|
0
|
0
|
|
0
|
0
|
|
printf("%s %s\n\nOptions (and their default values):\n\n", |
72
|
|
|
|
|
|
|
($0 =~ /^-e?$/ ? __PACKAGE__ : $0), __PACKAGE__->VERSION |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
foreach my $opt ( sort keys %Defaults ){ |
76
|
0
|
|
|
|
|
|
(my $arg = $opt) =~ tr/_/-/; |
77
|
0
|
|
|
|
|
|
printf(qq[ --%-18s "%s"\n], $arg, $Defaults{$opt}); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
print "\nFor more information try `perldoc Git::DescribeVersion::App`\n"; |
81
|
0
|
|
|
|
|
|
exit; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |