PBP/Defeat.pm

filter: Statementstmt 100% 61 / 61 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod n/a totaltotal 98.8% 87 / 88 CC 8 SCAR 12.7
CC
8
Cov
99%
__ANON__
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
↑ Summary PBP/Enforce.pm »
1 package Acme::PBP::Defeat;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use overload;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use vars qw[$VERSION];
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 $VERSION = qv( 1.2.3 );
10  
11 5 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
12
13 ### defeats RequireExtendedFormatting
14 5 ▶ overload::constant( 'qr' => sub { "(?-xms:$_[1])" } );
Subroutine __ANON__: called CC=1 SCAR=0.0
15 }
16  
17  
18 ### override PPI::Document->new to first be piped through perltidy
19 ### also, put all the POD at the end of the document
20 2 ▶{ use Perl::Tidy;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶ use PPI::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 my $rc = do{
24 2 my $ext = '.pm';
25 2 my $dir = join '/', split '::', __PACKAGE__;
26 2 $dir = File::Spec->rel2abs( $INC{$dir.$ext} ),
27 $dir =~ s/$ext$//;
28 2 File::Spec->catfile( $dir, 'PerlTidyRC'. $ext );
29 };
30  
31 2 my $org = PPI::Document->can('new');
32
33 2 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 6 ▶ *_tidy = *PPI::Document::new = sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
35 6 my $self = shift;
36 6 my $what = shift;
37  
38 6 my $sorted;
39 6 ▶ if( $what ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what) 3 3 6
40 3 Perl::Tidy::perltidy(
41 source => $what,
42 destination => \my $out,
43 perltidyrc => $rc,
44 );
45
46 3 my( @top, @bottom );
47 3 my $in_pod = 0;
48 3 for (split $/, $out) {
49 8 ▶ $in_pod = /^=/ ? 1 : $in_pod;
Branch: 1 branch
BranchTrueFalseTotal
/^=/ ? : 2 6 8
50 8 ▶ $in_pod ? do { push @bottom, $_ } : do { push @top, $_ };
Branch: 1 branch
BranchTrueFalseTotal
$in_pod ? : 3 5 8
51 8 ▶ $in_pod = /^=cut/ ? 0 : $in_pod;
Branch: 1 branch
BranchTrueFalseTotal
/^=cut/ ? : 1 7 8
52 }
53
54 3 $sorted = join $/, @top, $/, '__END__', $/, @bottom;
55 }
56  
57 ### use 'PPI::Document' if we're called via _tidy
58 ### only pass args if we were passed args.
59 6 ▶ return $org->( ref $self eq __PACKAGE__ ? 'PPI::Document' : $self,
Branch: 2 branches
BranchTrueFalseTotal
ref $self eq __PACKAGE__ ? : 0 6 6
$what ? : 3 3 6
60 $what ? \$sorted : ()
61 );
62 }
63 2 }
64  
65 ### Smart::Comments are evil, just like all source filters. So kill them.
66 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
67 2 ▶ use Module::Loaded qw[mark_as_loaded];
Subroutine BEGIN: called CC=1 SCAR=0.0
68 2 mark_as_loaded('Filter::Simple');
69
70 1 ▶ *Filter::Simple::import = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
71 1 my $who = [caller]->[0];
72 1 Carp::croak "Dear $who, source filters are _not_ a best practice!";
73 }
74 2 }
75  
76 ### 3-part versions are evil
77 # CHECK {
78 # for my $stash ( map { s|/|::|g; s/\.pm$//i; $_ } keys %INC ) {
79 # print "$stash -> " . $stash->VERSION . $/;
80 #
81 #
82 # #my $version = *{"$stash->{VERSION}"}{'SCALAR'};
83 # #warn "stash: $stash";
84 # #my $version = *{"$stash"};
85 #
86 # #print "$pkg -> $$version\n";
87 # }
88 # }
89  
90  
91 2 1;
↑ Summary PBP/Enforce.pm »