| 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 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | package Git::DescribeVersion::App; | ||||||||||||||||||||||||||||
| 14 | { | ||||||||||||||||||||||||||||
| 15 | 3 | $Git::DescribeVersion::App::VERSION = '1.015'; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 3 | $Git::DescribeVersion::App::AUTHORITY = 'cpan:RWSTAUNER'; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | # ABSTRACT: Run Git::DescribeVersion as one-line script | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use Git::DescribeVersion (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use Getopt::Long qw(GetOptions); # core | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # for simplicity | ||||||||||||||||||||||||||||
| 26 | 3 | our %Defaults = %Git::DescribeVersion::Defaults; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | my %get_opt_spec = map { | ||||||||||||||||||||||||||||
| 29 | 3 | 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 | 12 | ▶ | ( $dash =~ tr/_/-/ ? "$_|$dash=s" : "$_=s" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | } keys %Defaults; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # simple: enable `perl -MGit::DescribeVersion::App -e run` | ||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 3 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 1 | *{caller(0) . '::run'} = \&run; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1222 | ▶ | sub options { | ||||||||||||||||||||||||||
|
Subroutine
options: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | # allow usage as Git::DescribeVersion::App->run() | ||||||||||||||||||||||||||||
| 43 | # (for consistency with other App's) | ||||||||||||||||||||||||||||
| 44 | # and simply discard the unused argument | ||||||||||||||||||||||||||||
| 45 | 1222 | ▶ | shift(@_) if @_ && $_[0] eq __PACKAGE__; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and $_[0] eq __PACKAGE__
MC/DC100%2/2
@_ and $_[0] eq __PACKAGE__
@_
$_[0] eq __PACKAGE__
Truth table100%3/3
A and B
A= @_B= $_[0] eq __PACKAGE__
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1222 | my %env; | |||||||||||||||||||||||||||
| 48 | 1222 | foreach my $opt ( keys %Defaults ){ | |||||||||||||||||||||||||||
| 49 | # look for $ENV{GIT_DV_OPTION} | ||||||||||||||||||||||||||||
| 50 | 4888 | my $eopt = "\UGIT_DV_$opt"; | |||||||||||||||||||||||||||
| 51 | 4888 | ▶ | $env{$opt} = $ENV{$eopt} if exists($ENV{$eopt}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1222 | my %argv; | |||||||||||||||||||||||||||
| 55 | 1222 | ▶ | GetOptions(\%argv, 'help' => \&usage, %get_opt_spec) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | or usage(); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1222 | ▶ | my %args = ref($_[0]) ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # order of importance: %ENV, @ARGV, @_ | ||||||||||||||||||||||||||||
| 61 | 1222 | return {%env, %argv, %args}; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1200 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 1200 | print Git::DescribeVersion->new(options(@_))->version, "\n"; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub usage { | ||||||||||||||||||||||||||
|
Subroutine
usage: not called CC=3 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 3 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | # show package name if script name is "-" or "-e" | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | printf("%s %s\n\nOptions (and their default values):\n\n", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 3 | 1; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||