| 1 | # SPDX License Identifier: Apache License 2.0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # provides ithread-safe :Sealed subroutine attributes: use with care! | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Author: Joe Schaefer <joe@sunstarsys.com> | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | package clown; | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use v5.38; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use version; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use B::Generate (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use B::Deparse (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | our $DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our $VERSION = qv(1.0.4); | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | my %valid_attrs = (clown => 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | sub tweak :prototype($\@\@\@$$\%) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tweak: called CC=6 SCAR=19.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | my ($op, $lexical_varnames, $pads, $op_stack, $cv_obj, $pad_names, $processed_op) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | my ($idx, $sub_name); | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | if (ref($op) eq "B::PADOP") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $padix = $op->padix; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | # A little prayer | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # Not sure if this works better pre-ithread cloning, or post-ithread cloning. | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # I've only used it post-ithread cloning, so YMMV. | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # $targ collisions? ordering is a WAG with the @op_stack walker down below. | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | $sub_name = substr $$pads[$idx++][$padix], 1 until defined $sub_name; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | $sub_name = substr ${$op->sv->object_2svref}, 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | die "\&$sub_name does not exist" unless defined *$sub_name and defined *$sub_name{CODE}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined *$sub_name and defined *$sub_name{"CODE"}
MC/DC50%1/2
defined *$sub_name and defined *$sub_name{"CODE"}
defined *$sub_name
defined *$sub_name{"CODE"}
Truth table66%2/3
A and B
A= defined *$sub_nameB= defined *$sub_name{"CODE"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | $op = $op->next; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | push @$op_stack, $op if $$op; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | return ($op, 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub all { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all: not called CC=1 SCAR=0.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $pkg = caller; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # can segfault | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | eval "BEGIN { | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | while (my (undef, \$v) = each %{$pkg\::}) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | eval 'ref(\$v) eq q(CODE)' or next; | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | MODIFY_CODE_ATTRIBUTES(\$pkg, \$v, \"clown\"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | }"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | sub MODIFY_CODE_ATTRIBUTES { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
MODIFY_CODE_ATTRIBUTES: called CC=23 SCAR=36.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | my ($class, $rv, @attrs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | if ((not defined $DEBUG or $DEBUG ne "disabled") and grep $valid_attrs{+lc}, @attrs) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
!defined($clown::DEBUG) || $clown::DEBUG ne "disabled" and grep $valid_attrs{lc $_}, @attrs
not defined $clown::DEBUG or $clown::DEBUG ne "disabled"
MC/DC0%0/3
!defined($clown::DEBUG) || $clown::DEBUG ne "disabled" and grep $valid_attrs{lc $_}, @attrs
not defined $clown::DEBUG
$clown::DEBUG ne "disabled"
grep $valid_attrs{lc $_}, @attrs
Truth table20%1/5
not(A) or B and C
A= not defined $clown::DEBUGB= $clown::DEBUG ne "disabled"C= grep $valid_attrs{lc $_}, @attrs
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | my $cv_obj = B::svref_2object($rv); | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | my @op_stack = $cv_obj->START; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | my ($pad_names, @p) = $cv_obj->PADLIST->ARRAY; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | my @pads = map $_->object_2svref, @p; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | my @lexical_varnames = $pad_names->ARRAY; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | my %processed_op; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | my $tweaked; | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | while (my $op = shift @op_stack and not defined $^S) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
my $op = shift @op_stack and not defined $^S
MC/DC50%1/2
my $op = shift @op_stack and not defined $^S
my $op = shift @op_stack
not defined $^S
Truth table66%2/3
A and not(B)
A= my $op = shift @op_stackB= not defined $^S
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 23 | ▶ | ref $op and $$op and not $processed_op{$$op}++ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $op and $$op and not $processed_op{$$op}++
ref $op and $$op
MC/DC66%2/3
ref $op and $$op and not $processed_op{$$op}++
ref $op
$$op
not $processed_op{$$op}++
Truth table75%3/4
A and B and not(C)
A= ref $opB= $$opC= not $processed_op{$$op}++
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | or next; | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 11 | ▶ | $op->dump if defined $DEBUG and $DEBUG eq 'dump'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $clown::DEBUG and $clown::DEBUG eq "dump"
MC/DC0%0/2
defined $clown::DEBUG and $clown::DEBUG eq "dump"
defined $clown::DEBUG
$clown::DEBUG eq "dump"
Truth table33%1/3
A and B
A= defined $clown::DEBUGB= $clown::DEBUG eq "dump"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 11 | ▶ | if ($op->isa("B::PADOP") or $op->isa("B::SVOP")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$op->isa("B::PADOP") or $op->isa("B::SVOP")
MC/DC50%1/2
$op->isa("B::PADOP") or $op->isa("B::SVOP")
$op->isa("B::PADOP")
$op->isa("B::SVOP")
Truth table66%2/3
A or B
A= $op->isa("B::PADOP")B= $op->isa("B::SVOP")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | $tweaked += eval {tweak $op, @lexical_varnames, @pads, @op_stack, | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | $cv_obj, $pad_names, %processed_op}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | die __PACKAGE__ . ": tweak() aborted: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 10 | ▶ | if ($op->isa("B::PMOP")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | push @op_stack, $op->pmreplroot, $op->pmreplstart, $op->next; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif ($op->can("first")) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 5 | ▶ | for (my $kid = $op->first; ref $kid and $$kid; $kid = $kid->sibling) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $kid and $$kid
MC/DC50%1/2
ref $kid and $$kid
ref $kid
$$kid
Truth table66%2/3
A and B
A= ref $kidB= $$kid
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 7 | push @op_stack, $kid; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | unshift @op_stack, $op->next; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 5 | unshift @op_stack, $op->next, $op->parent; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | if (defined $DEBUG and $DEBUG eq "deparse" and $tweaked) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $clown::DEBUG and $clown::DEBUG eq "deparse" and $tweaked
defined $clown::DEBUG and $clown::DEBUG eq "deparse"
MC/DC0%0/3
defined $clown::DEBUG and $clown::DEBUG eq "deparse" and $tweaked
defined $clown::DEBUG
$clown::DEBUG eq "deparse"
$tweaked
Truth table25%1/4
A and B and C
A= defined $clown::DEBUGB= $clown::DEBUG eq "deparse"C= $tweaked
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | eval {warn "sub ", $cv_obj->GV->NAME // "__UNKNOWN__", " :clown ", | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$cv_obj->GV->NAME // "__UNKNOWN__"
MC/DC0%0/1
$cv_obj->GV->NAME // "__UNKNOWN__"
$cv_obj->GV->NAME
Truth table0%0/2
A
A= $cv_obj->GV->NAME
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | B::Deparse->new->coderef2text($rv), "\n"}; | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | warn "B::Deparse: coderef2text() aborted: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | return grep !$valid_attrs{+lc}, @attrs; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | no warnings qw/uninitialized redefine/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | $DEBUG = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | my $pkg = caller; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | ▶ | eval "package $pkg; use types; use class" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | if $DEBUG eq 'types'; # enable perl type system | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | eval "package $pkg; CHECK { package $pkg; clown::all() }" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | if $DEBUG eq 'all'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||