| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 30 | 6 | ▶ | $opt{version} and print("$VERSION\n"), exit(0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 6 | ▶ | $opt{help} || @ARGV < 1 and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt{"help"} or @ARGV < 1
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 5 | my $ename; | |||||||||||||||||||||||||||
| 39 | 5 | ▶ | if (@ARGV < 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | print $ename, "\t$_\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
@File::ERC::erc_termlist and %File::ERC::erc_tags
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC50%1/2
$ret ||= !$ename
$ret
!$ename
Truth table66%2/3
A ||= not(B)
A= $retB= !$ename
| |||||||||||||||||||||||||||||
| 55 | 10 | ▶ | $ename ||= '???'; # flag unknown code | ||||||||||||||||||||||||||
|
Condition50%1/2
$ename ||= "???"
MC/DC0%0/1
$ename ||= "???"
$ename
Truth table50%1/2
A
A= $ename
| |||||||||||||||||||||||||||||
| 56 | 10 | print $ename, "\t$_\n"; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||
| 59 | 4 | my @nums = File::ERC::tag2num($_); | |||||||||||||||||||||||||||
| 60 | 4 | ▶ | if (@nums < 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||