bin/macropp

filter: Statementstmt 100% 46 / 46 Branchbran 95.0% 19 / 20 Conditioncond 100% 18 / 18 MC/DCmcdc 100% 9 / 9 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 99.0% 99 / 100 CC 10 SCAR 18.9
CC
10
Cov
99%
getoptions
10.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.6
« bin/macrodir ↑ Summary blib/lib/Text/MacroScript.pm »
1 #!/usr/bin/perl
2  
3 # Copyright (c) 1999-2000 Mark Summerfield. All Rights Reserved.
4 # May be used/distributed under the GPL.
5  
6 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 29 ▶use Getopt::Long ;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 29 ▶use Text::MacroScript ;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 29 ▶use vars qw( $VERSION ) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 29 $VERSION = '2.14';
14  
15 29 my %Opt ;
16  
17 29 &getoptions ;
18  
19 my $Macro = Text::MacroScript->new(
20 -file => $Opt{'file'},
21 -comment => $Opt{'comment'},
22 -opendelim => $Opt{'opendelim'},
23 -closedelim => $Opt{'closedelim'},
24 27 -embedded => $Opt{'embedded'},
25 ) ;
26  
27 27 ▶if( $Opt{'macro'} or $Opt{'script'} or $Opt{'variable'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Opt{'macro'} or $Opt{'script'} or $Opt{'variable'}) { } 11 16 27
Condition100%6/6
$Opt{"macro"} or $Opt{"script"} or $Opt{"variable"}
l!l&&r!l&&!r
8316
$Opt{"macro"} or $Opt{"script"}
l!l&&r!l&&!r
5319
MC/DC100%3/3
$Opt{"macro"} or $Opt{"script"} or $Opt{"variable"}
$Opt{"macro"} $Opt{"script"} $Opt{"variable"}
Truth table100%4/4
A or B or C
A= $Opt{"macro"}B= $Opt{"script"}C= $Opt{"variable"}
ABCresult
1XX1
01X1
0011
0000
28 11 ▶ $Macro->list( -macro, $Opt{'name'} ) if $Opt{'macro'} ;
Branch: 1 branch
BranchTrueFalseTotal
if $Opt{"macro"} 5 6 11
29 11 ▶ $Macro->list( -script, $Opt{'name'} ) if $Opt{'script'} ;
Branch: 1 branch
BranchTrueFalseTotal
if $Opt{"script"} 5 6 11
30 11 ▶ $Macro->list( -variable, $Opt{'name'} ) if $Opt{'variable'} ;
Branch: 1 branch
BranchTrueFalseTotal
if $Opt{"variable"} 5 6 11
31 }
32 else {
33 16 ▶ while( <> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ARGV)) 39 14 53
34 39 print $Macro->expand( $_, $ARGV, $. );
35 }
36 }
37  
38 29 ▶sub getoptions {
Subroutine getoptions: called CC=10 SCAR=23.0
39  
40 # Defaults.
41 29 $Opt{'closedelim'} = '' ;
42 29 $Opt{'comment'} = 0 ;
43 29 $Opt{'emacro'} = 0 ;
44 29 $Opt{'files'} = [] ;
45 29 $Opt{'macro'} = 0 ;
46 29 $Opt{'name'} = 0 ;
47 29 $Opt{'opendelim'} = '' ;
48 29 $Opt{'script'} = 0 ;
49 29 $Opt{'variable'} = 0 ;
50  
51 29 ▶ &help if defined $ARGV[0] and $ARGV[0] =~ /^(-h|--help)$/o ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ARGV[0] and $ARGV[0] =~ /^(-h|--help)$/o 2 27 29
Condition100%3/3
defined $ARGV[0] and $ARGV[0] =~ /^(-h|--help)$/o
!ll&&!rl&&r
1262
MC/DC100%2/2
defined $ARGV[0] and $ARGV[0] =~ /^(-h|--help)$/o
defined $ARGV[0] $ARGV[0] =~ /^(-h|--help)$/o
Truth table100%3/3
A and B
A= defined $ARGV[0]B= $ARGV[0] =~ /^(-h|--help)$/o
ABresult
0X0
100
111
52  
53 27 Getopt::Long::config 'no_ignore_case' ;
54 27 ▶ GetOptions( \%Opt,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%Opt, "closedelim|c=s", "comment|C", "emacro|e", "file|f=s\@", "macro|m", "opendelim|o=s", "name|n", "script|s", "variable|v") or &help 27 0 27
55 'closedelim|c=s',
56 'comment|C',
57 'emacro|e',
58 'file|f=s@',
59 'macro|m',
60 'opendelim|o=s',
61 'name|n',
62 'script|s',
63 'variable|v',
64 ) or &help ;
65  
66 27 ▶ if( $Opt{'name'} and
Branch: 1 branch
BranchTrueFalseTotal
if ($Opt{"name"} and not $Opt{"macro"} and not $Opt{"script"} and not $Opt{"variable"}) 2 25 27
Condition100%9/9
$Opt{"name"} and not $Opt{"macro"} and not $Opt{"script"} and not $Opt{"variable"}
!ll&&!rl&&r
2412
$Opt{"name"} and not $Opt{"macro"} and not $Opt{"script"}
!ll&&!rl&&r
2313
$Opt{"name"} and not $Opt{"macro"}
!ll&&!rl&&r
2214
MC/DC100%4/4
$Opt{"name"} and not $Opt{"macro"} and not $Opt{"script"} and not $Opt{"variable"}
$Opt{"name"} not $Opt{"macro"} not $Opt{"script"} not $Opt{"variable"}
Truth table100%5/5
A and not(B) and not(C) and not(D)
A= $Opt{"name"}B= not $Opt{"macro"}C= not $Opt{"script"}D= not $Opt{"variable"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
67 ( not $Opt{'macro'} ) and
68 ( not $Opt{'script'} ) and
69 ( not $Opt{'variable'} )
70 ) {
71 2 $Opt{'macro'} = 1 ;
72 2 $Opt{'script'} = 1 ;
73 2 $Opt{'variable'} = 1 ;
74 }
75  
76 # Don't die if no delimiters are specified - Text::MacroScript.pm will
77 # default them to <: and :> if needed.
78  
79 27 ▶ $Opt{'opendelim'} = undef unless $Opt{'opendelim'} ;
Branch: 1 branch
BranchTrueFalseTotal
unless $Opt{"opendelim"} 23 4 27
80 27 ▶ $Opt{'closedelim'} = undef unless $Opt{'closedelim'} ;
Branch: 1 branch
BranchTrueFalseTotal
unless $Opt{"closedelim"} 25 2 27
81 27 $Opt{'embedded'} = $Opt{'emacro'} ;
82 }
83  
84 2 ▶sub help {
Subroutine help: called CC=1 SCAR=0.0
85  
86 2 print STDERR <<__EOT__ ;
87  
88 macropp v $VERSION. Copyright (c) Mark Summerfield 1999-2000.
89 All rights reserved. May be used/distributed under the GPL.
90  
91 usage: macropp [options] infile(s) > outfile
92  
93 options: (use the short or long name followed by the parameter where req'd)
94 -C --comment add the %%[] comment macro
95 -f --file s macro/script file to read (repeat for multiple files)
96 -m --macro just list macros [$Opt{'macro'}]
97 -n --name just list the names of macros/scripts [$Opt{'name'}]
98 (if no -m or -s or v are specified this sets them all)
99 -s --script just list scripts [$Opt{'script'}]
100 -v --variable just list variables [$Opt{'variable'}]
101  
102 -e --emacro operate as embedded perl processor [$Opt{'emacro'}]
103 -o --opendelim s closing delimiter for embedded processor [$Opt{'opendelim'}]
104 -c --closedelim s closing delimiter for embedded processor [$Opt{'closedelim'}]
105  
106 b = boolean 1 = true, 0 = false; i = integer; s = string e.g. filename
107  
108 See macrodir for a different approach.
109 __EOT__
110  
111 2 exit ;
112 }
113  
114 __END__
« bin/macrodir ↑ Summary blib/lib/Text/MacroScript.pm »