t/multi_pack.pl

filter: Statementstmt 83.3% 15 / 18 Branchbran 50.0% 5 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 75.7% 25 / 33 CC 7 SCAR 12.9
CC
7
Cov
71%
BEGIN
5.2
BEGIN
4.0
BEGIN
2.0
CRAP 3.6
↑ Summary t/dflt_stdout.pl »
1 # -*- perl -*-
2  
3 =head1 WHATS THIS
4  
5 This prog allows cmdline options (evaluated in a BEGIN) to selectively
6 pull in separate packages (currently X & Y), both of which use
7 AutoCategorize, and which therefore should be munged.
8  
9 By using either uppercase or lowercase options, you can control the
10 order that the modules are used wrt use of AutoCategorize in the main
11 script; uppercase options use the module 1st, lowercase use them after
12 main() use AutoCategorize is compiled.
13  
14 =cut
15  
16 21 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
17 # it seems unholy to do this, but perl Core does..
18 21 ▶ chdir 't' if -d 't';
Branch: 1 branch
BranchTrueFalseTotal
if -d "t" 0 21 21
19 21 ▶ use lib '../lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 21 $ENV{PERL5LIB} = '../lib'; # so children will see it too
21 }
22  
23 my $opts;
24 21 ▶BEGIN {
Subroutine BEGIN: called CC=5 SCAR=16.4
25 21 ▶ use Getopt::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 21 ▶ getopts ('wxyzWXYZvd', $opts={})
Branch: 1 branch
BranchTrueFalseTotal
&getopts("wxyzWXYZvd", scalar($opts = {})) or die "\n\t only options [abXYv] allowed\n\t\t-W : load X.pm before AutoCategorize\n\t\t-w : after AutoCategorize\n\t\t-X : load X.pm before AutoCategorize\n\t\t-x : after AutoCategorize\n\t\t-Y : load Y.pm before AutoCategorize\n\t\t-y : after AutoCategorize\n\t\t-Z : load Z.pm before AutoCategorize\n\t\t-z : after AutoCategorize\n\t\t-v : verbose\n\t\t" 21 0 21
27 or die qq{
28 only options [abXYv] allowed
29 -W : load X.pm before AutoCategorize
30 -w : after AutoCategorize
31 -X : load X.pm before AutoCategorize
32 -x : after AutoCategorize
33 -Y : load Y.pm before AutoCategorize
34 -y : after AutoCategorize
35 -Z : load Z.pm before AutoCategorize
36 -z : after AutoCategorize
37 -v : verbose
38 };
39
40 21 ▶ $DB::single = 1 if $opts->{d};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"d"} 0 21 21
41  
42 21 foreach $mod ('W','X','Y','Z') {
43 63 ▶ if ($opts->{$mod}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{$mod}) 15 48 63
44 15 print "loading $mod\n";
45 15 require "$mod.pm";
46 0 $mod->import;
47 }
48 }
49 }
50  
51 use Log::Log4perl::AutoCategorize
52 6 ▶ (
Subroutine BEGIN: called CC=2 SCAR=14.0
53 alias => 'myLogger',
54 $opts->{v}
55 ? # verbose - use default logger (to Screen), and
56 ( #debug => 'vfmjdsrsriabcz',
57 0 ▶ debug => 've', #debug => 'abcevfmrsi',
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'v'} ? : 0 0 0
58 )
59 : # use log-conf, wo excessive screen
60 ( initfile => 'log-conf',
61 debug => ''
62 ),
63 0 );
64  
65 BEGIN {
66 foreach $mod ('W','X','Y','Z') {
67 if ($opts->{lc $mod}) {
68 print "loading $mod\n";
69 require "$mod.pm";
70 $mod->import;
71 }
72 }
73 }
74  
75 # OK - now do runtime
76 # NOTE that the test expects particular line numbers, and will fail if
77 # you add even a blank line or comment here (above the myLogger calls)
78  
79 foreach (1..5) {
80 myLogger->warn($_);
81 myLogger->info($_);
82  
83 foreach $mod ('W','X','Y','Z') {
84 if ($opts->{$mod} or $opts->{lc $mod}) {
85 #print "running $mod\n";
86 $mod->truck($_);
87 }
88 }
89 }
90  
91 __END__
↑ Summary t/dflt_stdout.pl »