« 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
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | print STDERR "# Prepare Perl::Critic sources in $dstdir ...\n" if $options->{verbose} >= 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my $datadir = $dstdir; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | $datadir .= '/Perl/Critic/Utils' if $options->{fastmode}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$options->{"verbose"} and $options->{"verbose"} >= 4
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
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | print STDERR "# Run...\n" if $options->{verbose} && $options->{verbose} >= 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$options->{"verbose"} and $options->{"verbose"} >= 3
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | print STDERR join("\n# ", "", @output[0..$maxerr]) if $options->{verbose} >= 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | print STDERR "# $cmd\n" if $options->{verbose} && $options->{verbose} >= 4; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$options->{"verbose"} and $options->{"verbose"} >= 4
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
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | print STDERR "# Run...\n" if $options->{verbose} && $options->{verbose} >= 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$options->{"verbose"} and $options->{"verbose"} >= 3
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | print STDERR join("\n# ", "", @output[0..$maxerr]) if $options->{verbose} >= 4; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | my ($dstdir) = prepare($options); | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | return { failed => "no Benchmark-Perl-Formance-Cargo" } if not $dstdir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | return { | ||||||||||||||||||||||||||||
| 103 | 0 | upstream => upstream ($options, $dstdir), | |||||||||||||||||||||||||||
| 104 | bundled => bundled ($options, $dstdir), | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | 1; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||