DescribeVersion/App.pm

filter: Statementstmt 86.6% 39 / 45 Branchbran 75.0% 9 / 12 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 90.9% 10 / 11 Podpod 33.3% 1 / 3 totaltotal 84.2% 64 / 76 CC 9 SCAR 14.0
CC
9
Cov
85%
options
7.0
usage
6.5
BEGIN
1.0
CRAP 4.1
« DescribeVersion.pm ↑ Summary
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
BranchTrueFalseTotal
$dash =~ tr/_/\-/ ? : 9 3 12
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
BranchTrueFalseTotal
if @_ and $_[0] eq __PACKAGE__ 611 611 1222
Condition100%3/3
@_ and $_[0] eq __PACKAGE__
!ll&&!rl&&r
5606611
MC/DC100%2/2
@_ and $_[0] eq __PACKAGE__
@_ $_[0] eq __PACKAGE__
Truth table100%3/3
A and B
A= @_B= $_[0] eq __PACKAGE__
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if exists $ENV{$eopt} 26 4862 4888
52 }
53  
54 1222 my %argv;
55 1222 ▶ GetOptions(\%argv, 'help' => \&usage, %get_opt_spec)
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%argv, "help", \&Git::DescribeVersion::App::usage, %get_opt_spec) or usage() 1222 0 1222
56 or usage();
57  
58 1222 ▶ my %args = ref($_[0]) ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1200 22 1222
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
BranchTrueFalseTotal
$0 =~ /^-e?$/ ? : 0 0 0
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__
« DescribeVersion.pm ↑ Summary