blib/lib/Getopt/constant.pm

filter: Statementstmt 68.8% 42 / 61 Branchbran 39.5% 19 / 48 Conditioncond 31.2% 5 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 80.0% 4 / 5 Podpod n/a totaltotal 50.3% 70 / 139 CC 32 SCAR 49.4
CC
32
Cov
53%
import
156.8
__ANON__
1.0
BEGIN
1.0
CRAP 139.5
↑ Summary
1  
2 2 require 5.003_96; # Time-stamp: "2004-12-29 19:27:33 AST"
3 # same minimal version required as constant.pm
4  
5 package Getopt::constant;
6 2 $VERSION = '1.03';
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶sub import {
Subroutine import: called CC=32 SCAR=50.5
10 1 shift(@_); # We don't care about our own package name
11  
12 1 my(%h) = (@_); # Get default values from there.
13 1 my $pkg = caller;
14 1 ▶ my $pref = delete( $h{':prefix'} ) || '';
Condition50%1/2
delete $h{':prefix'} || ''
l!l
10
MC/DC0%0/1
delete $h{':prefix'} || ''
delete $h{':prefix'}
Truth table50%1/2
A
A= delete $h{':prefix'}
Aresult
11
00
15 1 my $usage = delete( $h{':usage' } ); # a usage message to throw at people
16 1 my $retain = delete( $h{':retain'} ); # if we should not change @ARGV
17 1 my $permissive = delete( $h{':permissive'} );
18 # if we should just skip weird things
19 1 my($x, @unknowns, @orig_ARGV);
20 1 ▶ @orig_ARGV = @ARGV if $retain;
Branch: 1 branch
BranchTrueFalseTotal
if $retain 0 1 1
21  
22 1 ▶ while(@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) 3 0 3
23 3 $x = $ARGV[0];
24 #print "Considering \"$x\"\n";
25 3 ▶ if($x eq '-') {
Branch: 5 branches
BranchTrueFalseTotal
if ($x eq '-') { } 0 3 3
elsif ($x eq '--') { } 1 2 3
elsif ($x =~ /--?([^=]+)=([^=]*)/s) { } 1 1 2
elsif ($x =~ /--?([^=]+)/s) { } 1 0 1
elsif (length $x and substr($x, 0, 1) eq '-') { } 0 0 0
26 # Deceptively not part of the options list, so bail.
27 0 last;
28 } elsif($x eq '--') {
29 # End of options list.
30 1 shift @ARGV;
31 1 last;
32 } elsif($x =~ m<--?([^=]+)=([^=]*)>s ) { # like -foo=123 or --foo=123
33 1 ▶ if(!exists $h{$1}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $h{$1}) { } 0 1 1
elsif (ref($h{$1} || '') eq 'ARRAY') { } 1 0 1
34 0 ▶ push @unknowns, $1 unless $permissive;
Branch: 1 branch
BranchTrueFalseTotal
unless $permissive 0 0 0
35 ▶ } elsif(ref($h{$1} || '') eq 'ARRAY') {
Condition50%1/2
$h{$1} || ''
l!l
10
MC/DC0%0/1
$h{$1} || ''
$h{$1}
Truth table50%1/2
A
A= $h{$1}
Aresult
11
00
36 1 my($name) = $1;
37 1 @{$h{$name}} = split(",", $2, -1);
38 } else {
39 0 $h{$1} = $2;
40 }
41 1 shift @ARGV;
42  
43 } elsif($x =~ m<--?([^=]+)>s ) { # like -foo or --foo
44 1 ▶ if(!exists $h{$1}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $h{$1}) { } 0 1 1
elsif (ref($h{$1} || '') eq 'ARRAY') { } 0 1 1
45 0 ▶ push @unknowns, $1 unless $permissive;
Branch: 1 branch
BranchTrueFalseTotal
unless $permissive 0 0 0
46 ▶ } elsif(ref($h{$1} || '') eq 'ARRAY') {
Condition50%1/2
$h{$1} || ''
l!l
01
MC/DC0%0/1
$h{$1} || ''
$h{$1}
Truth table50%1/2
A
A= $h{$1}
Aresult
11
00
47 0 @{$h{$1}} = (1); # guh, I guess that's right.
48 } else {
49 1 $h{$1} = 1;
50 }
51 1 shift @ARGV;
52  
53 ▶ } elsif(length $x and substr($x,0,1) eq '-') {
Condition0%0/3
length $x and substr($x, 0, 1) eq "-"
!ll&&!rl&&r
000
MC/DC0%0/2
length $x and substr($x, 0, 1) eq "-"
length $x substr($x, 0, 1) eq "-"
Truth table0%0/3
A and B
A= length $xB= substr($x, 0, 1) eq "-"
ABresult
0X0
100
111
54 0 ▶ push @unknowns, "\"$x\"" unless $permissive;
Branch: 1 branch
BranchTrueFalseTotal
unless $permissive 0 0 0
55  
56 } else {
57 0 last; # First non-option in @ARGV
58 }
59 }
60  
61 1 ▶ @ARGV = @orig_ARGV if $retain;
Branch: 1 branch
BranchTrueFalseTotal
if $retain 0 1 1
62  
63 1 ▶ if(@unknowns) {
Branch: 1 branch
BranchTrueFalseTotal
if (@unknowns) 0 1 1
64 0 ▶ if(ref($usage || '') eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($usage || '') eq 'CODE') { } 0 0 0
Condition0%0/2
$usage || ''
l!l
00
MC/DC0%0/1
$usage || ''
$usage
Truth table0%0/2
A
A= $usage
Aresult
11
00
65 0 $usage->(\@unknowns, [sort grep !m/^:/s, keys %h], \%h);
66 } else {
67 0 ▶ printf STDERR "Unknown option%s: %s\n",
Branch: 1 branch
BranchTrueFalseTotal
@unknowns == 1 ? : 0 0 0
68 (@unknowns == 1) ? '' : 's', join(' ', @unknowns);
69 0 ▶ if(defined $usage) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $usage) { } 0 0 0
70 0 print STDERR $usage
71 } else {
72 0 my(@x) = sort grep !m/^:/s, keys %h;
73 0 ▶ print STDERR
Branch: 1 branch
BranchTrueFalseTotal
@x == 1 ? : 0 0 0
74 (@x == 1) ?
75 '(The only known option is: ' : '(The known options are: ',
76 join(', ', @x), ")\n";
77 }
78 }
79
80 0 ▶ if($] <= 5.00599) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] <= 5.00599) { } 0 0 0
81 0 exit;
82 # Because if we put a 1 there, those versions of Perl will emit
83 # a nasty "Callback called exit" message. Ah well.
84 } else {
85 0 exit 1;
86 }
87 }
88  
89 1 ▶ while( my($name,$value) = each %h) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %h) 3 1 4
90 3 ▶ next unless length($name) and substr($name,0,1) ne ':';
Branch: 1 branch
BranchTrueFalseTotal
unless length $name and substr($name, 0, 1) ne ":" 0 3 3
Condition33%1/3
length $name and substr($name, 0, 1) ne ":"
!ll&&!rl&&r
003
MC/DC0%0/2
length $name and substr($name, 0, 1) ne ":"
length $name substr($name, 0, 1) ne ":"
Truth table33%1/3
A and B
A= length $nameB= substr($name, 0, 1) ne ":"
ABresult
0X0
100
111
91 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
92 3 ▶ if(ref($value || '') eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($value || '') eq 'ARRAY') { } 1 2 3
Condition50%1/2
$value || ''
l!l
30
MC/DC0%0/1
$value || ''
$value
Truth table50%1/2
A
A= $value
Aresult
11
00
93 #print "Setting ${pkg}::$pref$name to the list (@$value)\n";
94 1 ▶ *{"${pkg}::$pref$name"} = sub () { @$value };
Subroutine __ANON__: called CC=1 SCAR=0.0
95 } else {
96 #print "Setting ${pkg}::$pref$name to $value\n";
97 0 ▶ *{"${pkg}::$pref$name"} = sub () { $value };
Subroutine __ANON__: not called CC=1 SCAR=0.4
98 }
99 }
100  
101 1 return;
102 }
103 # Yup, that's it.
104 ###########################################################################
105 2 1;
106  
107 __END__
↑ Summary