blib/lib/Benchmark/Perl/Formance/Plugin/PerlCritic.pm

filter: Statementstmt 34.2% 26 / 76 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 53.8% 7 / 13 Podpod 0.0% 0 / 4 totaltotal 22.7% 33 / 145 CC 21 SCAR 39.4
CC
21
Cov
22%
upstream
90.0
bundled
90.0
prepare
12.0
CRAP 51.6
« blib/lib/Benchmark/Perl/Formance/Plugin/SpamAssassin.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/P6STD.pm »
1 package Benchmark::Perl::Formance::Plugin::PerlCritic;
2 1 our $AUTHORITY = 'cpan:SCHWIGON';
3 # ABSTRACT: benchmark plugin - PerlCritic - Run Perl::Critic on itself
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = "0.001";
9  
10 #############################################################
11 # #
12 # Benchmark Code ahead - Don't touch without strong reason! #
13 # #
14 #############################################################
15  
16 1 ▶use File::Temp qw(tempfile tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use File::Copy::Recursive qw(dircopy);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use File::ShareDir qw(dist_dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Time::HiRes qw(gettimeofday);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 our $count;
22 1 our $recurse;
23  
24 1 ▶use Benchmark ':hireswallclock';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 0 ▶sub prepare {
Subroutine prepare: not called CC=3 SCAR=24.8
Pod undocumented
27 0 my ($options) = @_;
28  
29 0 my $dstdir = tempdir( CLEANUP => 1 );
30 0 my $srcdir; eval { $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/PerlCritic" };
31 0 ▶ return if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
32  
33 0 ▶ print STDERR "# Prepare Perl::Critic sources in $dstdir ...\n" if $options->{verbose} >= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} >= 3 0 0 0
34 0 dircopy($srcdir, $dstdir);
35  
36 0 return $dstdir;
37 }
38  
39 0 ▶sub upstream {
Subroutine upstream: not called CC=9 SCAR=45.0
Pod undocumented
40 0 my ($options, $dstdir) = @_;
41  
42 0 (my $perlcritic = $^X) =~ s!/perl[\d.]*$!/perlcritic!;
43 0 ▶ print STDERR "# Use perlcritic: $perlcritic\n" if $options->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} > 2 0 0 0
44  
45 0 my $datadir = $dstdir;
46 0 ▶ $datadir .= '/Perl/Critic/Utils' if $options->{fastmode};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"fastmode"} 0 0 0
47  
48 0 my $version = `$^X $perlcritic --version`; chomp $version;
49 0 my $cmd = qq{$^X $perlcritic --exclude RequireFilenameMatchesPackage $datadir};
50  
51 0 ▶ print STDERR "# $cmd\n" if $options->{verbose} && $options->{verbose} >= 4;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} and $options->{"verbose"} >= 4 0 0 0
Condition0%0/3
$options->{"verbose"} and $options->{"verbose"} >= 4
!ll&&!rl&&r
000
MC/DC0%0/2
$options->{"verbose"} and $options->{"verbose"} >= 4
$options->{"verbose"} $options->{"verbose"} >= 4
Truth table0%0/3
A and B
A= $options->{"verbose"}B= $options->{"verbose"} >= 4
ABresult
0X0
100
111
52 0 ▶ print STDERR "# Run...\n" if $options->{verbose} && $options->{verbose} >= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} and $options->{"verbose"} >= 3 0 0 0
Condition0%0/3
$options->{"verbose"} and $options->{"verbose"} >= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$options->{"verbose"} and $options->{"verbose"} >= 3
$options->{"verbose"} $options->{"verbose"} >= 3
Truth table0%0/3
A and B
A= $options->{"verbose"}B= $options->{"verbose"} >= 3
ABresult
0X0
100
111
53  
54 0 my @output;
55 0 ▶ my $t = timeit $count, sub { @output = map { chomp; $_ } qx($cmd) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
56  
57 0 ▶ my $maxerr = ($#output < 10) ? $#output : 10;
Branch: 1 branch
BranchTrueFalseTotal
$#output < 10 ? : 0 0 0
58 0 ▶ print STDERR join("\n# ", "", @output[0..$maxerr]) if $options->{verbose} >= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} >= 3 0 0 0
59  
60 return {
61 0 Benchmark => $t,
62 count => $count,
63 perl_critic_version => $version,
64 };
65 }
66  
67 0 ▶sub bundled {
Subroutine bundled: not called CC=9 SCAR=45.0
Pod undocumented
68 0 my ($options, $dstdir) = @_;
69  
70 0 my $datadir = $dstdir;
71 0 ▶ $datadir .= '/Perl/Critic/Utils' if $options->{fastmode};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"fastmode"} 0 0 0
72  
73 0 my $perlcritic = "$dstdir/perlcritic";
74 0 my $version = `$^X -I $dstdir $dstdir/perlcritic --version`; chomp $version;
75 0 my $cmd = qq{$^X -I $dstdir $dstdir/perlcritic --exclude RequireFilenameMatchesPackage $datadir 2>&1};
76  
77 0 ▶ print STDERR "# Use perlcritic: $^X $perlcritic\n" if $options->{verbose} >= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} >= 3 0 0 0
78 0 ▶ print STDERR "# $cmd\n" if $options->{verbose} && $options->{verbose} >= 4;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} and $options->{"verbose"} >= 4 0 0 0
Condition0%0/3
$options->{"verbose"} and $options->{"verbose"} >= 4
!ll&&!rl&&r
000
MC/DC0%0/2
$options->{"verbose"} and $options->{"verbose"} >= 4
$options->{"verbose"} $options->{"verbose"} >= 4
Truth table0%0/3
A and B
A= $options->{"verbose"}B= $options->{"verbose"} >= 4
ABresult
0X0
100
111
79 0 ▶ print STDERR "# Run...\n" if $options->{verbose} && $options->{verbose} >= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} and $options->{"verbose"} >= 3 0 0 0
Condition0%0/3
$options->{"verbose"} and $options->{"verbose"} >= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$options->{"verbose"} and $options->{"verbose"} >= 3
$options->{"verbose"} $options->{"verbose"} >= 3
Truth table0%0/3
A and B
A= $options->{"verbose"}B= $options->{"verbose"} >= 3
ABresult
0X0
100
111
80  
81 0 my @output;
82 0 ▶ my $t = timeit $count, sub { @output = map { chomp; $_ } qx($cmd) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
83  
84 0 ▶ my $maxerr = ($#output < 10) ? $#output : 10;
Branch: 1 branch
BranchTrueFalseTotal
$#output < 10 ? : 0 0 0
85 0 ▶ print STDERR join("\n# ", "", @output[0..$maxerr]) if $options->{verbose} >= 4;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} >= 4 0 0 0
86  
87 return {
88 0 Benchmark => $t,
89 count => $count,
90 perl_critic_version => $version,
91 };
92 }
93  
94 0 ▶sub main {
Subroutine main: not called CC=3 SCAR=24.8
Pod undocumented
95 0 my ($options) = @_;
96  
97 0 ▶ $count = $options->{fastmode} ? 1 : 2;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 0 0 0
98  
99 0 my ($dstdir) = prepare($options);
100 0 ▶ return { failed => "no Benchmark-Perl-Formance-Cargo" } if not $dstdir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dstdir 0 0 0
101  
102 return {
103 0 upstream => upstream ($options, $dstdir),
104 bundled => bundled ($options, $dstdir),
105 }
106 }
107  
108 1 1;
109  
110 __END__
« blib/lib/Benchmark/Perl/Formance/Plugin/SpamAssassin.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/P6STD.pm »