| 1 | package Acme::PBP::Enforce; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use overload; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | my @Callers; | |||||||||||||||||||||||||||
| 8 | 7 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | ### to check for prototypes later, during CHECK: {} | ||||||||||||||||||||||||||||
| 11 | 7 | push @Callers, [caller]->[0]; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | overload::constant( 'q' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 14 | 3 | my($literal, $value) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | ### you've used tabs, but not \t to indicate them | ||||||||||||||||||||||||||||
| 17 | 3 | ▶ | if( $value =~ /\t/ and $literal !~ /\\t/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value =~ /\t/ and not $literal =~ /\\t/
MC/DC50%1/2
$value =~ /\t/ and not $literal =~ /\\t/
$value =~ /\t/
not $literal =~ /\\t/
Truth table66%2/3
A and not(B)
A= $value =~ /\t/B= not $literal =~ /\\t/
| |||||||||||||||||||||||||||||
| 18 | 2 | croak( "Illegal use of literal tab" ); | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | return $value; | |||||||||||||||||||||||||||
| 22 | 7 | } ); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | ### bareword filehandles are bad | ||||||||||||||||||||||||||||
| 26 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | *CORE::GLOBAL::open = sub (*;$@) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | croak( "Bareword filehandles not allowed. Use 'open my \$fh, $_[1]' instead" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | if Internals::SvREADONLY( $_[0] ); | ||||||||||||||||||||||||||||
| 30 | 1 | CORE::open( @_ ); | |||||||||||||||||||||||||||
| 31 | 2 | }; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub _disallow_prototypes { | ||||||||||||||||||||||||||
|
Subroutine
_disallow_prototypes: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 35 | 1 | my %use_proto; | |||||||||||||||||||||||||||
| 36 | 1 | for my $pkg ( @_ ) { | |||||||||||||||||||||||||||
| 37 | 2 | my $stash = $pkg . '::'; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 2 | for my $name (sort keys %$stash ) { | |||||||||||||||||||||||||||
| 41 | 13 | ▶ | my $sub = $pkg->can($name) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 8 | ▶ | my $proto = prototype $sub or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | $use_proto{ "$pkg->$name" } = $proto; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | if( keys %use_proto ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | croak( "Use of prototypes not allowed in:\n" . | ||||||||||||||||||||||||||||
| 50 | 1 | join '', map { "\t$_\n" } keys %use_proto ); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | CHECK { __PACKAGE__->_disallow_prototypes( @Callers ) } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | 1; | |||||||||||||||||||||||||||