blib/script/erc

filter: Statementstmt 100% 51 / 51 Branchbran 72.7% 16 / 22 Conditioncond 54.5% 6 / 11 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 83.6% 82 / 98 CC 2 SCAR 2.3
CC
2
Cov
87%
help
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« blib/lib/File/ERC.pm ↑ Summary blib/script/anvl »
1 #!/usr/local/bin/perl
2  
3 6 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 my $VERSION = $File::ERC::VERSION;
8  
9 6 ▶use File::ERC;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 # this :config allows -h24w80 for '‐h 24 ‐w 80', -vax for --vax or --Vax
13 6 ▶use Getopt::Long qw(:config bundling_override);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 my %opt = (
16 help => 0,
17 man => 0,
18 version => 0,
19 );
20  
21 # main
22 {
23 6 ▶ GetOptions(\%opt,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%opt, "help|h|?", "man", "version") or pod2usage("-exitstatus", 2, "-verbose", 1) 6 0 6
24 'help|h|?',
25 'man',
26 'version',
27 )
28 or pod2usage(-exitstatus => 2, -verbose => 1);
29 6 ▶ $opt{man} and pod2usage(-exitstatus => 0, -verbose => 2);
Branch: 1 branch
BranchTrueFalseTotal
$opt{"man"} and pod2usage("-exitstatus", 0, "-verbose", 2) 0 6 6
30 6 ▶ $opt{version} and print("$VERSION\n"), exit(0);
Branch: 1 branch
BranchTrueFalseTotal
$opt{"version"} and print("$VERSION\n"), exit 0 0 6 6
31  
32 6 ▶ $opt{help} || @ARGV < 1 and
Branch: 1 branch
BranchTrueFalseTotal
$opt{"help"} || @ARGV < 1 and help(), exit 0 1 5 6
Condition66%2/3
$opt{"help"} or @ARGV < 1
l!l&&r!l&&!r
015
MC/DC50%1/2
$opt{"help"} or @ARGV < 1
$opt{"help"} @ARGV < 1
Truth table66%2/3
A or B
A= $opt{"help"}B= @ARGV < 1
ABresult
1X1
011
000
33 help(), exit(0);
34  
35 5 my $cmd = lc shift @ARGV;
36 5 ▶ $cmd eq 'get' or help("$cmd: unrecognized command"), exit(2);
Branch: 1 branch
BranchTrueFalseTotal
$cmd eq "get" or help("${cmd}: unrecognized command"), exit 2 5 0 5
37  
38 5 my $ename;
39 5 ▶ if (@ARGV < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV < 1) 1 4 5
40 1 ▶ print $ename, "\t$_\n"
Branch: 1 branch
BranchTrueFalseTotal
($_, $ename) = each %File::ERC::erc_terms and do { print $ename, "\t$_\n" } 56 1 57
41 while (($_, $ename) = each %File::ERC::erc_terms);
42 1 exit 0;
43 }
44  
45 4 ▶ @File::ERC::erc_termlist && %File::ERC::erc_tags or
Branch: 1 branch
BranchTrueFalseTotal
@File::ERC::erc_termlist and %File::ERC::erc_tags or File::ERC::tag2num_init() 0 4 4
Condition33%1/3
@File::ERC::erc_termlist and %File::ERC::erc_tags
!ll&&!rl&&r
400
MC/DC0%0/2
@File::ERC::erc_termlist and %File::ERC::erc_tags
@File::ERC::erc_termlist %File::ERC::erc_tags
Truth table33%1/3
A and B
A= @File::ERC::erc_termlistB= %File::ERC::erc_tags
ABresult
0X0
100
111
46 File::ERC::tag2num_init(); # one-time lazy definition
47  
48 4 my $ret = 0;
49 4 for (@ARGV) { # check each argument type
50 14 ▶ if (/^[cvh]?\d/i) { # if it looks numeric-ish
Branch: 1 branch
BranchTrueFalseTotal
if (/^[cvh]?\d/i) { } 10 4 14
51 10 s/^(\d)/h$1/; # start with 'h' if pure digits
52 10 ($ename) = # only want array of 1 element
53 File::ERC::num2tag($_);
54 10 ▶ $ret ||= ! $ename; # one bad apple spoils it
Condition66%2/3
$ret ||= !$ename
l!l&&r!l&&!r
406
MC/DC50%1/2
$ret ||= !$ename
$ret !$ename
Truth table66%2/3
A ||= not(B)
A= $retB= !$ename
ABresult
1X1
011
000
55 10 ▶ $ename ||= '???'; # flag unknown code
Condition50%1/2
$ename ||= "???"
l!l
100
MC/DC0%0/1
$ename ||= "???"
$ename
Truth table50%1/2
A
A= $ename
Aresult
11
00
56 10 print $ename, "\t$_\n";
57 }
58 else {
59 4 my @nums = File::ERC::tag2num($_);
60 4 ▶ if (@nums < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@nums < 1) 1 3 4
61 1 print("???\t$_\n");
62 1 $ret = 1; # one bad apple
63 1 next;
64 }
65 3 for (@nums) {
66 6 print $_, "\t$File::ERC::erc_tags{$_}\n";
67 }
68 }
69 }
70 4 exit $ret;
71 }
72  
73 1 ▶sub help { my $msg = shift;
Subroutine help: called CC=2 SCAR=7.0
74  
75 1 ▶ $msg and print $msg, "\n";
Branch: 1 branch
BranchTrueFalseTotal
$msg and print $msg, "\n" 0 1 1
76 1 print << 'EOI';
77  
78 erc - lookup Electronic Resource Citation metadata tags
79  
80 Usage:
81 erc get print all known tags and semi-numeric codes
82 erc get | sort print all tags and codes in a more useful order
83 erc get tag ... print tags given by code, element name, or regexp
84  
85 Examples:
86 $ erc get where who
87 where h4
88 who h1
89 $ erc get 2 3
90 what h2
91 when h3
92 $ erc ^about-whe
93 about-when h13
94 about-where h14
95  
96 See "erc --man" for full documentation.
97  
98 EOI
99 1 return 1;
100 }
101  
102 __END__
« blib/lib/File/ERC.pm ↑ Summary blib/script/anvl »