bin/macrodir

filter: Statementstmt 85.3% 64 / 75 Branchbran 55.8% 19 / 34 Conditioncond 83.3% 10 / 12 MC/DCmcdc 71.4% 5 / 7 Subroutinesub 100% 14 / 14 Podpod n/a totaltotal 78.8% 112 / 142 CC 20 SCAR 27.7
CC
20
Cov
77%
wanted
31.8
getoptions
6.2
BEGIN
1.0
CRAP 15.9
↑ Summary bin/macropp »
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 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 22 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 ▶use Getopt::Long ;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 22 ▶use File::Basename ;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 22 ▶use File::Find ;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 22 ▶use File::Path ;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 22 ▶use Symbol ;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 22 ▶use Text::MacroScript ;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 22 ▶use vars qw( $VERSION ) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 22 $VERSION = '2.14';
19  
20 22 my %Opt ;
21  
22 22 &getoptions ;
23  
24 my $Macro = Text::MacroScript->new(
25 -embedded => $Opt{'prep'} ? 0 : 1,
26 20 ▶ -file => [ $Opt{'file'} ],
Branch: 1 branch
BranchTrueFalseTotal
$Opt{'prep'} ? : 4 16 20
27 ) ;
28  
29 20 ▶find( { preprocess => \&preprocess,
Branch: 1 branch
BranchTrueFalseTotal
scalar @ARGV ? : 3 17 20
30 wanted => \&wanted,
31 },
32 scalar @ARGV ? @ARGV : '.' ) ;
33  
34 37 ▶sub preprocess {
Subroutine preprocess: called CC=1 SCAR=0.0
35 37 return sort(@_);
36 }
37  
38 154 ▶sub wanted {
Subroutine wanted: called CC=15 SCAR=34.6
39 154 ▶ return unless /\.m$/o ;
Branch: 1 branch
BranchTrueFalseTotal
unless /\.m$/o 80 74 154
40  
41 74 my $file = $_ ;
42 74 my $newfile = $file ;
43 74 $newfile =~ s/\.m$//o ;
44 74 my $showdir = "$File::Find::dir/" ;
45 74 ▶ if( $Opt{'dir'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Opt{"dir"}) 0 74 74
46 0 my $targetdir = $showdir ;
47 0 ▶ if( $targetdir =~ m,^\./,o ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($targetdir =~ m[^\./]o) { } 0 0 0
48 0 $targetdir =~ s,^\./,$Opt{'dir'},o ;
49 }
50 else {
51 0 $targetdir =~ s/^$Opt{'root'}/$Opt{'dir'}/o ;
52 }
53 0 ▶ $targetdir .= '/' unless $targetdir =~ /\/$/o ;
Branch: 1 branch
BranchTrueFalseTotal
unless $targetdir =~ m[/$]o 0 0 0
54 0 $newfile = $targetdir . $newfile ;
55 0 $showdir = '' ;
56 }
57 74 ▶ if( $Opt{'force'} or ( not -e $newfile ) or
Branch: 2 branches
BranchTrueFalseTotal
if ($Opt{'force'} or not -e $newfile or (stat $newfile)[9] < (stat $file)[9]) { } 62 12 74
elsif ($Opt{'verbose'}) { } 12 0 12
Condition100%6/6
$Opt{"force"} or not -e $newfile or (stat $newfile)[9] < (stat $file)[9]
l!l&&r!l&&!r
56612
$Opt{"force"} or not -e $newfile
l!l&&r!l&&!r
164018
MC/DC100%3/3
$Opt{"force"} or not -e $newfile or (stat $newfile)[9] < (stat $file)[9]
$Opt{"force"} not -e $newfile (stat $newfile)[9] < (stat $file)[9]
Truth table100%4/4
A or not(B) or C
A= $Opt{"force"}B= not -e $newfileC= (stat $newfile)[9] < (stat $file)[9]
ABCresult
1XX1
01X1
0011
0000
58 ( (stat( $newfile ))[9] < (stat( $file ))[9] ) ) {
59 print STDERR "Expanding macros in $File::Find::name to $showdir$newfile\n"
60 62 ▶ if $Opt{'verbose'} ;
Branch: 1 branch
BranchTrueFalseTotal
if $Opt{"verbose"} 56 6 62
61 62 eval {
62 62 ▶ if( not $showdir ) { # Possibly new directory
Branch: 1 branch
BranchTrueFalseTotal
unless ($showdir) 0 62 62
63 0 my $path = dirname( $newfile ) ;
64 0 ▶ if( not -e $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $path) 0 0 0
65 0 ▶ print STDERR "Creating $path\n" if $Opt{'verbose'} ;
Branch: 1 branch
BranchTrueFalseTotal
if $Opt{"verbose"} 0 0 0
66 0 mkpath( $path ) ;
67 }
68 }
69 62 my $fh = gensym ;
70 62 ▶ open $fh, ">$newfile" or
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">$newfile" or die "Open '${newfile}' failed: $!\n" 62 0 62
71 die "Open '$newfile' failed: $!\n" ;
72 62 print $fh $Macro->expand_file( $file ) ;
73 62 close $fh ;
74 } ;
75 62 ▶ warn $@ if $@ ;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 62 62
76 }
77 elsif( $Opt{'verbose'} ) {
78 12 print STDERR "$showdir$newfile is up to date\n"
79 }
80 }
81  
82  
83 22 ▶sub getoptions {
Subroutine getoptions: called CC=6 SCAR=18.3
84  
85 # Defaults.
86 22 $Opt{'dir'} = '' ;
87 22 $Opt{'force'} = 0 ;
88 22 $Opt{'file'} = 'macro' ;
89 22 $Opt{'prep'} = 0 ;
90 22 $Opt{'root'} = Path::Tiny->cwd ;
91 22 $Opt{'verbose'} = 0;
92  
93 22 ▶ &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 20 22
Condition100%3/3
defined $ARGV[0] and $ARGV[0] =~ /^(-h|--help)$/o
!ll&&!rl&&r
1192
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
94  
95 20 Getopt::Long::config 'no_ignore_case' ;
96 20 ▶ GetOptions( \%Opt,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%Opt, "dir|d=s", "force|f", "file|F=s", "prep|p", "verbose|v") or &help 20 0 20
97 'dir|d=s',
98 'force|f',
99 'file|F=s',
100 'prep|p',
101 'verbose|v',
102 ) or &help ;
103  
104 20 ▶ $Opt{'dir'} .= '/' if $Opt{'dir'} and $Opt{'dir'} !~ /\/$/o ;
Branch: 1 branch
BranchTrueFalseTotal
if $Opt{"dir"} and not $Opt{"dir"} =~ m[/$]o 0 20 20
Condition33%1/3
$Opt{"dir"} and not $Opt{"dir"} =~ m[/$]o
!ll&&!rl&&r
2000
MC/DC0%0/2
$Opt{"dir"} and not $Opt{"dir"} =~ m[/$]o
$Opt{"dir"} not $Opt{"dir"} =~ m[/$]o
Truth table33%1/3
A and not(B)
A= $Opt{"dir"}B= not $Opt{"dir"} =~ m[/$]o
ABresult
0X0
100
111
105 }
106  
107 2 ▶sub help {
Subroutine help: called CC=1 SCAR=0.0
108  
109 2 print STDERR <<__EOT__ ;
110  
111 macrodir v $VERSION. Copyright (c) Mark Summerfield 1999-2000.
112 All rights reserved. May be used/distributed under the GPL.
113  
114 usage: macrodir [options] <path>
115  
116 -d --dir Put output files in <dir> instead of $Opt{'root'}
117 -f --force Force conversion [$Opt{'force'}]
118 -F --file Take macros from this file [$Opt{'file'}]
119 -h --help Show this screen and exit
120 -p --prep Operate as macro pre-processor instead of an embedded macro
121 expander
122 -v --verbose Verbose [$Opt{'verbose'}]
123  
124 Loads the macros from file '$Opt{'file'}' in the current directory then expands
125 macros embedded in <: and :> in every .m file in the current directory and any
126 subdirectories.
127  
128 Text::MacroScript now supplies a function relpath which returns the relative
129 path. (See html.macro example file for usage and Text::MacroScript.pm and
130 macropp documentation.)
131 __EOT__
132 2 exit ;
133 }
134  
↑ Summary bin/macropp »