/usr/local/bin/cpancover

filter: Statementstmt 57.8% 37 / 64 Branchbran 38.2% 13 / 34 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 52.6% 59 / 112 SCAR 41.6
CC
19
Cov
50%
main
69.5
get_options
9.0
BEGIN
1.0
CRAP 64.1
« blib/lib/Daemon/DaemonizeLight.pm ↑ Summary
1 #!/usr/local/bin/perl
2  
3 # Copyright 2002-2026, Paul Johnson (paul@pjcj.net)
4  
5 # This software is free. It is licensed under the same terms as Perl itself.
6  
7 # The latest version of this software should be available from my homepage:
8 # https://pjcj.net
9  
10 3 ▶use 5.42.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # VERSION
13  
14 3 ▶use Devel::Cover::Collection ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶use Cwd qw( abs_path cwd );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Getopt::Long qw( GetOptions );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Pod::Usage qw( pod2usage );
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # use Carp; $SIG{__DIE__} = \&Carp::confess;
21  
22 3 $|++;
23  
24 3 my $Options = {
25 bin_dir => abs_path($0) =~ s|/cpancover$||r,
26 build => 1,
27 compress_old_versions => 0,
28 docker => "docker",
29 dryrun => 0,
30 force => 0,
31 generate_html => 0,
32 latest => 0,
33 local => 0,
34 local_build => 0,
35 mark_rebuilt => 0,
36 modules => [],
37 output_file => "index.html",
38 rebuild => 0,
39 rebuild_batch => 100,
40 report => "html",
41 results_dir => cwd(),
42 timeout => undef,
43 verbose => 0,
44 workers => 0,
45 };
46  
47 sub get_options {
48 #<<<
49 3 ▶ die "Bad option" unless GetOptions(
Subroutine get_options: called CC=6 SCAR=22.0
Branch: 1 branch
BranchTrueFalseTotal
unless &GetOptions($Options, ("bin_dir=s", "build!", "compress_old_versions=i", "docker=s", "dryrun!", "env=s", "force!", "generate_html!", "help|h!", "info|i!", "latest!", "local!", "local_build!", "mark_rebuilt!", "module_file=s", "modules=s", "output_file=s", "rebuild!", "rebuild_batch=i", "report=s", "results_dir=s", "timeout=i", "verbose!", "version|v!", "workers=i")) 0 3 3
50 $Options, qw(
51 bin_dir=s
52 build!
53 compress_old_versions=i
54 docker=s
55 dryrun!
56 env=s
57 force!
58 generate_html!
59 help|h!
60 info|i!
61 latest!
62 local!
63 local_build!
64 mark_rebuilt!
65 module_file=s
66 modules=s
67 output_file=s
68 rebuild!
69 rebuild_batch=i
70 report=s
71 results_dir=s
72 timeout=i
73 verbose!
74 version|v!
75 workers=i
76 )
77 );
78 #>>>
79  
80 3 ▶ say "$0 version " . __PACKAGE__->VERSION and exit 0 if $Options->{version};
Branch: 1 branch
BranchTrueFalseTotal
if $Options->{"version"} 0 3 3
Condition25%1/4
$Options->{'version'} && (say("$0 version " . __PACKAGE__->VERSION) && exit 0)
!ll
30
say "$0 version " . __PACKAGE__->VERSION and exit 0
!ll
00
MC/DC0%0/2
$Options->{'version'} && (say("$0 version " . __PACKAGE__->VERSION) && exit 0)
$Options->{'version'} say "$0 version " . __PACKAGE__->VERSION
Truth table33%1/3
A && B
A= $Options->{'version'}B= say "$0 version " . __PACKAGE__->VERSION
ABresult
0X0
100
111
81 3 ▶ pod2usage(-exitval => 0, -verbose => 0) if $Options->{help};
Branch: 1 branch
BranchTrueFalseTotal
if $Options->{"help"} 0 3 3
82 3 ▶ pod2usage(-exitval => 0, -verbose => 2) if $Options->{info};
Branch: 1 branch
BranchTrueFalseTotal
if $Options->{"info"} 0 3 3
83 }
84  
85 sub newcp {
86 #<<<
87 Devel::Cover::Collection->new(
88 3 ▶ map { $_ => $Options->{$_} } qw(
Subroutine newcp: called CC=1 SCAR=0.0
89 bin_dir
90 docker
91 dryrun
92 env
93 force
94 local
95 mark_rebuilt
96 modules
97 output_file
98 rebuild
99 rebuild_batch
100 report
101 results_dir
102 timeout
103 verbose
104 workers
105 )
106 )
107 #>>>
108 }
109  
110 sub main {
111 # TODO - only one instance should run at a time
112 3 ▶ get_options;
Subroutine main: called CC=14 SCAR=42.4
113 # say Dumper($Options) if $Options->{verbose};
114  
115 3 ▶ if ($Options->{latest}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Options->{"latest"}) 0 3 3
116 0 my $cp = newcp;
117 0 $cp->get_latest;
118 0 return;
119 }
120  
121 3 ▶ if ($Options->{local_build}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Options->{"local_build"}) 0 3 3
122 0 my $cp = newcp;
123 0 $cp->set_modules(@ARGV);
124 0 $cp->local_build;
125 0 return;
126 }
127  
128 3 my %counts;
129  
130 3 ▶ if ($Options->{module_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Options->{"module_file"}) 0 3 3
131 0 my $cp = newcp;
132 0 $cp->set_module_file($Options->{module_file});
133 0 $counts{new_count} += $cp->cover_modules;
134 }
135  
136 3 ▶ if ($Options->{build}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Options->{"build"}) 3 0 3
137 3 my $cp;
138 3 ▶ if (@ARGV) {
Branch: 2 branches
BranchTrueFalseTotal
if (@ARGV) { } 3 0 3
elsif (not -t STDIN) { } 0 0 0
139 3 $cp = newcp;
140 3 $cp->set_modules(@ARGV);
141 } elsif (!-t STDIN) {
142 0 my @modules;
143 0 ▶ while (my $l = <>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = readline ARGV)) 0 0 0
144 0 chomp $l;
145 0 push @modules, split " ", $l;
146 }
147 0 $cp = newcp;
148 0 $cp->set_modules(@modules);
149 } else {
150 0 $cp = newcp;
151 }
152 3 $counts{new_count} += $cp->cover_modules;
153 }
154  
155 3 ▶ if ($Options->{rebuild}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Options->{'rebuild'}) { } 0 3 3
elsif ($Options->{'mark_rebuilt'}) { } 0 3 3
156 0 my $cp = newcp;
157 0 ▶ $counts{rebuilt_count} = $cp->rebuild_pass if $Options->{rebuild_batch};
Branch: 1 branch
BranchTrueFalseTotal
if $Options->{"rebuild_batch"} 0 0 0
158 0 ▶ $counts{all_rebuilt} = $cp->all_rebuilt ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cp->all_rebuilt ? : 0 0 0
159 0 $cp->write_status(%counts);
160 } elsif ($Options->{mark_rebuilt}) {
161 0 my $cp = newcp;
162 0 $cp->write_status(%counts);
163 }
164  
165 3 ▶ if ($Options->{generate_html}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Options->{"generate_html"}) 0 3 3
166 0 my $cp = newcp;
167 0 $cp->generate_html;
168 }
169  
170 3 ▶ if ($Options->{compress_old_versions}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Options->{"compress_old_versions"}) 0 3 3
171 0 my $cp = newcp;
172 0 $cp->compress_old_versions($Options->{compress_old_versions});
173 }
174 }
175  
176 3 main
177  
178 __END__
« blib/lib/Daemon/DaemonizeLight.pm ↑ Summary